yum安装Nginx
http://nginx.org/en/linux_packages.html#RHEL-CentOS
[root@web1 ~]# cat > /etc/yum.repos.d/nginx.repo <<EOF
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@web1 ~]# yum clean all
[root@web1 ~]# yum makecache
[root@web1 ~]# yum install nginx -y
Nginx源码编译安装
#下载
[root@web02 ~]# cd /opt/
[root@web02 opt]# wget http://nginx.org/download/nginx-1.19.10.tar.gz
#解压
[root@web02 opt]# tar xf nginx-1.19.10.tar.gz
#进去
[root@web02 opt]# cd nginx-1.19.10/
[root@web02 nginx-1.19.10]# ll
total 780
drwxr-xr-x 6 1001 1001 326 Apr 26 09:54 auto
-rw-r--r-- 1 1001 1001 310993 Apr 13 23:14 CHANGES
-rw-r--r-- 1 1001 1001 474560 Apr 13 23:14 CHANGES.ru
drwxr-xr-x 2 1001 1001 168 Apr 26 09:54 conf
-rwxr-xr-x 1 1001 1001 2590 Apr 13 23:13 configure
drwxr-xr-x 4 1001 1001 72 Apr 26 09:54 contrib
drwxr-xr-x 2 1001 1001 40 Apr 26 09:54 html
-rw-r--r-- 1 1001 1001 1397 Apr 13 23:13 LICENSE
drwxr-xr-x 2 1001 1001 21 Apr 26 09:54 man
-rw-r--r-- 1 1001 1001 49 Apr 13 23:13 README
drwxr-xr-x 9 1001 1001 91 Apr 26 09:54 src
#检查
[root@web02 nginx-1.19.10]# ./configure
#安装依赖
./configure: error: the HTTP rewrite module requires the PCRE library.
[root@web02 nginx-1.19.10]# yum install pcre pcre-devel -y
[root@web02 nginx-1.19.10]# ./configure
#出现如下界面成功
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
#自定义安装
./configure --user=www --group=www --prefix=/usr/local/nginx-1.19.10 --with-stream --with-mail --with-http_perl_module --without-http_gzip_module --with-http_ssl_module
#安装
[root@web02 nginx-1.19.10]# make -j && make install
#做软链接
[root@web02 local]# ln -s nginx-1.19.10/ nginx
#添加环境变量
[root@web02 local]# vim /etc/profile.d/HJBL.sh
export NGINX_HOME=/usr/local/nginx
PATH=$PATH:$NGINX_HOME/sbin
export PATH
[root@web02 local]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/nginx/sbin:/usr/local/nginx/sbin
#测试&检查
[root@web02 local]# nginx -t
nginx: the configuration file /usr/local/nginx-1.19.10/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.19.10/conf/nginx.conf test is successful
[root@web02 local]# nginx
[root@web02 local]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:928 0.0.0.0:* LISTEN 1387/sshd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1051/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 14913/nginx: master
php源码编译安装
下载5.6.4版本(和python一样,3.6永远的神)
# 环境准备
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libzip-devel pcre-devel
#下载php源码包到opt目录,然后解压
[root@web03 ~]# cd /opt
[root@web03 opt]# wget https://www.php.net/distributions/php-5.6.40.tar.gz
[root@web03 opt]# tar -xf php-5.6.40.tar.gz
[root@web03 opt]# cd php-5.6.40/ls
#检查系统配置,并指定安装模块与用户
[root@web03 php-5.6.40]# ./configure --prefix=/usr/local/php7
--with-config-file-path=/usr/local/php7/etc
--with-config-file-scan-dir=/usr/local/php7/etc/php.d --enable-mysqlnd
--with-mysqli
--with-pdo-mysql
--enable-fpm
--with-fpm-user=nginx
--with-fpm-group=nginx
--with-gd
--with-iconv
--with-zlib
--enable-xml
--enable-shmop
--enable-sysvsem
--enable-inline-optimization
--enable-mbregex
--enable-mbstring
--enable-ftp --with-openssl
--enable-pcntl
--enable-sockets
--with-xmlrpc
--enable-zip
--enable-soap
--without-pear
--with-gettext
--enable-session
--with-curl
--with-jpeg-dir
--with-freetype-dir
--enable-opcache
#编译并安装
[root@web03 ~]# make -j && make install #性能大约要3G内存,CPU两核的时候建议分开,先执行make,后install,才可以成功
# 复制ini文件
cp php.ini-production /usr/local/php7/etc/php.ini
# 配置fpm
cd /usr/src/php-7.0.0/sapi/fpm
cp init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
# 启动服务
/etc/init.d/php-fpm start
#加入环境变量
[root@web03 ~]# vim /etc/profile
PATH=$PATH:/usr/local/php/sbin
export PATH
使用systemctl管理
[root@web3 system]# ln -s #做软链接
[root@web3 system]# cat /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
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
[root@web3 system]# systemctl daemon-reload
#php的system管理
[root@web03 ~]# systemctl start php-fpm
#通常源码安装无法直接用systemctl启动所以运行以下代码:
[root@web03 ~]# vi /lib/systemd/system/php-fpm.service
[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
ExecStop=/bin/pkill -9 php-fpm
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#添加完成以后保存,使用systemctl list-unit-files --type=service查看有没有php-fpm.service
#如果没有就是用systemctl daemon-reload重新加载,在使用以上命令查看
#添加开机自启
systemctl enable php-fpm.service
[root@web03 ~]# systemctl start php-fpm