CentOS7.6系统下使用yum配置lnmp环境的方法

这篇文章主要介绍了CentOS7.6系统下使用yum配置lnmp环境的方法,需要的朋友可以参考下

一、安装版本详情

 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

B) 修改php-fpm的配置

 vim /etc/php-fpm.d/www.conf 找到以下两行,解除注释 listen.owner = nobody listen.group = nobody 找下以下两行,将各自的apache改为nginx user = apache -> user = nginx group = apache -> group = nginx

四、安装mariadb数据库

 yum install -y mariadb mariadb-server #开机自启 [root@ln-125 ~]# systemctl start mariadb.service [root@ln-125 ~]# systemctl enable mariadb.service #初始化数据库配置 mysql_secure_installation #配置默认设置(root密码登录方式等) #设置默认字符集 编辑 vim /etc/my.cnf [root@ln-125 ~]# grep -Ev '^#|^$' /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 character-set-server = utf8 ##设置默认编码 [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid !includedir /etc/my.cnf.d systemctl restart mariadb.service

五、测试

 cat >> /usr/share/nginx/html/index.php << EOF 

EOF

http://{域名}
http://{域名}/index.php

看到测试页,那么恭喜你搭建完成。

总结

以上就是CentOS7.6系统下使用yum配置lnmp环境的方法的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 服务器