其实没多复杂
① 将nginx和php都装好了
② 然后配置nginx,将php请求分发给php-fpm处理
linux下的配置文件一般在/usr/local/nginx/conf/nginx.conf
找到下面字样,并取消注释,且注意这个$document_root这个地方(原本应为$script***的,改成$document_root)
location ~ \.php$ {
root html;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
③启动nginx和php-fpm,然后写个phpinfo脚本测试下成功与否就可以了
nginx配置:
server{
#...其他location略
location?~*?\.php$?{
应用环境
⑤③⑧也就是说需要两个版本的PHP同时存在,供nginx根据需要调用不同版本.
思路
Nginx是通过PHP-FastCGI与PHP交互的.而PHP-FastCGI运行后会通过文件、或本地端口两种方式进行监听,在Nginx中配置相应的FastCGI监听端口或文件即实现Nginx请求对PHP的解释.
既然PHP-FastCGI是监听端口和文件的,那就可以让不同版本的PHP-FastCGI同时运行,监听不同的端口或文件,Nginx中根据需求配置调用不同的PHP-FastCGI端口或文件,即可实现不同版本PHP共存了.
配置记录
mkdir
cd
wget
-c
tar
zxvf
gzip
-cd
|
patch
-d
-p1
export
./buildconf
--force
./configure
--with-mysql=/usr/local/mysql
--with-mysqli=/usr/local/mysql/bin/mysql_config
--enable-fastcgi
--enable-fpm
make
ZEND_EXTRA_LIBS='-liconv'
install
value
或者监听文件:
name="listen_address"/path/to/unix/socket/value
其他参数根据服务器环境和需求自行定制.
⑤启动php-fpm,以后可以通过php-fpm进行管理:
start
cp
-f
(php
-⑤③x-source-dir)/sapi/fpm/init.d.php-fpm
/etc/init.d/php-fpm
chmod
php-fpm支持的操作:
start,启动PHP的FastCGI进程.
stop,强制终止PHP的FastCGI进程.
quit,平滑终止PHP的FastCGI进程.
restart,
重启PHP的FastCGI进程.
reload,
重新加载PHP的php.ini.
logrotate,
重新启用log文件.
vi
reload
location
~
{
fastcgi_pass
fastcgi_index
index.php;
include
fcgi.conf;
⑧记录一下自己编译php⑤⑤10使用的配置
--prefix=/usr/local/php-⑤⑤10
--with-config-file-path=/usr/local/php-⑤⑤10/etc
--with-mysql=mysqlnd
--with-mysqli=mysqlnd
--with-curl=/usr/bin
--enable-ftp
--enable-sockets
--with-gd
--with-jpeg-dir=/usr/local
--with-png-dir=/usr/local
--with-freetype-dir=/usr/local
--enable-gd-native-ttf
--with-iconv-dir=/usr/local
--enable-mbstring
--enable-calendar
--with-gettext
--with-libxml-dir=/usr/local
--with-zlib
--with-pdo-mysql=mysqlnd
--enable-dom
--enable-xml
--with-mcrypt=/usr/bin
--enable-zip
--enable-soap
--with-openssl
--enable-pcntl
--with-xmlrpc
--enable-opcache
①.、首先需要准备的应用程序包.
(还会用到)RunHiddenConsole:RunHiddenConsole.zip
②.、安装与配置.
①.)php的安装与配置.
extension_dir = "./ext"
更改为
往下看,再找到
;extension=php_mysql.dll
;extension=php_mysqli.dll
到这里,php已经可以支持mysql了.
此时此刻呢我们来配置php,让php能够与nginx结合.找到
;cgi.fix_pathinfo=1
我们去掉这里的封号.
cgi.fix_pathinfo=1
这一步非常重要,这里是php的CGI的设置.
②.)nginx的安装与配置.
location / {
root html;#这里是站点的根目录
index index.html index.htm;
将root html;改为root D:/wnmp/www;
再往下,找到
复制代码
#
#location ~ \.php$ {
# root html;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
先将前面的"#"去掉,同样将root html;改为root D:/wnmp/www;.再把标记为红色的/scripts改为"$document_root",这里的"$document_root"就是指前面"root"所指的站点路径,这是改完后的:
root D:/wnmp/www;
保存配置文件,就可以了.
nginx+php的环境就初步配置好了,来跑跑看.我们可以输入命令
来启动php,并手动启动nginx,当然也可以利用脚本来实现.
@echo off
REM Windows 下无效
REM 每个进程处理的最大请求数,或设置为 Windows 环境变量
set PHP_FCGI_MAX_REQUESTS=1000
echo Starting PHP FastCGI...
echo Starting nginx...
RunHiddenConsole D:/wnmp/nginx/nginx.exe -p D:/wnmp/nginx
再另外创建一个名为stop_nginx.bat的脚本用来关闭nginx
echo Stopping nginx...
taskkill /F /IM nginx.exe nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe nul
exit
做好后,是这样的
这样,我们的服务脚本也都创建完毕了.双击start_nginx.bat看看进程管理器是不是有两个nginx.exe的进程和一个php-cgi.exe的进程呢?
这样nginx服务就启动了,而且php也以fastCGI的方式运行了.
php
phpinfo();
保存后,打开浏览器输入"",如果看到
就说明,nginx+php的环境已经配置好了,呵呵~
以上就是土嘎嘎小编为大家整理的php并于nginx整合相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!