CentOS 7下编译安装Nginx+MySQL+PHP

CentOS 7 64位
IP地址:172.16.0.20
Nginx:1.12.0
MySQL:5.7.18
PHP:7.1.4
yum源:aliyun源

如果你的系统是新安装的RedHat 7或 Centos 7 ,可以使用我的一键优化脚本优化系统,有利于系统的使用和下面的安装。点击我查看 首先下载好我们的需要的包

创建一个目录存放下载的软件

[root@localhost ~]# mkdir /software [root@localhost ~]# cd /software/

软件下载地址
这是我的网盘链接
或者去它们各自的官网下载最新版,下载命令参考

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.18.tar.gz wget https://sourceforge.net/projects/pcre/files/pcre/8.40/pcre-8.40.tar.gz wget wget

这是需要的包

[root@localhost software]# ll 总用量 757804 -rw-r--r-- 1 root root 61612105 4月 18 14:55 mysql-boost-5.7.18.tar.gz -rw-r--r--. 1 root root 980831 4月 14 17:08 nginx-1.12.0.tar.gz -rw-r--r-- 1 root root 20319716 4月 18 15:41 php-7.1.4.tar.gz

关闭系统限制
关闭系统防火墙

[root@localhost software]# systemctl stop firewalld.service [root@localhost software]# systemctl disable firewalld.service

关闭SElinux

[root@localhost software]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config [root@localhost software]# setenforce 0 开始安装nginx

创建www账户 用来启动nginx

[root@localhost software]# useradd www -s /sbin/nologin

安装依赖的包

[root@localhost software]# yum -y install pcre pcre-devel zlib zlib-devel gcc-c++ gcc openssl*

解压Nginx源码包

root@localhost software]# tar zxvf nginx-1.12.0.tar.gz

进入解压后的目录,对Nginx进行配置

[root@localhost software]# cd nginx-1.12.0/ [root@localhost nginx-1.12.0]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre

编译和安装

[root@localhost nginx-1.12.0]# make && make install

启动Nginx

[root@localhost nginx-1.12.0]# /usr/local/nginx/sbin/nginx

浏览器访问测试是否ok


 

关闭Nginx进程

[root@localhost nginx-1.12.0]# killall nginx [root@localhost nginx-1.12.0]# ps -ef|grep nginx

nginx命令做软连接方便使用

[root@localhost nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /sbin/nginx

编写nginx启动脚本

cat >> /usr/lib/systemd/system/nginx.service << EOF [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx ExecReload=//usr/sbin/nginx -s reload ExecStop=/usr/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target EOF

修改完systemctl服务,需要重新加载下daemon

[root@localhost nginx-1.12.0]# systemctl daemon-reload

用systemctl启动Nginx服务,并查看状态

[root@localhost nginx-1.12.0]# systemctl start nginx [root@localhost nginx-1.12.0]# systemctl status nginx ● nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: active (running) since 二 2017-04-18 14:06:58 CST; 8s ago Docs: Process: 11816 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 11813 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Main PID: 11818 (nginx) CGroup: /system.slice/nginx.service ├─11818 nginx: master process /usr/sbin/nginx └─11820 nginx: worker process 4月 18 14:06:58 localhost.localdomain systemd[1]: Starting nginx - high performance web server... 4月 18 14:06:58 localhost.localdomain nginx[11813]: nginx: the configuration file /usr/local/nginx/conf/nginx...s ok 4月 18 14:06:58 localhost.localdomain nginx[11813]: nginx: configuration file /usr/local/nginx/conf/nginx.con...sful 4月 18 14:06:58 localhost.localdomain systemd[1]: Failed to read PID from file /usr/local/nginx/logs/nginx.pi...ment 4月 18 14:06:58 localhost.localdomain systemd[1]: Started nginx - high performance web server.

设置nginx开机启动

[root@localhost nginx-1.12.0]# systemctl enable nginx

nginx安装完成,下面安装mysql

安装MySQL

安装依赖包

[root@localhost nginx-1.12.0]# cd /software/ [root@localhost software]# yum -y install ncurses ncurses-devel bison cmake gcc gcc-c++

创建用户和组

[root@localhost software]# groupadd mysql [root@localhost software]# useradd -s /sbin/nologin -g mysql mysql -M [root@localhost software]# id mysql

解压mysql源码包

[root@localhost software]# tar zxvf mysql-boost-5.7.18.tar.gz

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/191db1c59a1e46fec03178ee061889db.html