一、安装包下载与安装
1.安装apache2
sudo apt-get install apache2
2.安装PHP
//-y的意思是全部默认选择yes
//8条命令分8次输入
//1
sudo apt -y install software-properties-common apt-transport-https lsb-release ca-certificates
//2
sudo add-apt-repository ppa:ondrej/php
//3
sudo apt-get update
//4
sudo apt install php7.2-fpm php7.2-mysql php7.2-curl php7.2-gd php7.2-mbstring php7.2-xml php7.2-xmlrpc php7.2-zip php7.2-opcache -y
//5
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/7.2/fpm/php.ini
//重启PHP
//6
systemctl restart php7.2-fpm
//7
sudo apt-get update
//8
sudo apt-get upgrade -y
3.安装libapache2-mod-php7.2,使apache2支持PHP
sudo apt-get install libapache2-mod-php7.2
4. 测试
新建一个test.php 放到 /var/www/html/中
通过访问 http://localhost/test.php 测试,代码如下:
<?php
phpinfo();
?>
命令行查看 php -v