1、基于CentOS7.4源码编译安装得lnmp
系统环境CentOS 7.4
系统最小化安装,只安装了一些常用包(vim、lirzs、gcc*、wget、bash-completion)
nginx版本1.14.0
mysql版本5.7.20
php版本7.2.6
1.1 下载网络yum源
[root@centos7_4 ~]# wget http://mirrors.aliyun.com/repo/Centos-7.repo -P /etc/yum.repos.d/ #这里安装的是阿里的网络源,epel扩展源,也可以安装阿里的,但是阿里的epel源有些包不全,所以下面就直接用yum安装网络epel源
[root@centos7_4 ~]# yum -y install epel-release
[root@centos7_4 ~]# ls /etc/yum.repos.d/
back Centos-7.repo CentOS-Media.repo epel.repo epel-testing.repo
[root@centos7_4 ~]# yum clean all;yum makecache
2 源码编译安装nginx
2.1 安装依赖包:
[root@centos7_4 ~]# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre*
2.2 创建nginx运行用户
[root@centos7_4 ~]# useradd -M -s /sbin/nologin nginx
下载pcre包
[root@centos7_4 ~]# wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.zip
[root@centos7_4 ~]# unzip pcre-8.42.zip -d /usr/local/src/
2.3 下载nginx源码包并解压
[root@centos7_4 ~]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
[root@centos7_4 ~]# tar zxf nginx-1.14.0.tar.gz -C /usr/local/src/
[root@centos7_4 ~]# cd /usr/local/src/nginx-1.14.0/
[root@centos7_4 nginx-1.14.0]#./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --user=nginx --group=nginx --with-pcre=/usr/local/src/pcre-8.42 #这个是可选项,如果yum安装了依赖包这里也可以不用
2.4 编译并安装
[root@centos7_4 nginx-1.14.0]# echo $?
0
[root@centos7_4 nginx-1.14.0]# make
[root@centos7_4 nginx-1.14.0]# echo $?
0
[root@centos7_4 nginx-1.14.0]# make install
[root@centos7_4 nginx-1.14.0]# echo $?
0
2.5 修改配置文件
[root@centos7_4 nginx-1.14.0]# vim /usr/local/nginx/conf/nginx.conf
user nginx nginx; #修改用户和组
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; #修改路径
include fastcgi_params;
}
2.6 添加环境变量,优化nginx服务
[root@centos7_4 ~]# /usr/local/nginx/sbin/nginx -t #检查nginx语法是否正确
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@centos7_4 ~]# /usr/local/nginx/sbin/nginx #安装好的启动路径
[root@centos7_4 ~]# vim /etc/profile #添加环境变量
export PATH=$PATH:/usr/local/nginx/sbin