How To Make a PHP Script Available for All Domains in EasyApache4


Well-Known Member
Aug 21, 2015
cPanel Access Level
Root Administrator
When I was using EasyApache3, I had some PHP scripts--like PHPMailer--that I used on multiple accounts, but since I only wanted to maintain a single copy of the script, I put the scripts in folders in the include_path for PHP. I could then use PHP's "include" functions to include them in my scripts on any account.

In EasyApache3, with only one version of PHP running, that was easy, but with EasyApache4, I wanted to take advantage of running MultiPHP, and suddenly I had a problem. Each version of PHP was using its own include_path and open_basedir setting.

The solution I came up with was to put the scripts I wanted available server-wide in the include_path for PHP 7, then I added a symlink in the other PHP versions' include_path that pointed to the actual files in the PHP 7 folder. After that, I made sure that the include_path for each version of PHP was in the open_basedir setting in the corresponding php.ini. Now, I only have to maintain the script in the PHP 7 folder, but it's available server-wide.

I'm posting a brief example here using PHPMailer in case it helps someone else. I don't claim to be an expert, so if there is a better way, I'm open to it.

  1. Upload your script to /opt/cpanel/ea-php70/root/usr/share/pear/. In my case, I created a folder called "PHPMailer" in that folder.
  2. Start a Terminal session and cd into the include_path folder for each PHP version you're using. For PHP 5.6 for example, you'd use the command:
    cd /opt/cpanel/ea-php56/root/usr/share/pear/
  3. Run the following command to create a symlink that points to your script. The command to create a symlink is:
    ln -s <path to the files> <file or folder name of the link>
    In my case, for PHPMailer in the "PHPMailer" folder, it was:
    ln -s /opt/cpanel/ea-php70/root/usr/share/pear/PHPMailer PHPMailer
  4. Verify that the PHP include_path for your PHP installation is in the open_basedir setting for PHP by looking at Software -> MultiPHP INI Editor -> Editor Mode. (You can quickly find the setting for open_basedir by pressing Ctrl + f and typing in "open_basedir" in the Editor.)
  5. Repeat steps 3 and 4 for each PHP version you want to have access to your server-wide script.
Of course, when PHP 7 reaches end-of-life, I'm going to have to move my server-wide scripts into a folder for the latest version of PHP, but for now, it works.


Staff member
Apr 11, 2011

I'm happy to see you were able to implement a custom solution to address the issue. Thank you for taking the time to post your workaround to the community.