macOS Mojave comes pre-installed with apache 2.4.34 and PHP 7.1.19. This guide is just to configure apache and install MySQL 5.7.25.
Make a Sites folder in your home folder
$ mkdir ~/SitesAdd a username.conf in /etc/apache2/users:
$ sudo nano /etc/apache2/users/$(whoami).conf
# Save and exit: Cntrl + X, Y, EnterInsert/Replace with the following (replace your username) and save:
<Directory "/Users/username/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
Set correct permission for config
$ sudo chmod 644 /etc/apache2/users/$(whoami).confOpen the main httpd.conf config:
$ sudo nano /etc/apache2/httpd.confScroll down and change listen address and port to:
Listen 127.0.0.1:80 # was: #Listen 12.34.56.78:80Uncomment and save the following (Cntrl+W to search):
LoadModule deflate_module libexec/apache2/mod_deflate.so
LoadModule expires_module libexec/apache2/mod_expires.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php7_module libexec/apache2/libphp7.so
# User home directories
Include /private/etc/apache2/extra/httpd-vhosts.conf
# Virtual hosts
Include /private/etc/apache2/extra/httpd-userdir.conf
Change main server configuration: User and group from:
User _www
Group _www
ServerAdmin [email protected]
#ServerName www.example.com:80
to:
User username
Group staff
ServerAdmin [email protected]
ServerName localhost:80
Document root from:
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
...
AllowOverride none
...
to:
DocumentRoot "/Users/username/Sites"
<Directory "/Users/username/Sites">
...
AllowOverride All
...
Save and exit: Cntrl + X, Y, Enter
Open userdir Apache config file:
$ sudo nano /etc/apache2/extra/httpd-userdir.confUncomment the following then save and exit:
Include /private/etc/apache2/users/*.conf
Restart the Apache server:
$ sudo apachectl -k restartDownload and install MySQL for OSX 10.11
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.25-macos10.14-x86_64.dmg
Copy your temporary password
An awesome tool that keeps all your clipboards:
https://itunes.apple.com/us/app/copyclip-clipboard-history/id595191960?mt=12
Start MySQL: SystemPreference -> MySQL -> Start MySQL Server. Tick Automatically start server on startup.
Command to start and stop MySQL in Terminal: $ sudo launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist $ sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
Open your shell profile
$ nano ~/.bash_profileAdd MySQL directory in a new line and save
$ export PATH="/usr/local/mysql/bin:$PATH"Reload the shell
$ source ~/.bash_profileChange your MySQL root password
$ /usr/local/mysql/bin/mysqladmin -u root -p'temp-password' password 'new-password'To fix a possible 2002 MySQL Socket error
$ sudo mkdir /var/mysql
$ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sockVerify your MySQL version if you want to:
$ /usr/local/mysql/bin/mysql -v -u root -p'newpassword'Restart Apache and enjoy your new MAMP server! 😎
$ sudo apachectl -k restartTo configre virtual hosts, open vhosts config:
$ sudo nano /etc/apache2/extra/httpd-vhosts.confRemove dummy data and paste in your new host:
<VirtualHost *:80>
DocumentRoot "/Users/username/Sites/example-project/public"
ServerName example.local
</VirtualHost>
To use http://localhost, insert:
<VirtualHost *:80>
DocumentRoot "/Users/username/Sites/example-project/public"
ServerName localhost
</VirtualHost>
Remember to add your hosts to /etc/hosts:
$ sudo nano /etc/hostsAnd add your hosts:
127.0.0.1 example.local
127.0.0.1 example2.local
Restart apache!
$ sudo apachectl -k restart