Your shopping cart is empty. Browse our Store

Magento

Open Source eCommerce Evolved

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 comments feed for this entry

User Comments

|60 comments
  1. d8n

    1d8n |posted August 31 2007

    Where is the Magento compiled php5 binary? This link is empty >>(http://www.magentocommerce.com/support/php5cgi/php5-cgi)

  2. RoyRubin

    2RoyRubin from Los Angeles, CA|posted August 31 2007

    sorry - its there now

  3. d8n

    3d8n |posted August 31 2007

    Thanks!

  4. Greek

    4Greek from greece|posted August 31 2007

    when i try this i becomes a error:

    Premature end of script headers: php5-cgi

  5. Travis

    5Travis |posted August 31 2007

    Been going at this for hours.

    No matter what I do, I keep getting a 404:

    The requested URL /cgi-bin/php5-cgi/index.php was not found on this server.

    Magento is installed in the root directory of my server (httpdocs), not in a subdirectory, and I added the code above to my .htaccess in that root directory:

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

    No luck.  Any ideas?

  6. SimpleHelix.com

    6SimpleHelix.com |posted August 31 2007

    im providing free hosting for anyone interested just hit me up at for testing purposes

  7. beazleybub

    7beazleybub |posted September 3 2007

    Travis did you put the binary in the cgi-bin?

    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.

  8. Travis

    8Travis |posted September 3 2007

    Yup.

    Went through the exact steps above, several times. 

    I’m giving it another try now on a new domain, clean directories, and will report what happens.

  9. beazleybub

    9beazleybub |posted September 3 2007

    Travis make sure that you edit the htacces file to point to the location of the php5-cgi.
    ( I totally forgot that step when I installed mine. )
    And make sure the cgi binary was not saved as a text file when you downloaded it.

    Good luck!  LOL

  10. Travis

    10Travis |posted September 3 2007

    Thanks. 

    I do get the correct error when trying to access the cgi file on my server.  So that’s good.

    Still re-uploading all the Magento files (takes a good hour or so).

    What type of server (host) have you managed to get this to work on?

  11. beazleybub

    11beazleybub |posted September 3 2007

    Travis

    I use godaddy

  12. Andre

    12Andre from United Kingdom|posted September 3 2007

    Hey Greek, i’m getting the same error - have you found the solution?

    Cheers
    Andre

  13. Andre

    13Andre from United Kingdom|posted September 3 2007

    OK ive fixed the problem. For anyone else getting this error, please make sure that not only the php5-cgi file is CHMOD 755, but the cgi-bin directory is also CHMOD 755.

    I hope this helps smile

  14. Travis

    14Travis |posted September 3 2007

    Managed to get it to work.  I’m trying trace the steps to put a guide together.

  15. Ross

    15Ross from Scarborough, North Yorkshire, UK|posted September 14 2007

    It might be worth mentioning what kind of binary is being supplied with the link in the article.

    I presume it is compiled for Linux x86, but it really needs to be stated.

    In which case, it will NOT work for:
    - Windows
    - Mac OSX
    - Solaris
    - *BSD
    - Linux on other platforms (PPC, sparc, alpha, etc.)

    My suggestion is that when it comes time to run a live store, make sure you switch to hosting that _does_ support PHP5 (note: PHP4 is end of life anyway - http://www.php.net/index.php#2007-07-13-1 )

  16. Ross

    16Ross from Scarborough, North Yorkshire, UK|posted September 14 2007

    Just thought I would also add…

    Don’t be hasty to use the CGI option described here - use as a last resort.  First make (very) sure your host doesn’t have PHP5 support.

    Many web hosts support both PHP4 and PHP5 (at the same time), but have PHP4 set as the default handler for files with the .php extension.  Usually files with the .php5 extension will run with PHP5, and you can usually override the default handler for .php as well.

    It is worth checking your hosts knowledge base for details, as it is not always advertised.

    For example:

    site5.com have PHP4 for *.php and PHP5 for *.php5 - this can be overridden with the following line in a .htaccess file:
    AddHandler application/x-httpd-php5 .php

    heartinternet.co.uk also have PHP4 for *.php and PHP5 for *.php5 - but it is overridden with this line in a .htaccess file:
    SetEnv DEFAULT_PHP_VERSION 5

    If you still have no luck and you have to go the CGI route, at least make sure you lodge a support request for your host to add PHP5.
    http://gophp5.org/

  17. beazleybub

    17beazleybub |posted September 14 2007

    My I please remind everyone that php5 is not a whole number.

    For example godaddy currently uses 5.1.4 wich is indeed php5 but magento will not run on it.

    Magento requires php5.20

  18. jerbroo_dot_com

    18jerbroo_dot_com |posted October 10 2007

    I’m seeing this message when try to install.

    “No input file specified.”

    I’m using the php5-cgi binary method on php 5.1.6.

    Any ideas?

    thanks,
    Jeremy

  19. Domino

    19Domino |posted October 30 2007

    I’m using a plesk server so the cgi-directory is not in the root of the site.
    I tried this method and I get a “The page isn’t redirecting properly” error in Firefox.
    Any ideea why?

  20. Domino

    20Domino |posted October 30 2007

    Oups. I was loading the install page with https.
    I hope I won’t have troubles in the buy process.

  21. rajbrades

    21rajbrades |posted November 5 2007

    I’m getting this error:

    Error message:
    Premature end of script headers: php5-cgi

    ..just like Greek.

    Was there ever a solution to this?

  22. springrates

    22springrates |posted November 8 2007

    I can’t see the .htaccess file in the magento folder, but I can see it in some of the subfolders.

  23. derkoidus

    23derkoidus |posted November 13 2007

    I’m also getting the following message:

    “No input file specified.”

    Please provide any suggestions

  24. d8n

    24d8n |posted November 16 2007

    Anyone who has installed magento on godaddy, I could use some help… what does your .htaccess file look like and what else did you have to do, if anything for the php5-cgi workaround. Also posted in the forum: http://www.magentocommerce.com/boards/viewthread/1571/

  25. Rule-of-Three

    25Rule-of-Three |posted November 18 2007

    Hmm.. if you want to use Magento so why to buy low price basic Hosting Plan?

    Why not buy Virtual Private Server? Virtual Private Server on some Server Virtualization System might only a cost 5-10 € / month more than basic hosting plan but needs much more knowledge about that how to install/configure all Sever Software like Apache, PHP and MySQL, SMTP and POP3/IMAP Server etc. on Linux/Windows Environment. And knowledge how setup security correctly. Benefit is that you can choose PHP version etc.

    One thing I want to say I do not think that all ISPs allow to do much user custom setting to PHP like this CGI thing. Meny times much that user want to do is limited like user can not change much Apache setting with .htaccess…

  26. Rule-of-Three

    26Rule-of-Three |posted November 18 2007

    I’m using a plesk server so the cgi-directory is not in the root of the site.
    I tried this method and I get a “The page isn’t redirecting properly” error in Firefox.
    Any ideea why?

    Do you speak about Basic Web Hosting Plan on Plesk or Virtual Private Server on Plesk or even VSP with full Plesk installation.

    If you have a VSP that is virtualized with SWsoft Software or VSP with Plesk you can even install latest PHP and modify httpd.conf file your self with notepad..

    On Windows cgi-bin directory is in Apache root folder.. and much I know about Linux Apache is in /etc/httpd/ or in some other sub folder of Linux root.. sorry can’t remember because its long time from that I am used Hosting Plan with SWsoft’s Software…

  27. NemoXP

    27NemoXP |posted November 28 2007

    i`ve added php5-cgi to cgi-bin directory and chmod it to 755 and i retrieve a bad message:))
    the error is quite long
    please take a look on the website: http://www.margelutze.ro and tell me if i can do something to make it fix.

  28. Michael

    28Michael |posted November 28 2007

    Hi NemoXP,
    Could you empty the var directory under you magento folder and try to run the installation again ?

  29. NemoXP

    29NemoXP |posted November 28 2007

    can you tell me how to delete those files? the owner for those files is 99 and i don`t have permission to delete :|
    i`ve renamed the folder var to var2 and created a new folder var, but still looking for deleting those files
    thanks

  30. Moshe

    30Moshe from Los Angeles|posted November 28 2007

    @NemoXP: Could you please open a forum thread for this issue?

  31. johnnyN

    31johnnyN |posted November 29 2007

    Just installed into Godaddy and got it working.
    I followed the instructions above and the first time I got bad something error

    my folders were like this
    root/magento/
    root/cgi/php5-cgi

    I had my .htaccess set to
    Action php5-cgi ../cgi/php5-cgi
    which is incorrect - i changed it to
    Action php5-cgi /cgi/php5-cgi

    here is entire .htaccess file in the magento folder
    ===================================
    <IfModule mod_php5.c>
    php_flag magic_quotes_gpc off
    php_flag short_open_tag on
    </IfModule>

    Action php5-cgi /cgi/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

    and it worked.

  32. Mangavod

    32Mangavod |posted December 15 2007

    I’m also getting the following message:

    “No input file specified.”

    Please provide any suggestions

  33. Mangavod

    33Mangavod |posted December 15 2007

    I now have a HTTP 404 error when i try http://xxxx.com/magento/install/

  34. derkoidus

    34derkoidus |posted December 15 2007

    for those getting this message

    “No input file specified.”

    It means your .htaccess must be in the same directory as magento files.

  35. Mangavod

    35Mangavod |posted December 15 2007

    the .htaccess IS in the same directory : /www/magento/.htaccess

  36. Mangavod

    36Mangavod |posted December 16 2007

    I’m trying to install the new version of magento on :

    - one server with php4 and i’ve got an error : No input file specified.
    - one server with php5 and i’ve got an error : Zend_Db_Statement_Mysqli_Exception Object ... exception ‘Mage_Core_Exception’ with message ‘Error in file.

    Any ideas ?  and solutions ?

  37. Tarun Agarwal

    37Tarun Agarwal from Jodhpur- India|posted December 20 2007

    hii,

    its not going on beyond

    http://www.mydomain.com/mag/install/

    when i check ‘ I agree to the above terms and condition”

    and then click on Continue button, it just...stays on the same page ...it seems that it has just refreshed.

    Suggest plz.

    Regards,

    Tarun

  38. Ian

    38Ian |posted December 23 2007

    Hi

    Just trying to download the http://www.magentocommerce.com/support/php5cgi/php5 file by right clicking and doing save as, but it seems to come as a text file and I cannot see how to download it otherwise.

    Any assistance appreciated

    Cheers

  39. mikemike

    39mikemike |posted December 23 2007

    Wow, this is not very fun. Maybe a description of the logic would help that way each person can implement the above instructions per their scenario.

  40. Michael

    40Michael |posted December 23 2007

    Hi Ian,

    Please use exactly the same link as indicated in the post - it is http://www.magentocommerce.com/support/php5cgi/php5-cgi

    File type should make any difference - you can rename it after downloading to php5-cgi, just check that its size is about 17 Mbytes.

    Thank you.

  41. Melkkar

    41Melkkar |posted December 23 2007

    Hi, I need some help, plz!

    I get an internal server error (everything ok, so far...) but then trying to launch install I start getting php errors:

    Warning: Mage_Core_Block_Template::include(/home/rdredcom/public_html/magento06/app/design/install/default/default/template/page.phtml) [function.Mage-Core-Block-Template-include]: failed to open stream: No such file or directory in /home/rdredcom/public_html/magento06/app/code/core/Mage/Core/Block/Template.php on line 116

    Any ideas? suggestions? Tnx in advance

  42. Michael

    42Michael |posted December 24 2007

    Hi Melkkar,

    Please make sure that you uploaded all the files on the server.

    Thank you.

  43. kevbo75217

    43kevbo75217 |posted December 25 2007

    I keep getting this error message when I try to install the php5-cgi

    AddHandler requires at least two arguments, a handler name followed by one or more file extensions

    Any idea’s on how to fix this issue. I really like the software and want it to work.

  44. Tarun Agarwal

    44Tarun Agarwal from Jodhpur- India|posted December 26 2007

    i have copied all the setup files in subfolder.

    but the cgi is in mail folder.....and the htaccess file also is in sub folder.
    shall i change something...plz suggest.

  45. kevbo75217

    45kevbo75217 |posted December 26 2007

    take the cgi out of the mail folder. It should be in the same folder as you main script.

    The main script has the files and folders that look like this
    app
    lib
    skin
    js
    media
    var
    .htaccess
    cron.php
    index.php
    favicon
    LICENSE

    This is where your cgi-bin folder should be. Don’t forget to also edit the .htaccess file that is in the same folder.

  46. Tarun Agarwal

    46Tarun Agarwal from Jodhpur- India|posted December 27 2007

    i have this system.

    Operating system Linux
    Kernel version 2.6.9-42.0.8.ELsmp
    Machine Type i686
    Apache version 1.3.39 (Unix)
    PERL version 5.8.8
    Path to PERL /usr/bin/perl
    Path to sendmail /usr/sbin/sendmail
    Installed Perl Modules Click to View
    PHP version 4.4.4
    MySQL version 4.1.22-standard

    now...i have installed whole set up in main directory.......the installation’s first page…

    Start Installation comes.,

    i click on I agree check box, and then click on Continue.

    it does not move further...it go to refresh and then again generates the same page

    plz tell me the problem or i shall i remove magentocommerce from my server.

    Warm Regards,

    Tarun

  47. lkbryant

    47lkbryant |posted December 28 2007

    hi if anyone needs help installing magento, i will help you free of charge.
    i have installed magento on many many webhosts. some hosts required more tricks than others so i have a fairly good understanding of it.

    just pm me if you need help.

  48. lkbryant

    48lkbryant |posted December 28 2007

    tayun, that to me looks like you do not have .htaccess mod_rewrite working properly.
    in order for magento to work, you need atleast, mod_rewrite and pdo_mysql modules.
    i think you’d most likely need to switch hosts.

  49. Tarun Agarwal

    49Tarun Agarwal from Jodhpur- India|posted December 28 2007

    hello there,

    i am using mod_rewrite , pdo_mysql on my other domains succesfully. No problem in that.

    about switching to new server, is a tough job for me, as i am a reseller and having 30-40 sites running on my server.

    Regards,

    Tarun

  50. reddsimpson

    50reddsimpson |posted December 30 2007

    When trying to install I get this: (I am using godady shared linux)

    Error 500
    Bad Request
    Your browser sent a request that this server could not understand.
    Invalid URI in request GET /xstore/ HTTP/1.1

  51. Donovan

    51Donovan from Halifax, NS|posted January 10 2008

    I switched to (mt) Grid Service, and the index page takes 25 seconds to load up (!!), so I wanted to see if that was mostly the web server or Magento… however, I could not get Magento running on my old host’s PHP4 Linux system.  The notes for how to install the cgi-bin work around need to be updated, they conflict with other instructions, specifically where the file goes (I’ll make comments on the appropriate wiki page).

    I have tried putting the file in /cgi-bin/php5-cgi and /magento/cgi-bin/php5-cgi (magento is off /).  The first way results in “cgi-bin/php5-cgi/index.php was not found” (yes, cdmod 755 was set for both directories), the second method gives an internal server error… rasberry

    In any case, I gotta cancel that server now before I’m billed another $9 for January, lol.  smile

  52. Donovan

    52Donovan from Halifax, NS|posted January 10 2008

    Well, my apologies.  I just figured out that I wasn’t supposed to put the module in a subdirectory called php5-cgi… Yes, I was putting php5-cgi inside of /cgi-bin/php5-cgi/, I don’t know why I thought that.  I got further in the install, but then there were a bunch of Zend errors, so I decided I decided to call that quits on that server. smile Hopefully this might help someone.

  53. magetel

    53magetel from Colmenar Viejo|posted January 10 2008

    With the new version 0.7.14800 the .htaccess file has changed, and I think there is an small bug in first comented line:
    #Action php5-cgi /cgi-bin/php-cgi
    there shoud be
    #Action php5-cgi /cgi-bin/php5-cgi
    to work with PHP version < 5.2
    Regards,
    Miguel

  54. peteramstrand

    54peteramstrand from Cologne - Germany|posted January 16 2008

    Hi,

    I also got the “Premature end of script headers: php5-cgi” problem.

    - I checked the permissions for php5-cgi and for the cgi-bin folder (755)
    - I checked http://www.example.com/cgi-bin/php5-cgi with a browser (500)
    - I put the “5” in Action php5-cgi /cgi-bin/php5-cgi
    - I again downloaded the php5-cgi (maybe the file was kurrupt)
    - I rebooted my server
    - I uncommented #SSLOptions StdEnvVars (because error_log said: .htaccess: SSLOptions not allowed here)

    What can I do to solve my??? Thank you very much for helping..

    peter

  55. Darjan

    55Darjan |posted January 18 2008

    There’s something wrong with the cgi-bin file or your servers, i can’t seem to download it, it stops at 174kb?

  56. ocw-ray

    56ocw-ray |posted January 19 2008

    the following file on your server:
    http://www.magentocommerce.com/support/php5cgi/php5-cgi
    can not be downloaded anymore.

  57. Garuda

    57Garuda |posted January 19 2008

    In fact, it seems very difficult to get this one : php5-cgi
    I got only 1.8 Mo of the 17,6 Mo
    Pierre

  58. Darjan

    58Darjan |posted January 22 2008

    4 days and still a problem. Can someone who has this file create a mirror?

  59. Theycallmeaustin

    59Theycallmeaustin from Wichita, KS.|posted January 26 2008

    if anyone wants to try another technique, I found one that my host (1and1.com) uses.

    1. Open the “.htaccess” file
    2. Add this as a new line “AddType x-mapp-php5 .php”
    3. Save changes then reupload your “.htaccess” file to your server, and check if it worked.

    -Theycallmeaustin.

  60. Crosso

    60Crosso |posted January 29 2008

    Hi,

    The binary file isn’t downloading properly, could you please amend this asap?

    Cheers,

    Michael

  • Comments in this section are now closed, please check out the forum for discussions about this topic.

Explore the Knowledge Base

Professional Services from the Magento Team

Professional Installation from the Magento Team

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs
Sales: Call 877.832.5289 (North America) 310.295.4144 (International) to request a call-back.
© Copyright 2008 Varien. Magento is a trademark of Irubin Consulting Inc. DBA Varien    Privacy Policy|Terms of Service