远程协助
当前位置:重庆拓磊计算机运营维护中心 > 文档中心 > 服务器 >
标题:CentOS7.6系统下使用yum配置lnmp环境的教程    日期:2019-05-14

一、安装版本详情

Server: MariaDB
 Server version: 5.5.60-MariaDB MariaDB Server
 [root@ln-125 ~]# cat /etc/redhat-release
 CentOS Linux release 7.6.1810 (Core)
 [root@ln-125 ~]# nginx -v
 nginx version: nginx/1.14.2
 [root@ln-125 ~]# php-fpm -v
 PHP 5.4.16 (fpm-fcgi) (built: Oct 30 2018 19:32:20)
 Copyright (c) 1997-2013 The PHP Group
 Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

二、安装Nginx服务

1.配置Nginx的yum源

[root@ln-125 ~]# cat >> /etc/yum.repos.d/nginx.repo <

2.安装并加入开机自启动

yum clean all ;
yum makecache ;
yum list nginx ;
#这时就可以看到nginx安装包了 ;
yum install nginx ;
systemctl enable nginx ;
systemctl start nginx 

如果有需要补充的安装模块可以根据当前Nginx版本到官方去下载源码包根据当前版本增量编译追加的模块即可

[root@ln-125 ~]# nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

三、安装相关php服务

 查询当前的php安装包

yum list php  php-fmp

这里为什么要安装php-fpm?

 因为php-fpm,是nginx和php的桥梁,php-fpm(快速进程管理),php-fpm默认进程为127.0.0.1:9000,一会php和php-fpm安装完成后,要配置nginx的配置文件,让其遇到客户端php请求是,转发给php-fpm(127.0.0.1:9000),php-fpm再让php解析完成,最后又给nginx.

 1.安装

yum install -y php php-fpm php-pear php-devel #httpd 

#httpd 可选,重庆电脑外包公司,参数更新中 php-pear为php的扩展工具,安装后可以用pecl install 命令安装php扩展

2.配置Nginx支持php文件 

默认Nginx是处理html和htm文件的需要配置Nginx支持php

vim /etc/nginx/conf.d/default.conf 
...
  location / {
    root  /usr/share/nginx/html; #设置根目录的绝对路径
    index index.html index.htm index.php; #匹配php文件
  }
  location ~ \.php$ {   #原来是注释掉的需要开启或复制
    root      /usr/share/nginx/html; #设置绝对路径
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #设置根目录匹配
    include    fastcgi_params;
  }
...

3.设置php的unix

sock 方式通信(可跳过这步)

 默认配置文件使用的是监听 9000 端口进行通信,针对小型单一、没有做负债均衡的服务器,可以使用 unix sock 方式通信增加php响应速度

touch /dev/shm/php-fpm-default.sock
[root@ln-125 ~]# cat /etc/php-fpm.d/www.conf |grep -Ev '^;|^$'
[www]
listen = /dev/shm/php-fpm-default.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = nobody
listen.group = nobody
listen.mode = 0666
user = nginx
group = nginx
。。。
systemctl restart php-fpm.service
systemctl enable php-fpm

4.优化配置(可选)

A) 修改php.ini的配置

vim /etc/php.ini 
cgi.fix_pathinfo=1 #将注释去掉,开启PHP的pathinfo伪静态功能。
max_execution_time = 0 #脚本运行的最长时间,默认30秒
max_input_time = 300#脚本可以消耗的时间,默认60秒
memory_limit = 256M#脚本运行最大消耗的内存,根据你的需求更改数值,默认128M
post_max_size = 100M #单提交的最大数据,此项不是限制上传单个文件的大小,而是针对整个表单的提交数据进行限制的。限制范围包括表单提交的所有内容.例如:发表贴子时,贴子标题,内容,附件等…默认8M
upload_max_filesize = 10M#上载文件的最大许可大小 ,默认2M
下一篇:CentOS7虚拟机安装并配置docker套件

联系我们
  • 客服热线:023-63522929(7 x 24h)
  • 在线客服:
  • 微信公众号 官方微博