• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Share PHP code across multiple vhosts

ArmandoF

New Pleskian
Hello everyone:

I need PHP file sharing across multiple domains from a primary domain (I use Plesk 10 with CentOS 6.0).

For example, share the directory: /var/www/vhosts/main_host/httpdocs/shared

To other domains:

/var/www/vhosts/other_host_1
/var/www/vhosts/other_host_2

Therefore, if coming from http://other_host_1/shared you can see the shared PHP code executed on page; the code located on /var/www/vhosts/main_host/httpdocs/shared

I try the next steps, but it always appears Forbidden:

1. Adding /var/www/vhosts/other_host_1/conf/vhost.conf, the following:

<Directory /var/www/vhosts/other_host_1/httpdocs>
<IfModule sapi_apache2.c>
php_admin_value open_basedir /var/www/vhosts/other_host_1/httpdocs/:/tmp/:/var/www/vhosts/main_host/httpdocs/shared/
</IfModule>
<IfModule mod_php5.c>
php_admin_value open_basedir /var/www/vhosts/other_host_1/httpdocs/:/tmp/:/var/www/vhosts/main_host/httpdocs/shared/
</IfModule>
</Directory>

2. Adding a symbolic link in /var/www/vhosts/other_host_1/httpdocs/

ln -s /var/www/vhosts/main_host/httpdocs/shared /shared


I tried creating Alias on vhost.conf (before the Directory tag):

Alias "/shared" "/var/www/vhosts/main_host/httpdocs/shared"

Doing this, you can download the PHP file, but not execute it... therefore, does not work.

Finally, I have also tried: "php_admin_value open_basedir none", without success.

Is there any way to do this? Can you guide me?

Thank you for all your help.

Armando

PD. I saw the following post, but does not work for me (or I don't understand at all) http://forum.parallels.com/pda/index.php/t-63117.html.
 
If you were on Plesk 11.0 (or 11.5) you could have edited PHP settings in UI. Actually 11.0 by default allows execution of shared PHP code, so you probably wouldn't even have had the issue.

For 10.0 you can probably try http://kb.parallels.com/en/432, but 10.0 is very old already, so upgrade is definitely recommended.
 
Hi,

I know, maybe I should have posted this as a Plesk 11 thread, but while Sergey L already mentioned Plesk 11, and I'm trying to solve exact the same problem, I'll reply to this thread...

I'm trying to do the same (Plesk 11.0.9), no luck so far....

Steps:

1. create subscriptions:
mainhost.com (this vhost contains the actual shared code dir (/httpdocs/shared/)
newhost1.com (link to service plan 'defhost')
newhost2.com (link to service plan 'defhost')

2. create symlinks to shared dir
ln -s /var/www/vhosts/mainhost.com/httpdocs/shared/ /var/www/vhosts/newhost1.com/httpdocs/shared
ln -s /var/www/vhosts/mainhost.com/httpdocs/shared/ /var/www/vhosts/newhost2.com/httpdocs/shared

3. change owner
chown -h /var/www/vhosts/newhost1.com/httpdocs/shared
chown -h /var/www/vhosts/newhost2.com/httpdocs/shared

4. Edit service plan 'defhost' + Update & Sync
PHP Settings ->open_basedir -> Set custom value: {WEBSPACEROOT}/:{TMP}/:/var/www/vhosts/mainhost.com/httpdocs

5. Check open_basedir setting (phpinfo()):
open_basedir
Local value: /var/www/vhosts/newhost1.com/:/tmp/:/var/www/vhosts/mainhost.com/httpdocs
Master value: /var/www/vhosts/newhost1.com/:/tmp/:/var/www/vhosts/mainhost.com/httpdocs

6. Create test.php in shared dir: /var/www/vhosts/mainhost.com/httpdocs/shared/test.php

7. Try to include test.php from shared dir:
Create /var/www/vhosts/newhost1.com/httpdocs/index.php:
<?php
require_once('shared/test.php');
?>

This results in these errors:
mod_fcgid: stderr: PHP Warning: require_once(shared/test.php): failed to open stream: Permission denied in /var/www/vhosts/newhost1.com/httpdocs/index.php on line 2
mod_fcgid: stderr: PHP Fatal error: require_once(): Failed opening required 'shared/test.php' (include_path='.:') in /var/www/vhosts/newhost1.com/httpdocs/index.php on line 2

Does anybody have any idea what I'm missing?

Thanks!
 
Last edited:
Back
Top