Apache2 on macOS Sierra 10.12.4

Using the already installed Apache2 Webserver on macOS Sierra 10.12.4 System.

http configuration

Uncomment the following Lines in /etc/apache2/httpd.conf

LoadModule php5_module libexec/apache2/libphp5.so
...
LoadModule userdir_module libexec/apache2/mod_userdir.so
...
Include /private/etc/apache2/extra/httpd-userdir.conf
...
ServerName locahhost

user configuration

Create a new file, named by your username /etc/apache2/users/.conf:


<Directory "/Users//Sites/">
Options Indexes MultiViews
AllowOverride None
Require all granted
</Directory>

adding SSL

If you dont have the need for SSL, just *restart apache* and you’re done. To enable SSL, you will have to modify /etc/apache2/httpd.conf again:

LoadModule socache_shmcb_module libexec/apache2/mod_socache_shmcb.so
...
LoadModule ssl_module libexec/apache2/mod_ssl.so
...
Include /private/etc/apache2/extra/httpd-ssl.conf

create the certificate and key

Here comes the tricky part, we have to create a directory for our certifikate and key files. Change into the new dir and create the Certificates by openssl. Be shure about the „Common Name“ and an „Email Address“, in this example i will leave all other Fields empty:

sudo su
mkdir /etc/apache2/ssl
cd /etc/apache2/ssl
openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout localhost.key -out localhost.crt
Generating a 4096 bit RSA private key
...
writing new private key to 'localhost.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:localhost
Email Address []:root@localhost

restarting apache2

Last of all we have to restart the apache webserver:

sudo apachectl restart

Related Posts