Apache 不为本地主机提供服务

Apache 不为本地主机提供服务

我已经在 VMWare 托管的 Linux Mint 21 服务器上设置了一个 Apache 服务器,我按照以下说明进行操作这个博客运行多个 PHP 版本(7.4 和 8.1)。

Apache 运行良好,在本地主机上提供页面服务,但虚拟服务器却超时,显示“DNS_PROBE_FINISHED_NXDOMAIN”。我不明白我做错了什么。

以下是 PHP 7 版本的配置文件:-

<VirtualHost *:80>
ServerAdmin [email protected]
ServerName legacy.local
DocumentRoot /var/www/legacy.local
DirectoryIndex info.php

<Directory /var/www/legacy.local>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

<FilesMatch \.php$>
# From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
</FilesMatch>

ErrorLog ${APACHE_LOG_DIR}/legacy.local_error.log
CustomLog ${APACHE_LOG_DIR}/legacy.local_access.log combined
</VirtualHost>

这是 PHP 8 版本的配置文件:-

<VirtualHost *:80>
ServerAdmin [email protected]
ServerName new.local
DocumentRoot /var/www/new.local
DirectoryIndex info.php

<Directory /var/www/new.local>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

<FilesMatch \.php$>
# From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost"
</FilesMatch>

ErrorLog ${APACHE_LOG_DIR}/new.local_error.log
CustomLog ${APACHE_LOG_DIR}/new.local_access.log combined
</VirtualHost>

错误日志显示 PHP7 的 FPM 可用:-

[08-Dec-2022 13:20:36] NOTICE: fpm is running, pid 801
[08-Dec-2022 13:20:36] NOTICE: ready to handle connections
[08-Dec-2022 13:20:36] NOTICE: systemd monitor interval set to 10000ms

错误日志显示 PHP8 的 FPM 也可用:-

[08-Dec-2022 13:20:36] NOTICE: fpm is running, pid 821
[08-Dec-2022 13:20:36] NOTICE: ready to handle connections
[08-Dec-2022 13:20:36] NOTICE: systemd monitor interval set to 10000ms

答案1

我无法让此配置正常工作,我重置了虚拟机并使用了此处的说明设置两个版本的PHP。

总结:-

#Set up default Web Server with PHP 8.x
sudo apt-get install -y lamp-server^
#Add PHP 7.x
sudo add-apt-repository -y ppa:ondrej/php
sudo apt update -y
sudo apt install -y php7.4

要从 PHP 8.x 切换到 7.x:-

sudo a2dismod php8.1
sudo systemctl restart apache2
sudo systemctl status apache2
sudo a2enmod php7.4
sudo systemctl restart apache2
sudo systemctl status apache2

要从 PHP 7.x 切换到 8.x:-

sudo a2dismod php7.4
sudo systemctl restart apache2
sudo systemctl status apache2
sudo a2enmod php8.1
sudo systemctl restart apache2
sudo systemctl status apache2

相关内容