I recently purchased a VPS with Interworx and began to migrate my sites from my trusty GigaDeal account. For the most part, I really like Interworx, but one thing that frustrated me with it was that it doesn't support PHP4 alongside PHP5 out of the box. I've come to like that feature of my GigaDeal plan-I can develop new scripts using the latest PHP features while not having to worry about breaking my existing scripts before I have time to migrate them.
I found a couple of posts on the Interworx forums about setting up such an environment using RPMs, but unfortunately the RPMs were user contributed and the links on the site no longer worked. So I decided to bite the bullet and figure out how to do it myself.
Background: My VPS came set up with PHP 4.3.11 and Apache 2. For the record, I'm running CentOS 4, but that shouldn't matter too much for the tutorial. Even though it isn't the most current version, I decided to leave PHP 4 alone (for now). That binary is powering the Interworx CP and I don't want to break it by introducing any unsupported changes.
1. Download and compile PHP 5. I opted to go with the most recent version, 5.2.4. For the sake of brevity, I'll leave it up to you to decide what options to pass to configure, but the ones listed are essential:
program-suffix tells the compiler to stick a "5" on the end of all of the PHP 5 binaries so that they won't overwrite the existing PHP 4 binaries. (I'm also installing to a different path --/usr/local instead of /usr--so this won't be an issue, but it still makes it easier to keep track of what's what.)Code:wget http://www.php.net/get/php-5.2.4.tar.gz/from/this/mirror tar xvfz php-5.2.4.tar.gz cd php-5.2.4 ./configure --program-suffix=5 --prefix=/usr/local --enable-force-cgi-redirect
Once the configure script runs successfully you are ready to make PHP 5:
If all goes well you should now have several php*5 binaries in /usr/local/bin.Code:make make test make install
2. Now, in order to run PHP scripts under their owner's UID, we need to have suPHP. Again, I'm using the most recent release(0.6.2).
Before you configure you'll need to edit the mod_suphp.c file in the src/apache2 directory of your unpacked suphp directory. Search for any occurrences of the string "ACCESS_CONF" (without quotes) and replace with "RSRC_CONF | ACCESS_CONF" (again, without quotes). If you do not do this you will get errors when you try to use suPHP_AddHandler in the server configuration process.Code:wget http://www.suphp.org/download/suphp-0.6.2.tar.gz tar xvfz suphp-0.6.2.tar.gz cd suphp-0.6.2.tar.gz
suPHP's configure script will work fine without any arguments, but I've opted to use paranoid mode which runs scripts as the user I designate (more on that later), but only if the file is owned by that user.
When done compiling, suPHP should add a file in /etc/httpd/conf.d called mod_suphp.conf. When Apache is restarted, it will parse this file and load the suPHP module.Code:./configure --prefix=/usr --with-setid-mode=paranoid make make install
3. Now open /etc/suphp.conf and set the following:
Then find the [handlers] section make sure it contains the following (you'll need to add the second line):Code:allow_file_others_writable = false allow_directory_others_writable = false
Code:x-httpd-php=php:/usr/bin/php x-httpd-php5=php:/usr/local/bin/php-cgi5
4. Now it is time to configure Apache to use suPHP. Open /etc/httpd/conf.d/mod_suphp.conf and replace the existing <IfModule mod_suphp.c>…</IfModule> block with the following:
You should also remove the /etc/httpd/conf.d/php.conf file (I renamed mine to php.conf.disabled so that I'll still have it if I need it later).Code:<IfModule mod_suphp.c> suPHP_Engine on suPHP_ConfigPath /etc suPHP_AddHandler x-httpd-php AddHandler application/x-httpd-php .php .php4 .php suPHP_AddHandler x-httpd-php5 AddHandler application/x-httpd-php5 .php5 </IfModule> DirectoryIndex index.php index.php5
5. /etc/httpd/conf.d also contains a file for each virtual host on the server. You will need to make two edits to each of these files:
a. Add the following line anywhere inside the <VirtualHost>…</VirtualHost> block:
Replace "username" and "groupname" with the appropriate values for the site's owner. Both should actually be the same value unless you've manually changed it. This tells suPHP which user should be used to run PHP scripts on this virtual host.Code:suPHP_UserGroup username groupname
b. Comment out (or remove) the line that starts "php_admin_flag." Since we've removed support for mod_php keeping this around will cause sites to fail with "500" errors.
6. Interworx uses a template when it creates new virtual host conf files that can be found at /home/interworx/etc/vhost-base.conf. You should edit this file as in step 5 so that future sites you add will automatically configured to use suPHP. Instead of providing actual user and group names in the suPHP_UserGroup directive, use the following, which Interworx will substitute with the names it assigns to new accounts:
Code:suPHP_UserGroup <<UNIQNAME>> <<UNIQNAME>>
7. Restart Apache to make all of your changes take place.
Code:service httpd restart
User configuration
Since mod_php has been disabled users will no longer be able to set php_value and php_flag directives in .htaccess. In fact, if they have any of these directives defined their sites will break after this change is made.
Unlike cPanel's implementation, users cannot simply drop a php.ini file into the current directory to override default settings. The can, however, redefine suPHP_ConfigPath to point to any directory containing a php.ini file in .htaccess:
Note that the path should be to a directory containing a php.ini file, not to the php.ini file itself.Code:suPHP_ConfigPath /home/myaccount
Users who want to make their .php scripts run under PHP5 can do so by adding the following to .htaccess:
I hope you find this helpful.Code:AddHandler application/x-httpd-php5 .php
--Jason


LinkBack URL
About LinkBacks



Reply With Quote


Bookmarks