Home php教程 php手册 apache中配置php支持模块模式、cgi模式和fastcgi模式的实验

apache中配置php支持模块模式、cgi模式和fastcgi模式的实验

Jun 06, 2016 pm 07:43 PM
apache cgi php support module model Configuration

首先安装apache、mysql和php,依次顺序安装。 1.apache、mysql的安装比较简单,略过 2. php的安装,我安装的是php5.3.6内置了php-fpm,所以不需要再单独下补丁了。 ./configure prefix=/usr/local/php5 / --with-mysql=/usr/local/mysql / --enable-fpm --wi

首先安装apache、mysql和php,依次顺序安装。

 

1.apache、mysql的安装比较简单,略过

 

2. php的安装,我安装的是php5.3.6内置了php-fpm,所以不需要再单独下补丁了。

./configure –prefix=/usr/local/php5 /
--with-mysql=/usr/local/mysql /
--enable-fpm
--with-apxs2=/usr/local/apache/bin/apxs
 

注意:

--enable-fastcgi

--enable-force-cgi-redirect

这2个php新版本已经内置支持,所以如果加上这2个参数,make完毕会提示这2个参数找不到。所以不需要加这2个参数了。 

 

--with-apxs2

这个参数看到有的文章说需要fastcgi模式的话,就不能配置这个,其实也不完全是这样,这个参数的用途只不过是把php的解释模块编译成so文件添加到apache的modules中,并且自动添加到conf文件。如果我们不想用模块模式的话,在httpd.conf中把:

LoadModule php5_module modules/libphp5.so

这行注释掉就可以了。

 

3.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 将Makefile中的路径改成你的apache的安装路径

# make install 安装成功

安装成功后,会自动把mod_fastcgi.so复制到/usr/local/apache/modules目录  

 

接下来是如何配置这4种模式:

1.模块模式

这种模式最简单,在http.conf中增加

LoadModule php5_module modules/libphp5.so

即可。然后在

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

 

2.CGI模式

这种模式需要注释掉

LoadModule php5_module modules/libphp5.so 这行。如果不注释这行会一直走到handler模式。也就是模块模式。

然后在httpd.conf增加action:

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

如果在/cgi-bin/目录找不到php-cgi.可自行从php的bin里面cp一个。

然后重启apache,再打开测试页面发现Server API变成:CGI/FastCGI。说明成功切换为cgi模式。

 

3.FastCgi模式,用apche内置进程管理器

首先要添加fastcgi模块到httpd.conf配置文件:

LoadModule fastcgi_module modules/mod_fastcgi.so

 这种模式注释不注释LoadModule php5_module modules/libphp5.so这行貌似没什么关系,只要配置了以下模块


   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

就会自动走到fastcgi模式。

然后重启apache,这个时候用 ps aux|grep php就会发现有很多php-cgi进程在运行。说明配置生效

 

 

 

 

4.FastCgi模式,用php-fpm进程管理器

首先要添加fastcgi模块到httpd.conf配置文件:

LoadModule fastcgi_module modules/mod_fastcgi.so

接着修改配置文件成:


   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

 

注意,127.0.0.1:9000是php-fpm的开启端口,所以我们还需要把php-fpm打开。

我电脑的位置是.

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

 

打开后再ps aux|grep php

会发现很多php-fpm的进程:

root      7002  0.4  1.5  13060  1912 ?        Ss   15:20   0:00 php-fpm: master process (/usr/local/php5/etc/php-fpm.conf)
nobody    7003  0.0  1.3  13052  1656 ?        S    15:20   0:00 php-fpm: pool www
nobody    7004  0.0  1.3  13052  1660 ?        S    15:20   0:00 php-fpm: pool www
nobody    7005  0.0  1.3  13052  1660 ?        S    15:20   0:00 php-fpm: pool www
nobody    7006  0.0  1.3  13052  1660 ?        S    15:20   0:00 php-fpm: pool www
nobody    7007  0.0  1.3  13052  1660 ?        S    15:20   0:00 php-fpm: pool www
nobody    7008  0.0  1.3  13052  1660 ?        S    15:20   0:00 php-fpm: pool www
nobody    7009  0.0  1.3  13052  1660 ?        S    15:20   0:00 php-fpm: pool www
nobody    7010  0.0  1.3  13052  1660 ?        S    15:20   0:00 php-fpm: pool www
nobody    7011  0.0  1.3  13052  1660 ?        S    15:20   0:00 php-fpm: pool www
nobody    7012  0.0  1.3  13052  1668 ?        S    15:20   0:00 php-fpm: pool www
nobody    7013  0.0  1.3  13052  1672 ?        S    15:20   0:00 php-fpm: pool www
nobody    7014  0.0  1.3  13052  1672 ?        S    15:20   0:00 php-fpm: pool www
nobody    7015  0.0  1.3  13052  1672 ?        S    15:20   0:00 php-fpm: pool www
nobody    7016  0.0  1.3  13052  1672 ?        S    15:20   0:00 php-fpm: pool www
nobody    7017  0.0  1.3  13052  1672 ?        S    15:20   0:00 php-fpm: pool www
nobody    7018  0.0  1.3  13052  1672 ?        S    15:20   0:00 php-fpm: pool www
nobody    7019  0.0  1.3  13052  1672 ?        S    15:20   0:00 php-fpm: pool www
nobody    7020  0.0  1.3  13052  1676 ?        S    15:20   0:00 php-fpm: pool www
nobody    7021  0.0  1.3  13052  1672 ?        S    15:20   0:00 php-fpm: pool www
nobody    7022  0.0  1.3  13052  1676 ?        S    15:20   0:00 php-fpm: pool www

 

再测试下访问没问题,大功搞成咯。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

How to set the cgi directory in apache How to set the cgi directory in apache Apr 13, 2025 pm 01:18 PM

To set up a CGI directory in Apache, you need to perform the following steps: Create a CGI directory such as "cgi-bin", and grant Apache write permissions. Add the "ScriptAlias" directive block in the Apache configuration file to map the CGI directory to the "/cgi-bin" URL. Restart Apache.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

How to start apache How to start apache Apr 13, 2025 pm 01:06 PM

The steps to start Apache are as follows: Install Apache (command: sudo apt-get install apache2 or download it from the official website) Start Apache (Linux: sudo systemctl start apache2; Windows: Right-click the "Apache2.4" service and select "Start") Check whether it has been started (Linux: sudo systemctl status apache2; Windows: Check the status of the "Apache2.4" service in the service manager) Enable boot automatically (optional, Linux: sudo systemctl

How to delete more than server names of apache How to delete more than server names of apache Apr 13, 2025 pm 01:09 PM

To delete an extra ServerName directive from Apache, you can take the following steps: Identify and delete the extra ServerName directive. Restart Apache to make the changes take effect. Check the configuration file to verify changes. Test the server to make sure the problem is resolved.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

How to view your apache version How to view your apache version Apr 13, 2025 pm 01:15 PM

There are 3 ways to view the version on the Apache server: via the command line (apachectl -v or apache2ctl -v), check the server status page (http://<server IP or domain name>/server-status), or view the Apache configuration file (ServerVersion: Apache/<version number>).

How to connect to the database of apache How to connect to the database of apache Apr 13, 2025 pm 01:03 PM

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

See all articles