Upgrade to PHP 5 on (dv) 3.0 Dedicated Virtual Servers
SUMMARY:
STOP:
- This procedure will not work for the (dv) 2.0 line of servers. The upgrade path for (dv) 2.0 servers can be found in another KB article.
- If you are using a (dv) 2.0 or 3.0 server we strongly encourage you to migrate to the new (dv) 3.5 service which as PHP 5 installed by default. If you are using a (dv) 3.5 you do not need to follow this article. For more information please click here.
- Whenever installing Third-Party software or upgrading core technologies on your server, please consult the official documentation. (mt) Media Temple does not support the installation and configuration of software not installed at time of service activation. Please consult our (dv) Scope of Support page for further explanation.
This point cannot be stressed enough. The best way to back up all of the information on the server so you can return to a previous state is by using our (dv) Backup Add-on service. This way if things don't go well with the upgrade you can always get your server working without too much hassle.
Step 2: Decide which way to run php5 scripts- suexec - Running your PHP scripts via suexec is the best way to get things working if you intend on running more than one site on your server. This method makes sure that the scripts are run as the domain user, keeping all output files with the same permissions and prohibiting scripts from accessing files owned by other users. Running PHP scripts using this method is recommended.
- non-suexec - Running PHP scripts without suexec provides a small speed increase but does not provide any of the cross user benefits necessary in a multi site deployment. If you wish to run your scripts by using the non-suexec method please see the appropriate section.
- The PHP5 package provided with your (dv) Dedicated-Virtual Server has PHP safe_mode set to 'Off' by default. As we understand that PHP is a complex framework, it's important to stress that this should be set to 'On' globally to minimize the amount of security vulnerabilities you may be exposed to as a result of incorporating PHP5 functionality on your domain. The following steps will guide you through re-enabling PHP safe_mode: A. Open the php.ini file for PHP5 and go to line 226. This command should take you to the right place:
B. You should see something like this:vi +/safe_mode /opt/php51/etc/php5/fastcgi/php.ini
Edit the line that reads 'safe_mode = Off' so that it is 'On' instead. It should look like this:; ; Safe Mode ; safe_mode = Off
Save this file (the command ':x' without quotes works in vi), then reload your web server:; ; Safe Mode ; safe_mode = On/etc/init.d/httpd restart
- These changes must be made on a per domain basis. Log into Plesk and enter the setup area for the domain that you would like to enable php5. Under 'Services' make sure that:
- CGI support is checked
- FastCGI support is checked
- SSH into your server as 'root' and execute these commands one at a time:
TIP:
Remember to replace mt-example.com with your actual domain name and username with the ftp username for that domain.
mkdir /var/www/vhosts/mt-example.com/bin/ cp /opt/php51/cgi-bin/php5 /var/www/vhosts/mt-example.com/bin/ cd /var/www/vhosts/mt-example.com/ chown -R username:psacln bin cd conf vi vhost.confThese commands: make a copy of the CGI version of php5 and place it in the 'bin' directory of the domain, change the owner of the 'bin' directory and the copy of php5 to the same as the domain user and create a vhost.conf file in the conf directory. - Add these lines to the vhost.conf file that you are editing with 'vi':
Again please remember to make the correct substitutions for usernameAddHandler fcgid-script .php5 SuexecUserGroup username psacln <Directory /var/www/vhosts/mt-example.com/httpdocs> FCGIWrapper /var/www/vhosts/mt-example.com/bin/php5 .php5 Options ExecCGI allow from all </Directory>and mt-example.com. Save this file (the command ':x' without quotes works in vi) - Execute this command to reconfigure your server to use the new vhost.conf file:
This will automatically restart your webserver./usr/local/psa/admin/sbin/websrvmng -a -v
- These changes must be made on a per domain basis. Log into Plesk and enter the setup area for the domain that you would like to enable php5. Under 'Services' make sure that:
- CGI support is unchecked
- FastCGI support is checked
- SSH into your server as 'root' and execute these commands one at a time:
Substitute your actual domain name forcd /var/www/vhosts/mt-example.com/conf vi vhost.conf - Add these lines to the vhost.conf file that you are editing with 'vi':
Please remember to substitute your actual domain name for mt-example.com. Save this file (the command ':x' without quotes works in vi)AddHandler fcgid-script .php5 <Directory /var/www/vhosts/mt-example.com/httpdocs> FCGIWrapper /opt/php51/cgi-bin/php5 .php5 Options ExecCGI allow from all </Directory> - Execute this command to reconfigure your server to use the new vhost.conf file:
This will automatically restart your webserver./usr/local/psa/admin/sbin/websrvmng -a -v
- Make sure you are in the proper directory:
cd /var/www/vhosts/mt-example.com/conf/ - Copy your new vhost.conf file into 'vhost_ssl.conf'
cp vhost.conf vhost_ssl.conf - Re-run the reconfigure webserver command.
/usr/local/psa/admin/sbin/websrvmng -a -v
NOTES:
Extensions: The above article will use PHP5 only if the script ends with the ".php5" extension. If you want all PHP scripts for that domain to run under PHP5, make the following change to your vhost.conf file:
with suexec:
AddHandler fcgid-script .php .php5
SuexecUserGroup username psacln
<Directory /var/www/vhosts/mt-example.com/httpdocs>
FCGIWrapper /var/www/vhosts/<domain>/bin/php5 .php
FCGIWrapper /var/www/vhosts/<domain>/bin/php5 .php5
Options ExecCGI
allow from all
</Directory> without suexec:
AddHandler fcgid-script .php .php5
<Directory /var/www/vhosts/mt-example.com/httpdocs>
FCGIWrapper /opt/php51/cgi-bin/php5 .php
FCGIWrapper /opt/php51/cgi-bin/php5 .php5
Options ExecCGI
allow from all
</Directory> You will then need to run the "reconfigure webserver" command listed above.
Sub-domains:
In order to enable php5 on subdomains, you must create another "vhost.conf" file in each subdomain's conf directory; i.e.:
/var/www/vhosts/mt-example.com/subdomains/<sub>/conf/complete the same steps as above, simply change the Directory paths to:
You will need to run the "reconfigure webserver" command listed above.
/var/www/vhosts/mt-example.com/subdomains/<sub>/httpdocs/
Revisions:
07-20-2009: Corrections in Stop Box at top
05-07-2009: Made corrections to the Sub-domains section where the path was being specified incorrectly. Also verified the example code is correct.
05-06-2009: Cleaned up some of the commands that did not import well from our old KnowledgeBase and added username, domain tip above. - Thanks to Daniel Tome for the feedback.
Fields marked with an asterisk(*) are required. Comment on this article