Website unavailable after upgrade to High Sierra

Learning that lasts. Online courses from $14.99

I upgraded a MacBook Pro laptop that was running OS X El Capitan to macOS High Sierra (10.13.6) this week. The laptop was running Apache webserver software. After the upgrade, the system wasn't listening on port 80 for HTTP connections, but I was able to start it listening again with sudo apachectl start.

$ netstat -a | grep http | grep LISTEN
$ sudo apachectl start
Enter PIN for 'Certificate For PIV Authentication (JAMES CAMERON)': 
$ netstat -a | grep http | grep LISTEN
tcp46      0      0  *.http                 *.*                    LISTEN     
$

I was then able to access the default webpage at http://localhost which displayed the page contained in index.html.en file in the DocumentRoot directory at /Library/WebServer/Documents, but whenever I attempted to display pages I had created elsewhere, I kept getting a "404 Not Found" page indicating the requested URL was not found on the server. When I checked /private/etc/apache2/extra/httpd-vhosts.conf, I found it had a April 4, 2018 timestamp, but no longer had the virtual host information I had previously put in the file.

$ ls -l /private/etc/apache2/extra/httpd-vhosts.conf
-rw-r--r--  1 root  wheel  1519 Apr  4  2018 /private/etc/apache2/extra/httpd-vhosts.conf
$

However, the previous version of the file was still in the dirctory with a ~previous appended to the filename.

$ ls -l /private/etc/apache2/extra/httpd-vhosts.conf~previous
-rw-r--r--  1 root  wheel  1373 Dec 15  2017 /private/etc/apache2/extra/httpd-vhosts.conf~previous
$

I was thus able to copy the previous version of the file over the new httpd-vhosts.conf file after saving the new version to another location in case I needed to reference it again.

$ sudo cp -a /private/etc/apache2/extra/httpd-vhosts.conf~previous /private/etc/
apache2/extra/httpd-vhosts.conf
Enter PIN for 'Certificate For PIV Authentication (JAMES CAMERON)': 
$

The /etc/apache2/httpd.conf file that is the main configuration file for Apache was also replaced during the operating system (OS) upgrade. The prior version also was preserved with httpd.conf~previous appended to it.

$ ls -l /etc/apache2/httpd.conf
-rw-r--r--  1 root  wheel  21150 Mar 13 14:29 /etc/apache2/httpd.conf
$ ls -l /etc/apache2/httpd.conf~previous
-rw-r--r--  1 root  wheel  20497 Feb 27  2018 /etc/apache2/httpd.conf~previous
$

Since the new version was missing the changes I had made previously to have Apache load the virtual hosts file and support Perl and Python scripts, after copying the new version of httpd.conf to a location where I could preserve it if I needed to reference it again, I copied that prior version over top of the httpd.conf file placed on the system during the upgrade and restarted the Apache web server.

$ sudo cp /etc/apache2/httpd.conf~previous /etc/apache2/httpd.conf Enter PIN for 'Certificate For PIV Authentication (JAMES CAMERON)': 
$ sudo apachectl restart
Enter PIN for 'Certificate For PIV Authentication (JAMES CAMERON)': 
$

But Apache wasn't listening for connections after I attempted to restart it, though I hadn't seen any error message. When I used the configtest option for apachectl, I saw that Apache couldn't load a module for PHP.

$ sudo apachectl restart
Enter PIN for 'Certificate For PIV Authentication (JAMES CAMERON)': 
$ netstat -a | grep http | grep LISTEN
$ sudo apachectl configtest
Enter PIN for 'Certificate For PIV Authentication (JAMES CAMERON)': 
httpd: Syntax error on line 169 of /private/etc/apache2/httpd.conf: Cannot load 
libexec/apache2/libphp5.so into server: dlopen(/usr/libexec/apache2/libphp5.so, 
10): image not found
$

So I commented out the line that loaded that PHP module in /etc/apache2/httpd.conf by putting a # at the beginning of the line. I didn't even have to issue an apachectl command again to start it listening on port 80 after I commented out the line.

$ netstat -an | grep 80 | grep LISTEN
tcp46      0      0  *.80                   *.*                    LISTEN     
$ netstat -a | grep http | grep LISTEN
tcp46      0      0  *.http                 *.*                    LISTEN     
$

But then, when I attempted to view PHP pages, the PHP code on the pages would be displayed rather than executed. So I then looked in the version of the httpd.conf that was installed during the OS upgrade process that I had saved and found the following line:

#LoadModule php7_module libexec/apache2/libphp7.so

I replaced the line referring to libphp5.so with the above line, removing the pound sign, i.e., the #, so the module would be loaded and then restarted Apache with sudo apachectl restart. The PHP code then was executed on PHP pages.

Related articles:

  1. Running an Apache web server under OS X El Capitan
  2. PHP for Apache on OS X El Capitan
  3. Using Perl with Apache under OS X El Capitan
  4. Using Python scripts with Apache on OS X El Capitan