安装nginx
1.首先下载nginx压缩包并解压
cd /opt
wget -c https://nginx.org/download/nginx-1.12.0.tar.gz #下载
tar xf nginx-1.12.0.tar.gz # 解压
2.安装依赖
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
3.进行配置和编译以及编译安装
cd /opt/nginx-1.12.0
./configure #配置
make && make install # 编译以及编译安装
4.启动nginx服务
find / -name nginx # 会显示在的位置
cd /usr/local/nginx/sbin # 这里是上面查找的位置
./nginx # 启动
ss -anp | grep nginx # 查看是否启动成功
5.创建软链接查看版本
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin #创建软链接
nginx -V # 查看nginx版本
6.配置systemctl管理
vim /usr/lib/systemd/system/nginx.service #创建文件
#文件内部信息
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
7.设置开机自启和systemctl等服务
systemctl daemon-reload #重载service配置文件
systemctl enable nginx.service # 设置开机自启动
# 因为之前启动过了,所以要关闭nginx
pkill -9 nginx # 关闭nginx进程
systemctl start nginx # 开启nginx
systemctl status nginx # 查看nginx状态
systemctl stop nginx # 关闭nginx
systemctl restart nginx # 重启nginx
安装PHP
1.首先安装PHP并解压
cd /opt
wget -c http://120.53.7.204:90/php-7.2.27.tar.gz .
tar -zxvf php-7.2.2.tar.gz
2.安装依赖
yum -y install gcc openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel
3.配置并编译以及编译安装
./configure --prefix=/usr/local/php --with-curl=/usr/local/curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
make && make install
4.配置PHP相关文件
cp /opt/php-7.2.27/php.ini-development /usr/local/bin/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
5.修改配置文件
vim /usr/local/php/lib/php.ini
cgi.fix_pathinfo=1 # 把这行注释打开 防止上传伪装文件
vim /usr/local/php/etc/php-fpm.conf
pid = /var/run/php-fpm.pid
6.启动php服务并创建软链接
cd /usr/local/php/sbin
./php-fpm
ss -anp | grep php
ln -s /usr/local/php/sbin/php-fpm /usr/local/bin
7.配置systemctl管理
vim /usr/lib/systemd/system/php-fpm.service
# 添加内容
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
8.设置开机自启和systemctl等服务
pkill -9 php-fpm
systemctl daemon-reload
systemctl enable php-fpm.service
systemctl start php-fpm
systemctl status php-fpm
systemctl stop php-fpm
systemctl restart php-fpm