Knowledgebase

Different PHP versions per directories using suPHP

Using different PHP versions per directory with suPHP involves configuring your web server to handle PHP scripts with different PHP versions based on the directory where the script is located. Here's a step-by-step guide for achieving this:

  1. Install and Configure Multiple PHP Versions:

    • First, you need to have multiple PHP versions installed on your server. You can do this using tools like phpbrew or by installing different PHP versions directly.
  2. Configure suPHP:

    • Modify your suPHP configuration to specify the desired PHP version for each directory. This can typically be done in the suphp.conf or similar configuration file.

      Example (suphp.conf):

      apache
    • <IfModule mod_suphp.c> AddType application/x-httpd-php5 .php suPHP_AddHandler application/x-httpd-php5 <Directory /path/to/directory1> suPHP_Engine on suPHP_AddHandler application/x-httpd-php5 suPHP_PHPPath /path/to/php5 </Directory> <Directory /path/to/directory2> suPHP_Engine on suPHP_AddHandler application/x-httpd-php7 suPHP_PHPPath /path/to/php7 </Directory> </IfModule>

      In this example, requests to /path/to/directory1 will be handled by PHP 5, while requests to /path/to/directory2 will be handled by PHP 7.

  1. Adjust File Permissions:

    • Ensure that the files and directories in each directory have the correct permissions for the PHP version they will be executed with.
  2. Restart Apache or Web Server:

    • After making changes to the configuration, restart your web server to apply the new settings.
  3. Verify Configuration:

    • Create simple PHP files in each of the directories (directory1/index.php and directory2/index.php) with phpinfo() to confirm that they are using the correct PHP versions.
  4. Test Your Setup:

    • Access the PHP files you created in both directories through a web browser. Verify that they display the PHP information corresponding to their respective versions.
  5. Monitor and Troubleshoot:

    • Keep an eye on your system to ensure that PHP scripts are executing with the correct versions. If any issues arise, check logs and review your configuration.

Please note that suPHP is relatively old and not actively maintained. It's generally recommended to use alternatives like php-fpm or similar technologies for more modern PHP versions.

Remember to back up your configurations and files before making any changes, especially if you're working on a production server. This way, you can easily revert back if something goes wrong during the setup process.

 
  • 0 Users Found This Useful
Was this answer helpful?