Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override PHP configuration when running in CGI mode

There are some tutorials out there telling me how to override PHP configuration when it is running in CGI mode. But I'm still confused because lots of them assume that the server is running on Linux. While I need to do that also on Windows.

My hosting is indeed using Linux but my local development computer is using Windows XP with Xampp 1.7.3. So I need to do that in my local computer first, then I want to change the configuration on hosting server.

The PHP in my hosting server is already run as CGI while in my local computer still run as Apache module.

At this point, the processes that I understand are:

  1. Change PHP to work in CGI mode. I did this by commenting these two line in "httpd-xampp.conf":

    # LoadFile "C:/xampp/php/php5ts.dll"
    # LoadModule php5_module modules/php5apache2_2.dll

  2. My PHP is now running as CGI. I checked this with phpinfo(). It tells me that the Server API is now CGI/FastCGI. Now I want to override php configuration.

  3. Create "cgi-bin" directory in DocumentRoot. My DocumentRoot is in "D:\www\" (I'm using apache with virtual host). So it is now "D:\www\cgi-bin".

  4. Change the default "cgi-bin" directory settings from "C:/xampp/cgi-bin/" to "D:\www\cgi-bin":

    ScriptAlias /cgi-bin/ "D:/www/cgi-bin/"

    <Directory "D:\www\cgi-bin">
       Options MultiViews Indexes SymLinksIfOwnerMatch Includes ExecCGI
       AllowOverride All
       Allow from All
    </Directory>
    
  5. Copy 'php.ini' file to "D:\www\cgi-bin" and modify upload_max_filesize setting from 128M to 10M.

  6. Create 'php.cgi' file in "D:\www\cgi-bin" and put these code inside the file:

    #!/bin/sh
    /usr/local/cpanel/cgi-sys/php5 -c /home/user/public_html/cgi-bin/

That's it. I'm stuck at this point. All of tutorials tell me to create 'php.cgi' file and put shell code inside the file.

How to do the 6th step on Windows? I know the next step is to create handler in .htaccess file to load that 'php.cgi'.

And also, because I will also need to change PHP configuration on my hosting server (Linux), is the 6th step above right? Some tutorial tells to insert these lines instead of above:

#!/bin/sh
export PHPRC=/site/ini/1
exec /cgi-bin/php5.cgi

I'm sorry if my question is not clear. I'm a new member and this is my first question in this site.

Thank you.

like image 942
Fitrah M Avatar asked Jan 03 '11 00:01

Fitrah M


People also ask

Can PHP run on CGI?

Running PHP as a CGI If you need to run an older version of PHP in order to maintain compatibility with your legacy software, you may run PHP as a CGI.

Is CGI faster than PHP?

On average, the PHP version is faster than the ASP version, while the CGI (C++) version is more than 10 times faster than both PHP and ASP.

What is PHP CGI mode?

PHP CGI means using the PHP interpreter through CGI mode. The web server will pass the data from the request to PHP (an external program); its input is a PHP file (usually on the server) and its output is HTML code (usually rendered in the client's browser). PHP CGI configuration is set via PHP INI directives files.


1 Answers

If your server is already running PHP as cgi, and you do not need to run multiple PHP configurations, steps 5 and 6 are not necessary. Just change the default php.ini

like image 130
Svemir Brkic Avatar answered Oct 05 '22 23:10

Svemir Brkic