[root@localhost ~]# yum -y install pcre-devel zlib-devel
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
[root@localhost ~]# cd /opt/
[root@localhost opt]# tar xf nginx-1.15.9.tar.gz
[root@localhost opt]# cd nginx-1.15.9/
[root@localhost nginx-1.15.9]# ./configure
--prefix=/usr/local/nginx
--user=nginx
--group=nginx
--with-http_stub_status_module
[root@localhost nginx-1.15.9]# make && make install
[root@localhost nginx-1.15.9]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@localhost nginx-1.15.9]# ls -l /usr/local/sbin/nginx
[root@localhost nginx-1.15.9]# nginx -t
[root@localhost nginx-1.15.9]# nginx
[root@localhost nginx-1.15.9]# netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 25166/nginx: master
[root@localhost nginx-1.15.9]# yum -y install lynx
[root@localhost nginx-1.15.9]# lynx 127.0.0.1
[root@localhost nginx-1.15.9]# yum install psmisc ##最小安装没有killall命令
[root@localhost nginx-1.15.9]# killall -s HUP nginx ##重新加载
[root@localhost nginx-1.15.9]# killall -s QUIT nginx ##停止服务
[root@localhost nginx-1.15.9]# vi /lib/systemd/system/nginx.service
[Unit]
Description=nginx #####描述
After=network.target ####描述服务类别
[Service]
Type=forking ####后台运行形式
PIDFile=/usr/local/nginx/logs/nginx.pid ####PID文件位置
ExecStart= /usr/local/nginx/sbin/nginx #####启动服务
ExecReload= /usr/bin/kill -s QUIT $MAINPID ####根据PID重新配置
ExecStop= /usr/bin/kill -s QUIT $MAINPID ####根据PID终止进程
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost nginx-1.15.9]# chmod 754 /lib/systemd/system/nginx.service
[root@localhost nginx-1.15.9]# systemctl enable nginx.service
[root@localhost nginx-1.15.9]# netstat -antp | grep nginx
[root@localhost nginx-1.15.9]# killall -s HUP nginx
[root@localhost nginx-1.15.9]# netstat -antp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 25496/nginx: master
[root@localhost nginx-1.15.9]# vi /usr/local/nginx/conf/nginx.conf
##全局配置
/usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#pid logs/nginx.pid;
##I/O时间配置
events {
use epoll;
worker_connections 4096;
}
##HTTP配置
http {
. . . . . . . . . . . .
access_log logs/access.log main;
sendfile on;
. . . . . . . .
keepalive_timeout 65;
. . . . . . . .
server {
listen 80;
server_name www.51xit.top;
charset utf-8;
. . . . . . . .
location / {
root html;
index index.html index.php;
}
. . . . . . . .
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
[root@localhost nginx-1.15.9]# nginx -t
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
见之前LAMP环境部署文档
[root@localhost ~]# yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
[root@localhost opt]# cd /opt ##提前把安装包传到此目录下
[root@localhost opt]# tar xf php-7.1.10.tar.bz2
[root@localhost opt]# cd php-7.1.10/
[root@localhost php-7.1.10/]# ./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
[root@localhost php-7.1.10/]# make && make install
[root@localhost php-7.1.10/]# cp php.ini-development /usr/local/php/lib/php.ini
[root@localhost php-7.1.10/]# vi /usr/local/php/lib/php.ini
mysqli.default_socket = /usr/local/mysql/mysql.sock
date.timezone = Asia/Shanghai
[root@localhost php-7.1.10]# /usr/local/php/bin/php -m ##验证安装的模块
[root@localhost php-7.1.10]# cd /usr/local/php/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# cd /usr/local/php/etc/php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# cd /usr/local/php/etc/
[root@localhost etc]# vi php-fpm.conf
pid = run/php-fpm.pid
;user = nginx
;group = nginx
[root@localhost etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
[root@localhost etc]# netstat -natp |grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 99975/php-fpm: mast
[root@localhost etc]# ln -s /usr/local/php/bin/* /usr/local/bin/
##创建软链接
[root@localhost etc]# ps aux | grep -c "php-fpm”
[root@localhost etc]# vi /usr/local/nginx/conf/nginx.conf
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;
}
[root@localhost etc]# vi /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
[root@localhost etc]# killall -s HUP nginx ##重启nginx
浏览器测试:http://20.0.0.21/index.php
[root@localhost ~]# mysql -u root -p
CREATE DATABASE bbs;
GRANT all ON bbs.* TO 'bbsadm'@'%' IDENTIFIED BY 'admin123';
GRANT all ON bbs.* TO 'bbsadm'@'localhost' IDENTIFIED BY 'admin123';
flush privileges; ##最后exit退出
[root@localhost ~]# vi /usr/local/nginx/html/index.php
<?php
$link=mysqli_connect('20.0.0.11','bbsadm','admin123');
if($link) echo "Success!!
";
else echo "Fail!!";
?>
[root@localhost ~]# killall -s HUP nginx ##重启