Installing Magento on a PHP4 server

Introduction

Some hosting providers do not yet provide PHP5 on their servers, opting instead to stay with PHP4 for the time being. As Magento is a PHP5-only application, this can be a barrier for some users. This document outlines a possible workaround for such a scenario. The goal is to install PHP5 as a CGI binary and configure the web server (Apache) to use it instead of the default PHP4.

Requirements

Every hosting provider has a slightly different way of doing things, so it's important to know if this method will work with your provider before continuing.

Below is a list of the basic requirements that this document expects. If you're unsure as to whether your provider supports these requirements, pass the list along to them and find out.

  • Operating System: Linux
  • Web Server: Apache with CGI support
  • FileInfo override control via .htaccess files
  • A user-writable cgi-bin directory
  • FTP access to your web root and cgi-bin directories

Step 1: Upload the PHP5 CGI binary

It is possible to compile a PHP5 binary yourself, but for the purposes of this solution, we've provided one for you. You can download it here: http://www.magentocommerce.com/support/php5cgi/php5-cgi (if you are using IE you will need to right click on this link and save file as). This file is also available in .zip (7.2 MB), .tar.gz (7.2 MB), and .tar.bz2 (6.8 MB) formats to download (the files contain exactly the same php5-cgi binary inside and are provided in different formats just for your convenience).

Once downloaded, use your FTP client to upload the file to your cgi-bin directory. If you don't know where your cgi-bin directory is, ask your hosting provider.

After uploading, use your FTP client to set the proper mode of the php5-cgi file. This function varies for each FTP client, but it usually called Change Permissions or Change Mode or Chmod. Once you find the function, you must set the permissions so the web server can run this file. There are two typical ways of representing file permissions in Linux:

  • As a number (eg, 755)
  • As a series of permissions categorized into user, group, and other

If your FTP client uses the first representation, set the permission on the php5-cgi binary to be 755, or 0755. If your FTP client uses the second representation, set the permissions as shown in the image below.

image

Step 2: Modify the Magento .htaccess file

By default, the web server will want to run the Magento application using PHP4, which will not work. In order to point it to the new PHP5 CGI binary, you must modify the .htaccess file in the Magento top-level directory.

Using your FTP client, edit the file .htaccess in your top-level magento directory.

The existing file looks something like this:

<IfModule mod_php5.c>
    
php_flag magic_quotes_gpc off
    php_flag short_open_tag on
</IfModule>

DirectoryIndex index.php

RewriteEngine on

#RewriteBase /

RewriteCond %{REQUEST_URI} !^/media/
RewriteCond %{REQUEST_URI} !^/skin/
RewriteCond %{REQUEST_URI} !^/js/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d
RewriteCond 
%{REQUEST_FILENAME} !-l

RewriteRule 
.* index.php

Add two lines to it so it looks like this:

<IfModule mod_php5.c>
    
php_flag magic_quotes_gpc off
    php_flag short_open_tag on
</IfModule>

Action php5-cgi /cgi-bin/php5-cgi 
AddHandler php5
-cgi .php
 
DirectoryIndex index
.php

RewriteEngine on

#RewriteBase /

RewriteCond %{REQUEST_URI} !^/media/
RewriteCond %{REQUEST_URI} !^/skin/
RewriteCond %{REQUEST_URI} !^/js/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d
RewriteCond 
%{REQUEST_FILENAME} !-l

RewriteRule 
.* index.php

You'll want to modify the path in the Action line to point to the location of the php5-cgi binary you uploaded in Step 1.

Now test your Magento installation by visiting it with your web browser. If you see Magento smiling back at you, then you are now happily running on PHP5.

Troubleshooting

I still see "Invalid PHP version" when visiting my Magento page.
This probably means that your hosting provider does not allow the FileInfo overrides via .htaccess files. This is a necessary requirement for this solution, so you'll have to ask your hosting provider for it.

I see "Internal Server Error" when visiting my Magento page.
This is a typical error message when a CGI binary quits unexpectedly, and could be caused by a number of things. If you have access to your server's Apache error log, you can look there for some clues. We'll cover a few more common issues here.

  1. Bad location to the PHP5 binary
    Make sure the AddHandler directive in your .htaccess file is pointing to the correct location for the PHP5 binary. You can often test it by trying to surf to the location with your web browser. For example, if your site is http://www.example.com and your PHP5 location is /cgi-bin/php5-cgi, try visiting http://www.example.com/cgi-bin/php5-cgi with your web browser. If you see a Internal Server Error message, then that means your PHP5 binary is in the correct location. If you get a File not found message, then this is not the correct location.
  2. Bad permissions on the PHP5 binary
    Double check the permissions on the PHP5 CGI binary you uploaded in Step 1. They should be 755 or rwxr-xr-x, depending on your FTP client's representation.
More details about specific environment quirks could be found here: http://www.askapache.com/php/custom-phpini-tips-and-tricks.html

RSS: New Article posts

Explore the Knowledge Base