4

I am currently hosting a simple multi-tenancy service on cPanel shared hosting, where customers who signed up will have a subdomain, directory and a database dynamically assigned to them (via XMLAPI):

Customer A subdomain directory7: /home/xxx/public_html/customers/custA/ (http://custA.abc.com),
Customer B subdomain directory: /home/xxx/public_html/customers/custB/ (http://custB.abc.com) etc.

All customers will be served with the same copy of the system files (except for their respective config file), so I created symlinks from my customers' subdomain directory to: /home/xxx/mainfiles/

However, I was greeted with PHP warnings as follows:

[17-Dec-2014 07:28:39 Europe/London] PHP Warning:  Unknown: open_basedir restriction in effect. File(/home/xxx/mainfiles/index.php) is not within the allowed path(s): (/home/xxx/public_html/customers/custA:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp) in Unknown on line 0
[17-Dec-2014 07:28:39 Europe/London] PHP Warning:  Unknown: failed to open stream: Operation not permitted in Unknown on line 0
[17-Dec-2014 07:28:39 Europe/London] PHP Fatal error:  Unknown: Failed opening required '/home/xxx/public_html/customers/custA/index.php' (include_path='.:/opt/alt/php54/usr/share/pear:/opt/alt/php54/usr/share/php') in Unknown on line 0

Therefore, I will need to call my web hosting company every single time I have a new customer signing up, to turn off this particular open_basedir parameter for the new customer's subdomain/directory.

The hosting company told me that the open_basedir parameter is configured per subdomain/directory, but cannot be configured per directory path (i.e. /home/xxx/mainfiles).

Are there any better way of doing this? Like using .htaccess or something...

My aims are:

  1. System files must be secure, not directly accessible by users but only via subdomain calls - Thus I store it one level ABOVE public_html
  2. I want to have a common folder where all my customer's subdomain directory will point to - So in the future I only need to do once changes for all customers
  3. Customers can access the system upon successful sign-up
  4. Remains to host in shared server hosting - Serving only small system file

migrated from serverfault.com Dec 17 '14 at 11:48

This question came from our site for system and network administrators.

  • If your hosting provider has not restricted the usage of .htaccess, you should be able to allow your custom path to the open_basedir through an .htaccess file. – Sree Dec 17 '14 at 10:53
  • Could you kindly provide some code examples? @Sree Never done any .htaccess stuff before. – ChristWolf Dec 17 '14 at 10:56
1

This sounds like an issue with the hosting company in my opinion. Who are you using? You should be able to modify your php.ini file across the board or at least find someone with this option set so it won't throw an error every time. Just a thought.

0

From Will Setting open_basedir in an .htaccess file completely limit a PHP scripts directory access? here is how you set the open_basedir for PHP in your .htaccess file:

php_flag open_basedir  "/var/www/vhosts/mydomain.com/php_can_only_access_files_in_this_directory/"
  • I have tried that approach on the shared hosting server but it still could not work. What I did was to open a new file in the new subdomain directory, then create a new .htaccess to open_basedir to "home/xxx/public_html/customers/newcustomer". Do you think migration my site to Amazon AWS will help? – ChristWolf Dec 19 '14 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.