Converting from mod_php to php-cgi : Steps to take for a seemless upgrade

Question:

I’d like to change from mod_php to php-cgi. What steps should I take to make sure the change is smooth?

Answer:

Most conversions are as simple as selecting the new version to use in the control panel. If a small amount of possible downtime on your site is acceptable you may want to just try the change and see. In the worst case, you’ll have to wait as long as 15 minutes to switch back to the old version.

The server looks for changes and reloads (if needed) your php configuration every 15 minutes. If you make the change and find you site has problems, you’ll need to “undo” the change by selecting the version you were running previously. You’ll then need to wait for the server to reload your config. Note: During this time your site still runs – there is no downtime – but it does not run the new php version.

If you want near-zero probability of problems (or if you tried the approach above and ran it problems), we recommend the following:

1. Make sure there are no files owned by the generic server user “nobody”. Do this:

find /home/your_user_name_here -user nobody -print

If it shows files owned by nobody, you’ll need to put in a support request for an admin to change the ownership back to your own username.

2. Use the php.ini file that your site was running under before :


mkdir /home/your_username_here/etc/
cp /usr/local/lib/php.ini /home/your_username_here/etc/

4. Make sure date.timezone is set in php.ini. A common problem ugprading to php5.3 is not having date.timezone set. It needs to be set either in your code or (easier) in php.ini

An example for EST timezone is :

date.timezone = 'America/New_York'

5. Check the php.net changelog documentation for any functions that have been removed or changed between the version you are currently running and the version you are upgrading to.

Running a different php version for only part of my website

Update: for newer accounts use :

php-script

instead of

custom-php

You can also set the php version on a per-directory basis (for testing, development, etc.). To run a different php version on part of your site, perform the following.

Create a .htaccess file :

.htaccess

(the leading dot is required)

inside the top level directory for which you want to change the php version.

Inside the file put the lines:

AddHandler custom-php .php .pcgi .phtml .inc .phtml~ .php~ .inc~ .html~
Action custom-php /cgi-sys/php5.6

some users may need the following instead:

Action php-script /cgi-sys/php7
AddHandler php-script .php .maml .html .css .mss .pcgi .phtml .inc .phtml~ .php~ .inc~ .html~

Replace php5.6 with which ever version you want to run
You can also add other file extensions to the list in the first line.

Depending upon the server and current php verison, you can choose from among:

/cgi-sys/php8.1
/cgi-sys/php7
/cgi-sys/php7.4
/cgi-sys/php5.6

etc.

In general, many php<major-version>.<minor-version> will work. The possible versions may vary. Contact support if a version you need is missing.

Historical Notes:

The following no longer is allowed. This is kept for historical reference:

To run a part of your site as mod_php, add this line to a .htaccess in the directory you want to run as mod_php :


AddHandler application/x-httpd-php .php3 .phtml .php .php4 .php~ .php3~ .php4~ .phtml~ .inc .inc~