博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用yum配置lnmp环境(CentOS7.6)
阅读量:4629 次
发布时间:2019-06-09

本文共 4849 字,大约阅读时间需要 16 分钟。

一、安装版本详情

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 -Vnginx version: nginx/1.14.2built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) built with OpenSSL 1.0.2k-fips  26 Jan 2017TLS SNI support enabledconfigure 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.socklisten.backlog = -1listen.allowed_clients = 127.0.0.1listen.owner = nobodylisten.group = nobodylisten.mode = 0666user = nginxgroup = nginx。。。systemctl restart php-fpm.servicesystemctl 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#脚本运行最大消耗的内存,根据你的需求更改数值,默认128Mpost_max_size = 100M  #单提交的最大数据,此项不是限制上传单个文件的大小,而是针对整个表单的提交数据进行限制的。限制范围包括表单提交的所有内容.例如:发表贴子时,贴子标题,内容,附件等…默认8Mupload_max_filesize = 10M#上载文件的最大许可大小 ,默认2MB) 修改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/mysqlsocket=/var/lib/mysql/mysql.socksymbolic-links=0character-set-server = utf8  ##设置默认编码[mysqld_safe]log-error=/var/log/mariadb/mariadb.logpid-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
看到测试页,那么恭喜你搭建完成。

END

转载于:https://www.cnblogs.com/haozheyu/p/10090176.html

你可能感兴趣的文章
Centos6.5基于GPT格式磁盘分区
查看>>
node.js是做什么的?
查看>>
LeetCode之461. Hamming Distance
查看>>
HSSFWorkbook 与 XSSFWorkbook
查看>>
希尔排序——算法系列
查看>>
javascript ES6 新特性之 扩展运算符 三个点 ...
查看>>
数论(Lucas定理) HDOJ 4349 Xiao Ming's Hope
查看>>
Jetson tk1 安装 CUDA,ROS,OpenCV和kinect2以及刷机以及ssh远程控制
查看>>
linux 下byte,char,unsigned char的区别
查看>>
团队任务四(无图)
查看>>
mysql 免安装
查看>>
Introduction to Linux Kernel
查看>>
IE8下面的line-height的bug
查看>>
wealthy benefit from class action lawsuits
查看>>
【转】apache常用配置
查看>>
WIn7下Ubuntu 14.04 安装
查看>>
学习日记
查看>>
json操作2
查看>>
BOS项目 第2天(BaseDao、BaseAction、用户登录、自定义strust登录拦截器)
查看>>
zoj 3554 A Miser Boss
查看>>