Install and configure Apachephp-cgi in Linux

Source: Internet
Author: User
Tags apache php php cli sapi microsoft iis
& Nbsp; 1. differences between php-cgi and php-cli. In general, PHP is a product running on the Web environment and is developed in a hybrid manner with HTML tags, display the result in a browser as an interactive script. PHP is located in the middle layer between the Web server (Apache, MicrosoftIIS, etc.) and the user, called SAPI (alternative forweb 1, php-cgi and php-cli differences

In general, PHP is a product running in the Web environment. it is developed in a mix of HTML tags and displays the results in a browser as an interactive script. PHP is located at the intermediate layer between the Web server (Apache, Microsoft IIS, etc.) and the user. it is called the SAPI (Short for web server API ). On the Web server, PHP always acts as a reference and user interface function.

The php cli version is similar to the CGI mode of PHP. although there are many common behaviors between them, CLI and CGI belong to different SAPIs.


CLI does not use GET or POST form processing, does not have MIME header information output, and other implicit SAPI implementation.
2. install the required software


Wget http://museum.php.net/php5/php-5.2.6.tar.gz
Wget http://jaist.dl.sourceforge.net/sourceforge/mod-fcgid/mod_fcgid.2.2.tgz
Wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
Wget http://www.apache.org/dist/httpd/httpd-2.2.15.tar.gz

2. install apache

Tar-zvxf httpd-2.2.15.tar.gz
Cd httpd-2.2.5
Mkdir-p/usr/local/apache
./Configure-prefix =/usr/local/apache-enable-modules = so-enable-rewrite
Make
Make install

3. install mod_fcgid and mod_fastcgi

Tar zxvf mod_fcgid.2.2.tgz
Cd mod_fcgid.2.2
Make
Make install

Open the Makefile file before installation, and set top_dir =/usr/local/apache to your apache installation directory, the generated mod_fastcgi.so file is automatically stored in the modules file of apache.

Tar zxvf mod_fastcgi-2.4.6.tar.gz
Cd mod_fastcgi-2.4.6
Cp Makefile. AP2 Makefile
Make
Make install

Like above: Open the Makefile file before installation, and set top_dir =/usr/local/apache in it to your apache installation directory, the generated mod_fcgid.so file is automatically stored in the modules file of apache.

If top_dir is not modified, the generated. so file is in your installation directory. it is also possible to manually copy it to the modules of apache. I have not tried this.

4. configure apache

Here, we will only briefly describe the configuration of fastcgi, and find other configuration items on the Internet.

LoadModule fastcgi_module modules/mod_fastcgi.so

FastCgiServer/usr/local/apache/fcgi-bin/php-processes 10 // number of processes that start php-cgi
ScriptAlias/fcgi-bin/"/usr/local/apache/fcgi-bin/" // start the php-cgi process path
AddHandler php-fastcgi. php

SetHandler fastcgi-script

Action php-fastcgi/fcgi-bin/php restart

Check the modules loaded by apache.

/Usr/local/apache/bin/httpd-l
See if mod_cgi.c is available.

5. install php (fastcgi mode)

Tar zxvf php-5.2.6.tar.gz
Cd php-5.2.6
. /Configure-prefix =/usr/local/php-with-mysql =/usr/local/mysql-with-zlib-dir-with-freetype-dir =/usr-- jpeg-dir =/usr-with-png-dir =/usr-enable-gd-native-ttf-with-gd-enable-ftp-with-iconv-with-gettext- with-curl-enable-fastcgi-with-openssl
Make & make install

Note: the compilation parameters cannot be added-with-apxs2 =/usr/local/apache2/bin/apxs; otherwise, the installed php execution file is in cli mode, that is, the command mode.

Another point is that previously, I installed php in cli mode. before installing cgi mode, I did not delete the original file in the installation directory, so there are two in my bin directory, one is the php command mode and the other is the fastcgi mode.

After installation, check it.

/Usr/local/php/bin/php-v

PHP 5.2.6 (cgi-fcgi) (built: Jan 20 2010 13:09:17)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
With eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator

If the red one appears, it indicates that your php supports fastcgi.




Apache cgi

Is under my/usr/local/php/bin/, if you want to use php-cgi, cp php-cgi php, if you want to use php-cli, cp php-cli php

6. start apache and php-cgi and view

Start apache

/Usr/local/apache2/bin/apachectl start




View apache php-cgi

Why is it php, not php-cgi? it is actually the same thing, but its name is different. Because the php file under/usr/local/apache/fcgi-bin calls php under bin. if you want to display php-cgi, you can use ln to create a php-cgi soft link in fcgi-bin and name it php. the soft link is equivalent to a shortcut in windows. Haha
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.