Centos 6.8编译安装LNMP环境(Nginx+MySQL+PHP)教程

2019-10-12 14:55:39于丽

前言

对于新手的一点建议:

最好熟悉一下linux 的基本命令,vim的常用命令 千万不要无脑复制,先看一下命令,特别是路径要注意 学会排查错误

本篇安装的软件版本为:

Linux:Centos6.8 Nginx:1.10.3 MySQL:5.7.17 PHP:7.0.16

最近研究了Linux系统下的PHP环境搭建,个人感觉最好最好不要用yum默认的程序包安装,因为版本都比较低,下载最新的稳定版自行安装比较好。现在网上教程很多,之所以还记这篇,原因有一点,当你重复网上的教程自行安装时,90%还是会出现各种各样的问题,因为你可能linux的系统版本不同,你想装的软件版本不同,安装的方法不同,你下错了安装包的版本,还有其它乱七八糟的。举个例,比如你看着5.6的mysql安装教程,装5.7的,你感觉没问题,但是事实就是,5.7的不一样了!而且网上还没有新的这方面内容,不好找,这就需要你去摸索了,亲身经历啊。这里面,Niginx感觉最好配,MySQL最坑。

一 准备工作

1. 关闭SELINUX

修改配置文件,重启服务后永久生效。

# sed -i ‘s/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

命令行设置立即生效。

# setenforce 0

2. 如果是阿里云ECS用户,安全组设置中开启80端口方便调试。 

二 安装Nginx

1. 下载源码包

上Nginx官网,复制最新稳定版的下载地址过来,然后用wget下载(接下来需要下载安装包的都可以用wget):

# cd /usr/local/src
# wget http://nginx.org/download/nginx-1.10.3.tar.gz

下载完成的状态基本都是以下这样的:

2. 进行解压编译

# tar xvf nginx-1.10.3.tar.gz
# yum groupinstall “Development tools”
# yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel

执行完成。

进入解压后的nginx-1.10.3文件夹:

cd /usr/local/src/nginx-1.10.3

执行以下语句:

./configure 
--prefix=/usr/local/nginx 
--sbin-path=/usr/sbin/nginx 
--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/tmp/nginx/client 
--http-proxy-temp-path=/var/tmp/nginx/proxy 
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi 
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi 
--http-scgi-temp-path=/var/tmp/nginx/scgi 
--user=nginx 
--group=nginx 
--with-pcre 
--with-http_v2_module 
--with-http_ssl_module 
--with-http_realip_module 
--with-http_addition_module 
--with-http_sub_module 
--with-http_dav_module 
--with-http_flv_module 
--with-http_mp4_module 
--with-http_gunzip_module 
--with-http_gzip_static_module 
--with-http_random_index_module 
--with-http_secure_link_module 
--with-http_stub_status_module 
--with-http_auth_request_module 
--with-mail 
--with-mail_ssl_module 
--with-file-aio 
--with-ipv6 
--with-http_v2_module 
--with-threads 
--with-stream 
--with-stream_ssl_module