本文已参与[新人创作礼]活动,一起开启掘金创作之路
1:添加 PPA
PPA地址
sudo add-apt-repository ppa:ondrej/php
apt update
安装 PHP PHP 7.3
sudo apt install php7.3-fpm php7.3-cli php7.3-mbstring php7.3-zip php7.3-mysql php7.3-xml php7.3-gd php7.3-bcmath
PHP 7.4
sudo apt install php7.4-fpm php7.4-cli php7.4-mbstring php7.4-zip php7.4-mysql php7.4-xml php7.4-gd php7.4-bcmath
使用不同版本的PHP
本地域名解析
使用命令 sudo vim /etc/hosts 修改 hosts 文件, 添加域名解析
127.0.0.1 73.php.cn
127.0.0.1 74.php.cn
安装 Nginx
sudo apt install nginx
创建项目
创建项目目录
mkdir ~/www/73.php.cn -p
mkdir ~/www/74.php.cn -p
分别在 ~/www/73.php.cn 和 ~/www/74.php.cn 目录下创建 index.php , 文件内容如下
<?php
echo phpinfo();
Nginx 配置
使用命令 sudo vim /etc/nginx/sites-enabled/73.php.cn.conf 创建配置文件, 内容如下
server {
listen 80;
root /home/wyj/www/73.php.cn;
index index.php index.html index.htm index.nginx-debian.html;
server_name 73.php.cn;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
}
}
使用命令 sudo vim /etc/nginx/sites-enabled/74.php.cn.conf 创建配置文件, 内容如下
server {
listen 80;
root /home/wyj/www/73.php.cn;
index index.php index.html index.htm index.nginx-debian.html;
server_name 73.php.cn;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
}
}