我已經在 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