I have a new Mac Studio running OS X 14.5 Sonoma. I am trying to configure my Apache2 server to run PHP.
Following suggestions found in various web pages I’ve done the following…
I’ve modified /etc/apache2/httpd.conf
and created /etc/apache2/users/<myshortusername>.conf
to enable Apache2. This seems to have worked. Both http://localhost/index.html
and http://localhost/~<myshortusername>/index.html
display the expected output.
/etc/apache2/users/<myshortusername>.conf
contains
<Directory "/Users/john/Sites/">
AddLanguage en .en
AddHandler cgi-script .cgi .pl .php
Options Indexes MultiViews FollowSymLinks ExecCGI
AllowOverride None
Require host localhost
</Directory>
[I’m suspicious of the AddHandler
line. That seems to be saying that .php
files are handled by cgi-script
?]
I installed PHP v8.2 using MacPorts. I believe the command I used was
sudo port install php82
but I don’t have a written record of this.
I then edited /etc/apache2/httpd.conf
in an attempt to enable PHP.
I added
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php_module libexec/apache2/mod_php82.so
I changed
<IfModule dir_module>
# DirectoryIndex index.html
DirectoryIndex index.html index.php
</IfModule>
and
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
and
# LogLevel warn
LogLevel debug
and changed the definintion of ServerAdmin
to a custom email address.
My test file (info.php
) in ~<myshortusername>/Sites
is
<html>
<body>
<h1>Localhost</h1>
<?php
echo (phpinfo());
?>
</body>
<html>
I then stopped and restarted the Apache server with
sudo launchctl remove org.apache2.httpd
sudo launchctl start -w /System/Library/LaunchDaemons/org.apache.httpd.plist
On typing http://localhost~<myshortusername>/info.php
into the address bar of my browser I see:
/private/var/log/apache2/error_log
is empty.
Since I see [email protected]
rather than my custom ServerAdmin
and since errror_log
is empty, I think that my changes to httpd.conf
aren’t being picked up.
apachectl configtest
returns Syntax OK
.
What am I doing wrong?