设为首页 收藏本站
查看: 683|回复: 0

[经验分享] nginx+php5-fpm安装

[复制链接]

尚未签到

发表于 2018-11-14 10:15:23 | 显示全部楼层 |阅读模式
我的博客已迁移到xdoujiang.com请去那边和我交流  
一、基础环境
  
1、cat /etc/debian_version
  
7.8
  

  
2、uname -r
  
3.2.0-4-amd64
  

  
3、ip(eth0)
  
10.0.0.109
  

  
4、nginx版本
  
1.4.7
  

  
二、安装nginx
  
1、安装所需要的基础包
  
apt-get -y install libpcre3-dev libpcre3 libssl-dev zlib1g-dev make
  

  
2、建立nginx用户
  
1)groupadd nginx
  
2)useradd nginx -g nginx -s /bin/false
  

  
3、下载nginx
  
axel -n 10 http://nginx.org/download/nginx-1.4.7.tar.gz
  

  
4、解压
  
tar zxvf nginx-1.4.7.tar.gz && cd nginx-1.4.7
  

  
5、编译三部曲
  
1)./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module
  
2)make && make install
  

  
6、参数说明
  
--prefix=/opt/nginx    将安装路径指定在/opt/nginx
  
http_ssl_module         https协议模块
  
http_gzip_module        压缩的HTTP服务器的响应模块
  
http_rewrite_module     重写模块
  
--user=nginx            nginx用户
  
--group=nginx           nginx组
  

  
7、为了方便 弄个软链接
  
ln -s /opt/nginx/sbin/nginx /usr/local/sbin/nginx
  

  
8、修改nginx配置文件以支持php-fpm
  
1)先备份下
  
cp /opt/nginx/conf/nginx.conf /opt/nginx/conf/nginx.conf.bak
  
2)修改以下内容
  
2c2
  
< user nginx;
  
---
  
> #user  nobody;
  
36,39c36,38
  
<         listen       10.0.0.109:80;
  
<         server_name  10.0.0.109;
  
<         access_log /opt/nginx/logs/10.0.0.109.access.log;
  
<         error_log /opt/nginx/logs/10.0.0.109.error.log;
  
---
  
>         listen       80;
  
>         server_name  localhost;
  
>
  
66,72c65,71
  
<         location ~ \.php$ {
  
<             root           html;
  
<             fastcgi_pass   unix:/run/shm/php5-fpm.sock;
  
<             fastcgi_index  index.php;
  
<             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  
<             include        fastcgi_params;
  
<         }
  
---
  
>         #location ~ \.php$ {
  
>         #    root           html;
  
>         #    fastcgi_pass   127.0.0.1:9000;
  
>         #    fastcgi_index  index.php;
  
>         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
  
>         #    include        fastcgi_params;
  
>         #}
  

  
9、启动nginx服务
  
nginx
  

  
10、查看端口和进程
  
1)netstat -tupnl|grep nginx
  
tcp        0      0 10.0.0.109:80           0.0.0.0:*               LISTEN      13852/nginx: master
  
2)ps -ef |grep nginx
  
root     13852     1  0 22:51 ?        00:00:00 nginx: master process nginx
  
nginx    13853 13852  0 22:51 ?        00:00:00 nginx: worker process
  
nginx    13907 13906  0 22:52 ?        00:00:00 php-fpm: pool www
  
nginx    13908 13906  0 22:52 ?        00:00:00 php-fpm: pool www
  

  
PS:
  
1、停止nginx服务
  
nginx -s quit
  
2、重新加载配置
  
nginx -s reload
  

  
三、安装php5-fpm
  
1、安装php5-fpm及php
  
apt-get -y install php5-cli
  
apt-get -y install php5-fpm
  

  
2、修改php-fpm配置文件
  
1)先备份下
  
cp /etc/php5/fpm/pool.d/www.conf /etc/php5/fpm/pool.d/www.conf.bak
  
2)修改以下内容
  
diff /etc/php5/fpm/pool.d/www.conf /etc/php5/fpm/pool.d/www.conf.bak
  
22,23c22,23
  
< user = nginx
  
< group = nginx
  
---
  
> user = www-data
  
> group = www-data
  
33c33
  
< listen = /run/shm/php5-fpm.sock
  
---
  
> listen = /var/run/php5-fpm.sock
  
44,46c44,46
  
< listen.owner = nginx
  
< listen.group = nginx
  
< listen.mode = 0660
  
---
  
> listen.owner = www-data
  
> listen.group = www-data
  
> ;listen.mode = 0660
  

  
3、重启php-fpm服务
  
/etc/init.d/php5-fpm restart
  

  
4、查看进程
  
ps -ef |grep php
  
root     13906     1  0 22:52 ?        00:00:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
  
nginx    13907 13906  0 22:52 ?        00:00:00 php-fpm: pool www
  
nginx    13908 13906  0 22:52 ?        00:00:00 php-fpm: pool www
  

  
四、写个php文件测试
  
cat /opt/nginx/html/info.php
  
;
  

  
五、nginx相关模块及参考文章
  
1、nginx相关模块
  
ngx_http_core_module
  
ngx_http_access_module
  
ngx_http_addition_module
  
ngx_http_auth_basic_module
  
ngx_http_auth_request_module
  
ngx_http_autoindex_module
  
ngx_http_browser_module
  
ngx_http_charset_module
  
ngx_http_dav_module
  
ngx_http_empty_gif_module
  
ngx_http_f4f_module
  
ngx_http_fastcgi_module
  
ngx_http_flv_module
  
ngx_http_geo_module
  
ngx_http_geoip_module
  
ngx_http_gunzip_module
  
ngx_http_gzip_module
  
ngx_http_gzip_static_module
  
ngx_http_headers_module
  
ngx_http_hls_module
  
ngx_http_image_filter_module
  
ngx_http_index_module
  
ngx_http_limit_conn_module
  
ngx_http_limit_req_module
  
ngx_http_log_module
  
ngx_http_map_module
  
ngx_http_memcached_module
  
ngx_http_mp4_module
  
ngx_http_perl_module
  
ngx_http_proxy_module
  
ngx_http_random_index_module
  
ngx_http_realip_module
  
ngx_http_referer_module
  
ngx_http_rewrite_module
  
ngx_http_scgi_module
  
ngx_http_secure_link_module
  
ngx_http_session_log_module
  
ngx_http_spdy_module
  
ngx_http_split_clients_module
  
ngx_http_ssi_module
  
ngx_http_ssl_module
  
ngx_http_status_module
  
ngx_http_stub_status_module
  
ngx_http_sub_module
  
ngx_http_upstream_module
  
ngx_http_upstream_conf_module
  
ngx_http_userid_module
  
ngx_http_uwsgi_module
  
ngx_http_xslt_module
  

  
ngx_mail_core_module
  
ngx_mail_auth_http_module
  
ngx_mail_proxy_module
  
ngx_mail_ssl_module
  
ngx_mail_imap_module
  
ngx_mail_pop3_module
  
ngx_mail_smtp_module
  

  
ngx_stream_core_module
  
ngx_stream_access_module
  
ngx_stream_limit_conn_module
  
ngx_stream_proxy_module
  
ngx_stream_ssl_module
  
ngx_stream_upstream_module
  

  
2、参考文章
  
http://nginx.org/en/docs
  
http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_core_module.html
  

  
六、效果



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-634879-1-1.html 上篇帖子: nginx自签ssl证书 下篇帖子: Nginx实战配置详解
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表