Setup apache and php without xampp on mac
Published:
Tested on Mac Ventura 13.2.1 (22D68)
- Install httpd/apache
- Install php
- Open
/usr/local/etc/httpd/httpd.conf - (Optional) If you want to have numerous hosts without a unique hostname each, uncomment
Include /usr/local/etc/httpd/extra/httpd-vhosts.conf(remove #) - Uncomment
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so, handle url rewrite. - (Optional) Change default project directory in
DocumentRoot"/Library/Projects/php"
<Directory "/Library/Projects/php"> - Create a separate apache conf file, let’s say in
extras/directory, with the namephp.conf - Add a script to load php module in it.
#or /usr/local/opt/php/lib/httpd/modules/libphp.soLoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so - Add these php configurations in the next line.
<IfModule php_module> <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> <IfModule dir_module> DirectoryIndex index.html index.php </IfModule> </IfModule> - Back to the
httpd.conf, load thephp.conffile by adding this line.
Include /usr/local/etc/httpd/extra/php.conf - start/restart httpd.
sudo brew services start httpd - Run php.
sudo php -S 127.0.0.1:8080. - You can configure custom domain name in
etc/hostsfile.
References: Apache on macos
Possible problems:
Could not determine the server.
Or you have an existing apache installed/configured already.
