Skip to content

Instantly share code, notes, and snippets.

@tommyskott
Last active April 20, 2020 14:42
Show Gist options
  • Save tommyskott/26ee5c84a9bebf16e6fe720a44ca2601 to your computer and use it in GitHub Desktop.
Save tommyskott/26ee5c84a9bebf16e6fe720a44ca2601 to your computer and use it in GitHub Desktop.
macOS: Localhost, Apache, Php, MariaDB (MySQL)

Localhost with Apache, Php, mariaDB

Apache config

httpd -v
sudo atom /etc/apache2/httpd.conf

Load modules

LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule include_module libexec/apache2/mod_include.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php7_module libexec/apache2/libphp7.so

SSL:
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

User tommyskott
Group staff

DocumentRoot "/Users/tommyskott/wwwroot"
<Directory "/Users/tommyskott/wwwroot">
    Options FollowSymLinks Multiviews
    MultiviewsMatch Any
    AllowOverride All
    Require all granted
</Directory>

Include /private/etc/apache2/extra/httpd-vhosts.conf
Include /private/etc/apache2/vhosts/*.conf

SSL

cd /etc/apache2/extra/httpd-ssl.conf
Comment out everything in: 
<VirtualHost _default_:443></VirtualHost>

brew install mkcert
brew install nss # if you use Firefox
mkcert -install

mkdir /tmp/crt && cd /tmp/crt
mkcert borgenfalk.local "*.borgenfalk.local"

sudo mkdir /etc/apache2/ssl
sudo mv *.pem /etc/apache2/ssl

Virtual hosts

sudo mkdir /etc/apache2/vhosts
cd /etc/apache2/vhosts
sudo touch _default.conf
sudo atom _default.conf

<VirtualHost *:80>
    DocumentRoot "/Users/tommyskott/wwwroot"
</VirtualHost>

sudo touch 001-borgenfalk.local.conf
sudo atom 001-borgenfalk.local.conf

<VirtualHost *:80>
  ServerName borgenfalk.local
  ServerAlias www.borgenfalk.local
  DocumentRoot /Users/tommyskott/wwwroot/borgenfalk

  ErrorLog "/private/var/log/apache2/borgenfalk.local-error_log"
  CustomLog "/private/var/log/apache2/borgenfalk.local-access_log" common

  <Directory "/Users/tommyskott/wwwroot/borgenfalk">
    Options FollowSymLinks Indexes
    AllowOverride All
    Require all granted
  </Directory>
  
  RewriteEngine on
  RewriteCond %{SERVER_NAME} =borgenfalk.local [OR]
  RewriteCond %{SERVER_NAME} =www.borgenfalk.local
  RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

sudo cp 001-borgenfalk.local.conf 001-borgenfalk.local-ssl.conf
sudo atom 001-borgenfalk.local-ssl.conf

<IfModule mod_ssl.c>
  <VirtualHost *:443>
  	ServerName borgenfalk.local
    ServerAlias www.borgenfalk.local
  	DocumentRoot /Users/tommyskott/wwwroot/borgenfalk

  	ErrorLog "/private/var/log/apache2/borgenfalk.local-error_log"
    CustomLog "/private/var/log/apache2/borgenfalk.local-access_log" common

    SSLEngine on
    SSLCertificateFile "/private/etc/apache2/ssl/borgenfalk.local+1.pem"
    SSLCertificateKeyFile "/private/etc/apache2/ssl/borgenfalk.local+1-key.pem"
  </VirtualHost>
</IfModule>

Restart Apache

apachectl restart
apachectl configtest

Hosts config

sudo atom /etc/hosts
127.0.0.1       borgenfalk.local
127.0.0.1       www.borgenfalk.local

Clear DNS cache

dscacheutil -flushcache

Php

Note: some missing modules in built-in php on macOS Mojave. Let's install it from brew instead.

brew install php
brew services start php
php -v
php --ini
php -i
php -m

Since brew is not used as default package manager for PHP on Mac anymore, you have to use pecl to install additional PHP extensions.

brew install imagemagick
pecl install imagick

Multiple Php versions

brew install php@7.1
brew unlink php && brew link --force php@7.1
echo 'export PATH="/usr/local/opt/php@7.1/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.1/sbin:$PATH"' >> ~/.zshrc
brew services stop php
brew services start php@7.1

MySQL (mariaDB)

Note: Problems with using root user in mariadb. Login with sudo and create a new user and give them all privileges.

brew install mariadb
brew services start mariadb

mysql -V
which mysql

sudo mysql -u root -p
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
FLUSH PRIVILEGES;
exit

brew services restart mariadb

Sequel Pro (nightly build)

brew tap homebrew/cask-versions
brew cask install sequel-pro-nightly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment