Support / KnowledgeBase

 
Search the KnowledgeBase Search

Upgrade to PHP 5 on (dv) 3.0 Dedicated Virtual Servers

  • Applies to: (dv) 3.0

  • Difficulty: Hard

  • Time needed: 30 minutes

  • Tools needed: root, ssh, vi knowledge

 

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.
Step 1: Make backups

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.
Step 3 (optional): Re-enabling PHP safe_mode
  • 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:
    vi +/safe_mode /opt/php51/etc/php5/fastcgi/php.ini
    B. You should see something like this:
    ;
    ; Safe Mode
    ;
    safe_mode = Off
    Edit the line that reads 'safe_mode = Off' so that it is 'On' instead. It should look like this:
    ;
    ; Safe Mode
    ;
    safe_mode = On
    Save this file (the command ':x' without quotes works in vi), then reload your web server:
    /etc/init.d/httpd restart
Running PHP via suexec
  1. 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
    Save this setup.
  2. 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.conf
    These 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.
  3. Add these lines to the vhost.conf file that you are editing with 'vi':
    AddHandler 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> 
    Again please remember to make the correct substitutions for username and mt-example.com. Save this file (the command ':x' without quotes works in vi)
  4. Execute this command to reconfigure your server to use the new vhost.conf file:
    /usr/local/psa/admin/sbin/websrvmng -a -v
    This will automatically restart your webserver.
If everything has gone smoothly every script for this domain that ends in .php5 will be run via suexec with the new version of php. Running PHP without suexec
  1. 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
    Save this setup.
  2. SSH into your server as 'root' and execute these commands one at a time:
    cd /var/www/vhosts/mt-example.com/conf
    vi vhost.conf
    Substitute your actual domain name for
  3. Add these lines to the vhost.conf file that you are editing with '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> 
    Please remember to substitute your actual domain name for mt-example.com. Save this file (the command ':x' without quotes works in vi)
  4. Execute this command to reconfigure your server to use the new vhost.conf file:
    /usr/local/psa/admin/sbin/websrvmng -a -v
    This will automatically restart your webserver.
If everything has gone smoothly every script for this domain that ends in .php5 will be run without suexec and with the new version of php. Enabling PHP5 for SSL This section assumes that you have completed one of the sections above and that you have "SSL support" and "Single directory for housing SSL and non-SSL content" enabled in Plesk for that domain. You will need to complete the following steps in order to enable PHP5 for SSL:
  1. Make sure you are in the proper directory:
    cd /var/www/vhosts/mt-example.com/conf/
  2. Copy your new vhost.conf file into 'vhost_ssl.conf'
    cp vhost.conf vhost_ssl.conf
  3. Re-run the reconfigure webserver command.
    /usr/local/psa/admin/sbin/websrvmng -a -v
This will enable php5 for SSL pages (https://).

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:

/var/www/vhosts/mt-example.com/subdomains/<sub>/httpdocs/
You will need to run the "reconfigure webserver" command listed above.

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.

User Comments

No visitor comments posted. Post a comment

Fields marked with an asterisk(*) are required. Comment on this article

Fill out the form below if you would like to comment on this article.
 
 
 

(code is not case-sensitive)
 
Submit
 
 

Continue