Search code examples
phpcpanelsymlinkinternal-server-erroropen-basedir

Using symlink and php includes outside user's directory with cPanel


I have a dedicated server with cPanel, hosting our custom backend system and multiple websites. The backend is hosted on a separate domain and contains a folder ("shared") which has a lot of php-classes and images that are used by all websites that are controlled by the backend.

For example:
Backend: 'backend.com'
Website 1: 'website1.com'
Website 2: 'website2.com'
etc.

I created a symlink from website1.com like this:

ln -s /home/backend/public_html/shared/ /home/website1/public_html/shared

Then I disabled the open_basedir protection for website1.com in cPanel and created a .user.ini file to set the open_basedir value:

open_basedir = /home/website1/public_html/:/home/backend/public_html/shared/

When I try to access a file through website1.com in the (symlinked) shared folder I get a 500 Internal server error. The apache log shows:

[Fri Nov 20 03:51:45 2015] [error] [client xxx.xxx.xx.xx] SoftException in Application.cpp:422: Mismatch between target UID (513) and UID (512) of file "/home/website1/public_html/shared/__debug.php"
[Fri Nov 20 03:51:45 2015] [error] [client xxx.xxx.xx.xx] Premature end of script headers: __debug.php

I understand there is a mismatch between user/group, but is there a way to solve this problem?


Solution

  • Fixed it with Cpanel Addon Domains. This way all the domains are hosted in the same cPanel account, and there are no ownership problems.