【PHP】php代码在Linux上不被解析问题
| 1 minute read | Using 150 words
解决 php 代码 在 linux 上 不被解析问题
解决方法
1. step1: 编辑 /ect/apache2/apache2.conf
文件, 在尾部添加
# enable executing php files
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
2. 执行一下命令
sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php8.1
NOTE : 上述命令中的 php7.0
替换成你自己的 PHP 版本
你应该会看到以下内容
sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php8.1
Module mpm_event already disabled
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering dependency mpm_prefork for php8.1:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php8.1:
Enabling module php8.1.
To activate the new configuration, you need to run:
systemctl restart apache2
3 .重启 Apache2 服务
sudo systemctl restart apache2
问题原因
apache by default does not recognize php files, i.e. it doesn't know it has to preprocess with
phpthem before displaying.
apache2 默认无法识别 php 文件, 无法解析 php 代码
了解更多: https://askubuntu.com/questions/1166425/php-not-working-on-ubuntu-18-04