Apache not serving local hosts

Apache not serving local hosts

I have set up an Apache Server on an a VMWare hosted Linux Mint 21 Server, I have followed the instructions at this blog to run multiple PHP versions (7.4 and 8.1).

Apache is running fine and serving pages on localhost ok but the Virtual Servers just time out with "DNS_PROBE_FINISHED_NXDOMAIN". I'm stumped as to what I'm doing wrong.

Here is the config file for the PHP 7 version:-

<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>

Here is the config file for the PHP 8 version:-

<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>

The error logs show FPM for PHP7 available:-

[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

The error logs show FPM for PHP8 available as well:-

[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

I was unable to get this configuration working, I reset the VM and used the instructions here to set up the two versions of PHP.

To sum up:-

#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

To switch from PHP 8.x to 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

To switch from PHP 7.x to 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

관련 정보