Instruction to Install Apache, MySQL, and PHP on MacOS Mojave

Instruction to Install Apache, MySQL, and PHP on MacOS Mojave
0

#1

The following Full instructions will guide you to Install Apache, MySQL, PHP, and phpMyAdmin for a real Local Web Development Environment on the new MacOS 10.14 Mojave.

1. Install and configure Apache

  • Enable Apache

Apache is disabled by default from MacOS. To enable it, enter the following command line through Terminal (Found under /Applications/Utilities/)

sudo apachectl start

To stop and restart Apache on MacOS:

sudo apachectl stop
sudo apachectl restart

After start Apache, Enter the following to check version:

httpd -v


The apache version on my MacOS Mojave is Apache/2.4.34
You may want to enter the http://localhost/ on the web-browser to make sure it works:

If the default localhost does not work, use the following to see problems.

apachectl configtest
  • Where is the Root documents?

The default ( http://localhost/) loads data from

/Library/WebServer/Documents/

  • User Level Root

Clearly, There is other web root directory which is missing by default is the ‘ ~/Sites’ folder in the User account. This takes a bit longer to set up but some users are very accustomed to using it. How to solve this little thing?

Simply, you just to make a “ Sites ” folder at the root level of your account and then it will work at normal. Once you make the Sites folder you will notice that it has a unique icon which is a throwback from a few versions older. Make that folder before you set up the user configuration file described next.

You have to make a few additional tweaks to get the ~/Sites folder back up and running.


Add a “username.conf” filed under /etc/apache2/users/ by the following command line:

Nano /etc/apache2/users/username.conf

Fill the following

<Directory "/Users/username/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>


To Save, Control X, then Y, then Enter.

Set 644 permission:

sudo chmod 644 /etc/apache2/users/username.conf

Next, we need to modify httpd.conf under /etc/apache2/ to uncomment some modules.

sudo nano /etc/apache2/httpd.conf

Uncomment the following modules

LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule include_module libexec/apache2/mod_include.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so

While you have this file open also to get php running, uncomment the below … (Mentioned also in the PHP part of the article).

LoadModule php7_module libexec/apache2/libphp7.so

And also uncomment this configuration file also in httpd.conf – which allows user home directories.

Include /private/etc/apache2/extra/httpd-userdir.conf

To Save, Control X, then Y, then Enter.

We now need make some changes to httpd-userdir.conf file.

sudo nano /etc/apache2/extra/httpd-userdir.conf

Uncomment the following

Include /private/etc/apache2/users/*.conf

To Save, Control X, then Y, then Enter.

Apache need to be reloaded to update new changes.

sudo apachectl restart

At the results, this user level document root will be viewable at:

http://localhost/~username/

  • Override .htaccess and allow URL Rewrites
    We should allow any .htaccess files used to override the default settings.
sudo nano /etc/apache2/httpd.conf

add AllowOverride All like the following screenshot

Uncomment the following

LoadModule rewrite_module libexec/apache2/mod_rewrite.so