1.安装依赖包
apt-get install gcc
apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g zlib1g-dev
sudo apt-get install openssl
sudo apt-get install libssl-dev
2.安装nginx
进入官网选择版本nginx.org
我选择的是nginx-1.22.1复制下载地址
root@sml-virtual-machine:~# wget https://nginx.org/download/nginx-1.22.1.tar.gz
下载好了解压
root@sml-virtual-machine:~# tar -zxvf nginx-1.22.1.tar.gz
进入里面
root@sml-virtual-machine:~# cd nginx-1.22.1/
监测环境是否满足需求
root@sml-virtual-machine:~/nginx-1.22.1# ./configure
3.编译nginx
安装
root@sml-virtual-machine:~/nginx-1.22.1# apt-get install -y make
编译
root@sml-virtual-machine:~/nginx-1.22.1# make && make install
进入 目录查看编译好的文件
root@sml-virtual-machine:~/nginx-1.22.1# cd /usr/local/nginx
root@sml-virtual-machine:~/nginx-1.22.1# cd /usr/local/nginx
root@sml-virtual-machine:/usr/local/nginx# ls -al
总计 24
drwxr-xr-x 6 root root 4096 8月 5 22:12 .
drwxr-xr-x 11 root root 4096 8月 5 22:12 ..
drwxr-xr-x 2 root root 4096 8月 5 22:12 conf #配置文件
drwxr-xr-x 2 root root 4096 8月 5 22:12 html #源码
drwxr-xr-x 2 root root 4096 8月 5 22:12 logs #日志文件
drwxr-xr-x 2 root root 4096 8月 5 22:12 sbin #启动文件
4.启动nginx
root@sml-virtual-machine:/usr/local/nginx/sbin# ./nginx
5.访问nginx
输入IP
6.增加源地址
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.3
7.安装php
apt-get install php7.3 php7.3-mysql php7.3-fpm php7.3-curl php7.3-xml php7.3-gd php7.3-mbstring php-memcached php7.3-zip
8.配置php-fpm
找到php配置文件
root@sml-virtual-machine:/usr/local/nginx/sbin# find / -name www.conf
查看php版本
root@sml-virtual-machine:/usr/local/nginx/sbin# update-alternatives --config php
切换成7.3版本
进入刚刚找到的配置文件修改监听端口 9000
root@sml-virtual-machine:/usr/local/nginx/sbin# vim /etc/php/7.3/fpm/pool.d/www.conf
重启php
root@sml-virtual-machine:/usr/local/nginx/sbin# service php7.3-fpm restart
7.修改nginx配置文件
进入配置文件目录
root@sml-virtual-machine:/usr/local/nginx/conf# vim nginx.conf
修改为下图
重启一下nginx
root@sml-virtual-machine:/usr/local/nginx/sbin# ./nginx -s reload
查看9000端口有没有
root@sml-virtual-machine:/usr/local/nginx/sbin# lsof -i:9000
8.测试
进入nginx的html页面建一个php文件
root@sml-virtual-machine:/usr/local/nginx/html# vim web.php
写入
IP地址后面输入php文件名显示出下面的页面就成功了