nginx配置文件php|nginx配置支持php

⑴ 如何正确配置Nginx+PHP

其实没多复杂1. 将nginx和php都装好了2. 然后配置nginx,将php请求分发给php-fpm处理linux下的配置文件一般在/usr/local/nginx/conf/nginx.conf找到下面字样,并取消注释,且注意这个$document_root这个地方(原本应为$script***的,改成$document_root)location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }3.启动nginx和php-fpm,然后写个phpinfo脚本测试下成功与否就可以了

⑵ 云服务器如何配置nginx支持php

[[email protected] ~]# wget http://am1.php.net/get/php-7.1.2.tar.gz/from/this/mirror[[email protected] ~]# tar xzvf php-7.1.2.tar.gz[[email protected] ~]# cd php-7.1.2/[[email protected] ~]# ./configure –prefix=/usr/local/php –enable-fpm[[email protected] php-7.1.2]# make&&make install查看是否成功编译安装PHP[[email protected] php-7.1.2]# php -vPHP 7.1.2 (fpm-fcgi) (built: Apr 14 2017 20:21:53)Copyright (c) 1997-2017 The PHP GroupZend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies 编译安装完成后PHP不具备配置文件php.ini,此时只需复制php.ini-proction到 /usr/local/lib/php.ini即可,php.ini文件一般在/usr/local/lib/和/etc目录下 [[email protected] php-7.1.2]# cp php.ini-proction /usr/local/lib/php.ini[[email protected] php]# /usr/local/php/sbin/php-fpm[14-Apr-2017 20:59:49] ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)[14-Apr-2017 20:59:49] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'[14-Apr-2017 20:59:49] ERROR: FPM initialization failed启动php-fpm发现缺乏配置文件/usr/local/php/etc/php-fpm.conf此时只需复制php-fpm的配置文件在安装php时提供的配置文件的模版/usr/local/php/etc/php-fpm.conf.default到相应/usr/local/php/etc/php-fpm.conf即可 [[email protected] etc]# /usr/local/php/sbin/php-fpm [14-Apr-2017 21:14:32] WARNING: Nothing matches the include pattern '/usr/local/php/etc/php-fpm.d/﹡.conf' from /usr/local/php/etc/php-fpm.conf at line 125.[14-Apr-2017 21:14:32] ERROR: No pool defined. at least one pool section must be specified in config file[14-Apr-2017 21:14:32] ERROR: failed to post process the configuration[14-Apr-2017 21:14:32] ERROR: FPM initialization failed [[email protected] etc]# cp php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [[email protected] etc]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf[[email protected] etc]# /etc/init.d/php-fpm [14-Apr-2017 21:23:02] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)[14-Apr-2017 21:23:02] ERROR: FPM initialization failed[[email protected] etc]# netstat -nldp|grep 9000tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3721/php-fpm: maste [[email protected] php-7.1.2]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm[[email protected] php-7.1.2]# chmod a+x /etc/init.d/php-fpm [[email protected] php-7.1.2]# ll /etc/init.d/php-fpm -rwxr-xr-x 1 root root 2401 4月 14 21:26 /etc/init.d/php-fpm[[email protected] php-7.1.2]# /etc/init.d/php-fpm startStarting php-fpm [14-Apr-2017 21:28:09] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)[14-Apr-2017 21:28:09] ERROR: FPM initialization failed failed[[email protected] php-7.1.2]# netstat -nldp |grep 9000tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3721/php-fpm: maste [[email protected] php-7.1.2]# kill 3721[[email protected] php-7.1.2]# netstat -nldp |grep 9000[[email protected] php-7.1.2]# /etc/init.d/php-fpm startStarting php-fpm done[[email protected] php-7.1.2]# service php-fpm statusphp-fpm (pid 3927) is running…[[email protected] php-7.1.2]# chkconfig –add php-fpm[[email protected] php-7.1.2]# chkconfig php-fpm –level 345 on配置nginx支持PHP修改nginx的配置文件,支持php文件的解析,找到location的添加位置,在后面添加下面这个locationlocation ~ .php$ { root /usr/share/nginx/html; #指定php的根目录 fastcgi_pass 127.0.0.1:9000;#php-fpm的默认端口是9000 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }

⑶ nginx配置支持php

nginx本身不支持php解析,需要配合php-fpm来配置。

location~.php${root/var/www;#指定php的根目录fastcgi_pass127.0.0.1:9000;#php-fpm的默认端口是9000fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;includefastcgi_params;}

centos下安装php-fpm (php及其它组件已经安装过的情况)

yuminstallphp-fpm

启动php-fpm 并设置开机启动 (centos 7)

systemctlstartphp-fpmsystemctlenablephp-fpm

⑷ 如何正确配置Nginx+PHP

1、Nginx安装安装编译软件库[[email protected] ~]# yum -y install gcc gcc-c++ autoconf automake openssl openssl-devel pcre-devel zlib-devel下载nginx 1.6.2源码包[[email protected] ~]# wget http://nginx.org/download/nginx-1.6.2.tar.gz解压nginx[[email protected] ~]# tar zxvf nginx-1.6.2.tar.gz进入解压文件夹[[email protected] ~]# cd nginx-1.6.2编译设置模块[[email protected] nginx-1.6.2]# ./configure –with-http_stub_status_mocule –prefix=/opt/nginx安装[[email protected] nginx-1.6.2]# make && make installnginx编译安装性能优化1、在nginx 源码文件找到auto/cc/gcc文件找到如下几行#debug[[email protected] ~]# CFLASS=”$CFLAGS -g”2、特定CPU优化CPU类型编译–with-cc-opt=”-O3″–with-cpu-opt=CPU类型查看CPU类型[[email protected] ~]# cat /proc/cpuinfo | grep “model name”nginx重新启动[[email protected] ~]# /opt/nginx/sbin/nginx -s reloadnginx启动[[email protected] ~]# /opt/nginx/sbin/nginxnginx检测配置[[email protected] ~]# /opt/nginx/sbin/nginx -t2、PHP的安装和配置安装php依赖软件库[[email protected] ~]# yum install -y gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel mysql mysql-devel下载php5.6源码包[[email protected] ~]# wget http://am1.php.net/distributions/php-5.6.3.tar.gz解压[[email protected] ~]# tar -zxvf php-5.6.3.tar.gz[[email protected] ~]# cd php-5.6.3编译设置模块[[email protected] php-5.6.3]# ./configure –prefix=/usr/local/php –with-mysql=mysqlnd–with-mysqli=mysqlnd –enable-fpm –with-pear –with-curl –with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir –with-iconv –with-mhash –with-zlib –enable-mbstring –disable-debugmake && make install复制php配置文件[[email protected] php-5.6.3]# cp php.ini-proction /opt/php/lib/php.ini启动php-fpm[[email protected] php-5.6.3]# /opt/php/sbin/php-fpm检测配置是否正确[[email protected] php-5.6.3]# /opt/php/sbin/php-fpm -t在centos上成功编译安装nginx 1.6、php 5.6并成功启动nginx和php-fpm后,访问php提示”File not found.”,同时在错误日志中看到:2013/10/22 20:05:49 [error] 12691#0: *6 FastCGI sent in stderr: “Primary script unknown” while reading response header from upstream, client: 192.168.168.1, server: localhost, request: “GET / HTTP/1.1″, upstream: “fastcgi://127.0.0.1:9000″, host: “192.168.168.133”:在Nginx配置文件中找到定义调用脚本文件的地方,如:fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;修改成如下方式($document_root):fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;nginx gzip设置gzip on;gzip_min_length 1k;gzip_buffers 4 16k;gzip_http_version 1.1;gzip_comp_level 2;gzip_types text/plain application/x-javascript text/css applocation/xml;gzip_vary on;来源:CentOS编译安装Nginx1.6、PHP5.6 – http://www.leixuesong.cn/84

⑸ nginx和php的两种通信方式

Nginx与PHP的两种通信方式-unix socket和tcp socket 1、两者Nginx配置 unix socket 需要在nginx配置文件中填写php-fpm运行的pid文件地址。 location ~ \.php$ {     include fastcgi_params;     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;;     fastcgi_pass unix:/var/run/php5-fpm.sock;     fastcgi_index index.php; }tcp socket 需要在nginx配置文件中填写php-fpm运行的ip地址和端口号。 location ~ \.php$ {     include fastcgi_params;     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;;     fastcgi_pass 127.0.0.1:9000;     fastcgi_index index.php; }2、两者比较从上面的图片可以看,unix socket减少了不必要的tcp开销,而tcp需要经过loopback,还要申请临时端口和tcp相关资源。但是,unix socket高并发时候不稳定,连接数爆发时,会产生大量的长时缓存,在没有面向连接协议的支撑下,大数据包可能会直接出错不返回异常。tcp这样的面向连接的协议,多少可以保证通信的正确性和完整性。 3、选择建议:如果是在同一台服务器上运行的nginx和php-fpm,并发量不超过1000,选择unix socket,因为是本地,可以避免一些检查操作(路由等),因此更快,更轻。 如果面临高并发业务,我会选择使用更可靠的tcp socket,以负载均衡、内核优化等运维手段维持效率。

⑹ 如何在Nginx下配置PHP程序环境

Linux 系统 php 在编译的时候 可以选择开启php-fpm 这个模块就是支持Nginx 的。也可以加入支持apache的模块 apx2 ,php编译成功之后,Nginx建立虚拟主机的配置文件 只需要加入php的解析模块就可以了。

⑺ 如何正确配置Nginx+PHP

[email protected] ~]# yum -y install gcc gcc-c++ autoconf automake openssl openssl-devel pcre-devel zlib-devel下载nginx 1.6.2源码包[[email protected] ~]# wget http://nginx.org/download/nginx-1.6.2.tar.gz解压nginx[[email protected] ~]# tar zxvf nginx-1.6.2.tar.gz进入解压文件夹[[email protected] ~]# cd nginx-1.6.2编译设置模块[[email protected] nginx-1.6.2]# ./configure –with-http_stub_status_mocule –prefix=/opt/nginx安装[[email protected] nginx-1.6.2]# make && make installnginx编译安装性能优化1、在nginx 源码文件找到auto/cc/gcc文件找到如下几行#debug[[email protected] ~]# CFLASS=”$CFLAGS -g”2、特定CPU优化CPU类型编译–with-cc-opt=”-O3″–with-cpu-opt=CPU类型查看CPU类型。太多了写不完,如果想知道更多知识,可以去后盾人看看相关的教材。希望对你有用。

⑻ mac配置php-fpm,nginx运行多版本php

1、brew 安装 php5.6 php5.7 nginx 2、配置php-conf 3、配置虚拟主机 安装好brew 用brew 命令安装,如果速度太慢或访问不了,自行goole brew 换源 brew search php  查看可用的php版本 brew install [email protected]  安装php5.6 brew install [email protected] 安装php5.6 brew install nginx       安装nginx 1、修改php5.6 php-fpm的端口为9056     cd usr/local/etc/php/5.6 # 到php5.6的目录下     vi    php-fpm.conf # 修改文件         listen = 127.0.0.1:9056  # 修改此端口         daemonize = yes # 修改为允许后台启动php-fpm 2、修改php5.6 php-fpm的端口为9070     cd /usr/local/etc/php/7.1/php-fpm.d # 到php7.1的目录下     vi www.conf # 修改端口         listen = 127.0.0.1:9056  # 修改此端口         vi    php-fpm.conf  # 修改文件          daemonize = yes # 修改为允许后台启动php-fpm 3、启动php-fpm     cd /usr/local/sbin # 到此目录,建立两个软链接指向不同版本的php切换到root用户 ./php-fpm56  ./php-fpm71 启动后可看到php-fpm的进程,则成功 ps-ef | grep php-fpm cd /usr/local/etc/nginx/  # 到nginx的目录下 复制默认的配置文件到server下(此目录用来存虚拟主机文件) 这里我在server创建了这两个vi local.phpinfo56.com.conf # 修改本地域名和nginx代理到php-fpm端口,按照这种方法修改另一个 nginx # 启动nginx nginx -s reload # 修改配置文件,重新加载nginx vi /etc /hosts  # 修改host 加上映射关系 cd  /usr /local/var/www # 在此目录下建立一个index.php echo "<?php phpinfo();" > index.php 在浏览器访问可看到

⑼ 如何正确配置Nginx + PHP

先上配置的过程,下面是解释。

⑽ 如何正确配置 Nginx 和 PHP

直接贴上代码逐行进行讲解,此处贴出一个能正常启动php脚本的最简nginx vhost配置:[plain] view plain server { listen 8011; server_name test.cn; location ~ \.php?.*$ { root /share/test; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 1、第一个大括号 server{ }:不必多说,代表一个独立的server,2、listen 8011:代表该server监听8011端口 3、location ~ \.php?.*${ }:代表一个能匹配对应uri的location,用于匹配一类uri,并对所匹配的uri请求做自定义的逻辑、配置。这里的location,匹配了所有带.php的uri请求,例如:http://192.168.244.128:8011/test.php/asdasd http://192.168.244.128:8011/index.php等4、root /share/test:请求资源根目录,告诉匹配到该location下的uri到/share/teset文件夹下去寻找同名资源。5、fastcgi_pass 127.0.0.1:9000:这行开始是本文的重点:这行代码的意思是,将进入到该location内的uri请求看做是cgi程序,并将请求发送到9000端口,交由php-fpm处理。6、fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; :这行配置意思是:动态添加了一行fastcgi配置,配置内容为SCRIPT_FILENAME,告知管理进程,cgi脚本名称。由于我的nginx中只有fastcgi_params文件,没有fastcgi.conf文件,所以要使php-fpm知道SCRIPT_FILENAME的具体值,就必须要动态的添加这行配置。7、include fastcgi_params; 引入fastcgi配置文件以上就是最简洁版的nginx启动php脚本的最简配置,当重启nginx之后,在/share/test目录下创建一个xx.php文件,输入<?php echo "hello world"; ?>保存,然后在浏览器中访问localhost:8011/xx.php 就可以在网页上显示hello world了。


赞 (0)