Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

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

Discussion in 'Workarounds and Optimization' started by linux4me2, Aug 5, 2016.

  1. linux4me2

    linux4me2 Well-Known Member

    Joined:
    Aug 21, 2015
    Messages:
    222
    Likes Received:
    57
    Trophy Points:
    28
    Location:
    USA
    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:
      Code:
      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:
      Code:
      ln -s <path to the files> <file or folder name of the link>
      In my case, for PHPMailer in the "PHPMailer" folder, it was:
      Code:
      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.
     
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,421
    Likes Received:
    1,956
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice