Installation
How to Install Apache HTTP Server on MacOS – TecAdmin
A much better description is here from the folks at Git-Tower.
We need to install a local apache. This page shows how to install http doing this:
brew install httpd
sudo brew services start httpdI found apache2 as a module, so I am trying that instead:
brew install apache2
brew services start apache2Note that using sudo, this fails telling me that Homebrew should not be started as root. So start the apache as normal user.
The Git-Tower folks say it’s better to do this:
brew install httpd phpNote that we’re using the fact that httpd refers to Apache; also note that we’re installing php should you not have it.
Starting, stopping, restarting
brew services start httpd
brew services restart httpd
brew services stop httpdIt has started an apache daemon on port 8080.
Configuration
The tutorial refers to /usr/local/etc/httpd and /usr/local/var/www, but in fact, at least for me, the configuration is in /opt/homebrew/etc/httpd, and the webroot is in /opt/homebrew/var/www.
Install PHP with Apache
Open /opt/homebrew/etc/httpd/httpd.conf and do these changes:
Listen 8080to
Listen 80Comment in
Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.confas well as
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.soAdd these lines where the modules are loaded:
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so
Include /opt/homebrew/etc/httpd/extra/httpd-php.confEdit / create a file /opt/homebrew/etc/httpd/extra/httpd-php.conf:
<IfModule php_module>
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>Virtual Host Setup
Edit /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf.
I’ve e.g. replaced the file by this:
<VirtualHost *:80>
ServerName koolreport-examples.test
DocumentRoot /opt/local/www/examples
<Directory "/opt/local/www/examples">
Require all granted
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName koolreport.test
DocumentRoot /opt/local/www/reports
<Directory "/opt/local/www/reports">
Require all granted
AllowOverride All
</Directory>
</VirtualHost>After having added koolreport.test and koolreport-examples.test to /etc/hosts for 127.0.0.1.
I’m adding koolreport.test as an virtual host; I’ll blog in a separate post about the koolreport installation.
Add a simple phpinfo.php
Create a file /opt/homebrew/var/www/phpinfo.php with this content:
<?php phpinfo();Restart the Server
brew services restart httpdRelated: [[🧠 Ideaverse/Other/- -|Other]]
Created: 1$=dv.span(dv.current().file.ctime)