Experiment on configuring the module mode, cgi Mode, and fastcgi mode of php in apache

Source: Internet
Author: User
Install apache, mysql, and php in sequence. 1. The installation of apache and mysql is relatively simple. I skipped 2. php installation. I installed php5.3.6 with the built-in php-fpm, so I don't need to install a separate patch .. Configureprefixusrlocalphp5 -- with-mysqlusrlocalmysql -- enable-fpm -- wi

Install apache, mysql, and php in sequence. 1. The installation of apache and mysql is relatively simple. I skipped the installation of 2.php. I installed php5.3.6 with the built-in php-fpm, so I don't need to install a separate patch. ./Configure prefix =/usr/local/php5/-- with-mysql =/usr/local/mysql/-- enable-fpm -- wi

Install apache, mysql, and php in sequence.

1. The installation of apache and mysql is relatively simple, skipped

2. For php installation, I installed php5.3.6 with the built-in php-fpm, so I don't need to install the patch separately.

./Configure-prefix =/usr/local/php5/
-- With-mysql =/usr/local/mysql/
-- Enable-fpm
-- With-apxs2 =/usr/local/apache/bin/apxs

Note:

-- Enable-fastcgi

-- Enable-force-cgi-redirect

These two new php versions have built-in support. Therefore, if these two parameters are added, the system prompts that these two parameters cannot be found after make is complete. Therefore, you do not need to add these two parameters.

With-apxs2

This parameter cannot be configured in some articles that require fastcgi mode. In fact, this is not exactly the case, the purpose of this parameter is to compile the php interpretation module into the so file and add it to the modules of apache and automatically add it to the conf file. If you do not want to use the module mode, run the following command in httpd. conf:

LoadModule php5_module modules/libphp5.so

This line can be commented out.

3. Install mod_fastcgi

# Wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz

# Tar-zxvf mod_fastcgi-2.4.6.tar.gz

# Cd mod_fastcgi-2.4.6

# Cp Makefile. AP2 Makefile

# Vim Makefile: change the path in Makefile to your apache installation path.

# Make install

After the installation is successful, mod_fastcgi.so will be automatically copied to the/usr/local/apache/modules directory

The following describes how to configure the four modes:

1. Module Mode

This mode is the easiest to add in http. conf

LoadModule php5_module modules/libphp5.so

You can. Then

AddType application/x-httpd-php. php
AddType applicaiton/x-httpd-php-source. phps

2. CGI Mode

This mode needs to be commented out

LoadModule php5_module modules/libphp5.so. If you do not comment this line, it will always go to the handler mode. That is, the module mode.

Then add action in httpd. conf:

Action application/x-httpd-php/cgi-bin/php-cgi

If you cannot find php-cgi in the/cgi-bin/directory, you can use cp in the php bin.

Restart apache, open the test page, and find that the Server API becomes CGI/FastCGI. It indicates that the cgi Mode is successfully switched.

3. FastCgi mode, with apche built-in Process Manager

First, add the fastcgi module to the httpd. conf configuration file:

LoadModule fastcgi_module modules/mod_fastcgi.so

This mode annotation does not comment out LoadModule php5_module modules/libphp5.so this line seems to have nothing to do with, as long as the following module is configured


FastCgiServer/usr/local/apache/cgi-bin/php-cgi-processes 20
AddType application/x-httpd-php. php

AddHandler php-fastcgi. php

Action php-fastcgi/cgi-bin/php-cgi

It will automatically go to fastcgi mode.

Restart apache and use ps aux | grep php to check that many php-cgi processes are running. Indicates that the configuration takes effect.

4. FastCgi mode, using the php-fpm Process Manager

First, add the fastcgi module to the httpd. conf configuration file:

LoadModule fastcgi_module modules/mod_fastcgi.so

Then modify the configuration file:


FastCgiExternalServer/usr/local/apache/cgi-bin/php-cgi-host 127.0.0.1: 9000

AddType application/x-httpd-php. php

AddHandler php-fastcgi. php

Action php-fastcgi/cgi-bin/php-cgi

Note that 127.0.0.1: 9000 is the enabled port of php-fpm, so we also need to open php-fpm.

My computer is located.

>>>/Usr/local/php5/sbin/php-fpm

After enabling ps aux | grep php

You will find many php-fpm processes:

Root 7002 0.4 1.5 13060 1912? Ss php-fpm: master process (/usr/local/php5/etc/php-fpm.conf)
Nobody 7003 0.0 1.3 13052? S php-fpm: pool www
Nobody 7004 0.0 1.3 13052? S php-fpm: pool www
Nobody 7005 0.0 1.3 13052? S php-fpm: pool www
Nobody 7006 0.0 1.3 13052? S php-fpm: pool www
Nobody 7007 0.0 1.3 13052? S php-fpm: pool www
Nobody 7008 0.0 1.3 13052? S php-fpm: pool www
Nobody 7009 0.0 1.3 13052? S php-fpm: pool www
Nobody 7010 0.0 1.3 13052? S php-fpm: pool www
Nobody 7011 0.0 1.3 13052? S php-fpm: pool www
Nobody 7012 0.0 1.3 13052? S php-fpm: pool www
Nobody 7013 0.0 1.3 13052? S php-fpm: pool www
Nobody 7014 0.0 1.3 13052? S php-fpm: pool www
Nobody 7015 0.0 1.3 13052? S php-fpm: pool www
Nobody 7016 0.0 1.3 13052? S php-fpm: pool www
Nobody 7017 0.0 1.3 13052? S php-fpm: pool www
Nobody 7018 0.0 1.3 13052? S php-fpm: pool www
Nobody 7019 0.0 1.3 13052? S php-fpm: pool www
Nobody 7020 0.0 1.3 13052? S php-fpm: pool www
Nobody 7021 0.0 1.3 13052? S php-fpm: pool www
Nobody 7022 0.0 1.3 13052? S php-fpm: pool www

Then we can test whether the access is correct.

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.