How to Use PHP 5
The following text was taken (and edited) from the following forum posts:
The Quick and Easy Way
Simply add this line to your .htaccess file:
AddType application/x-httpd-php5 .php
That's it. All your php scripts now run under PHP 5.
The More Involved and Customizable Method
However, if you need to customize parameters (such as upload_max_filesize, memory_limit), you won't be able to enable those through .htaccess (like you would with php4) and you won't be able to edit the server's php.ini file. So to customize php5 for your specific site, you'll need to be sure you .htaccess contains both of these lines:
Action application/x-httpd-php5 /php5.fcgi
AddType application/x-httpd-php5 .php
And you'll need to use the custom php5.fcgi script below.
How It Works
We've added PHP5 running through
FastCGI. It's like a CGI, except fast, as the name implies. The short of it is that your PHP5 interpreter stays running even after the request for a page has been completed. Unlike CGI, this means you don't have to incur the expensive task of starting up PHP from scratch on every page load.
Every server has a separate copy of PHP5 installed at
/usr/local/php5-fcgi/ that is compiled with
FastCGI support. Just like you do with Ruby, you need a way to hook that up to execute when a .php5 file is hit. To make things easy, we've added a default configuration in Apache to all the servers that runs all .php5 files through a shell script. In reality, you can have that script do whatever you want, but ideally it will just call over to the PHP5 binary and get the party started.
Using PHP5
First, create a file in your
public_html directory called
php5.fcgi. If this is a subdomain put the file in the subfolder for the site instead of public_html. This script will be called whenever there is a request to a .php5 page and there are no active
FastCGI PHP processes running. You will need to
CHMOD this script as
755 to ensure it functions properly. In it, you'll want to put this:
#!/bin/sh
PHP_FCGI_CHILDREN=2
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=500
export PHP_FCGI_MAX_REQUESTS
exec /usr/local/php5-fcgi/bin/php
That's all there is to it. What is that script doing? Well, it sets some basic
FastCGI-related environmental variables to ensure that you don't have a ton of
FastCGI processes starting up and that they are killed off after 500 requests to protect against memory leaks. Please don't increase these values as they could lead to unstable operation of your server. Be a good neighbor!
Custom php.ini
Since you're free to make some changes to this script, you can also set it up to run your own
php.ini file. You can change the last line to this:
exec /usr/local/php5-fcgi/bin/php -c /home/username/php.ini
That will point to a
php.ini file in your home directory that you can set up with whatever options you'd like. We have used the default
php.ini-dist file for the copies of PHP5 on all the servers, so you can use
this php.ini file to start with. Feel free to make any configuration changes you like, but remember to consider the fact that you're on a server with other users. Do your best to disable any potential
security∞-related settings (like
register_globals∞) or performance-related settings (like
MySQL persistent connections).
So, go and enjoy all the new features and changes that PHP5 has to offer.
Link to server's default php.ini for php5:
INFOphpini
Notes and Considerations
- The php5.fcgi file MUST contain only UNIX type line endings otherwise this won't work.
- The php5.fcgi file MUST must have appropriate permissions, such as CHMOD 755.
- A .htaccess file may be used to set various settings, including addtype for extensions.
- If you use the custom php5.fcgi in the ~/public_html directory for your primary domain, you *must enable this for all your addon domains and place the php5.fcgi and .htaccess files for all your Addon Domains
- See also the PHP wiki page
There are 2 comments on this page. [Display comments]