In dit bericht beschrijf ik in een aantal stappen hoe je een WordPress ontwikkelomgeving omgeving kunt opzetten op een Mac.
Brew
Homebrew is een pakket manager voor je Mac en erg handig voor het installeren van allerlei handig tools.
Met het volgende commando kun je Homebrew installeren, maar ik adviseer je om de instructies op de Homebrew website te volgen:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Mocht je Brew al geïnstalleerd hebben dan kun je met het volgende commando Brew bijwerken.
brew update brew upgrade
PHP
PHP kan eenvoudig via Homebrew geïnstalleerd worden, maar hiervoor moet je wel even de PHP repository intappen.
https://github.com/Homebrew/homebrew-php
Met de volgende commando’s kun je de PHP repository voor Homebrew tappen:
brew tap homebrew/dupes brew tap homebrew/versions brew tap homebrew/homebrew-php
Vervolgens kun je met het volgende commando bekijken wel opties er beschikbaar zijn voor het installeren van PHP 5.6:
brew options php56
Als het goed is geeft dit commando het volgende resultaat:
--disable-opcache Build without Opcache extension --disable-zend-multibyte Disable auto-detection of Unicode encoded scripts (PHP 5.2 and 5.3 only) --homebrew-apxs Build against apxs in Homebrew prefix --with-apache Enable building of shared Apache 2.0 Handler module, overriding any options which disable apache --with-cgi Enable building of the CGI executable (implies --without-apache) --with-debug Compile with debugging symbols --with-fpm Enable building of the fpm SAPI executable (implies --without-apache) --with-gmp Build with gmp support --with-homebrew-curl Include Curl support via Homebrew --with-homebrew-libxslt Include LibXSLT support via Homebrew --with-homebrew-openssl Include OpenSSL support via Homebrew --with-imap Include IMAP extension --with-libmysql Include (old-style) libmysql support instead of mysqlnd --with-mssql Include MSSQL-DB support --with-pdo-oci Include Oracle databases (requries ORACLE_HOME be set) --with-pgsql Include PostgreSQL support --with-phpdbg Enable building of the phpdbg SAPI executable (PHP 5.4 and above) --with-thread-safety Build with thread safety --with-tidy Include Tidy support --without-bz2 Build without bz2 support --without-mysql Remove MySQL/MariaDB support --without-pcntl Build without Process Control support --without-pear Build without PEAR --without-snmp Build without SNMP support --HEAD install HEAD version
Ik heb vervolgens PHP 5.6 geïnstalleerd met de volgende opties:
brew install php56 --with-debug --with-fpm --with-homebrew-curl --with-homebrew-libxslt --with-homebrew-openssl
Zodra de installatie is voltooid kun je via het volgende commando controleren of de juiste PHP versie is geïnstalleerd;
php -v
Vervolgens kun je met het volgende commando controleren welke modules er actief zijn:
php -m
PHP-extensies
Er zijn binnen Brew flink wat PHP-extensies beschikbaar, deze kun je met het volgende commando weergeven:
brew search php56-
Hieronder vind je een aantal handige PHP-extensies ik geïnstalleerd heb.
Xdebug
Xdebug is een PHP-extensie die debugging functionaliteiten toevoegt, om dit te installeren kan het volgende commando uitgevoerd worden:
brew install php56-xdebug
Tidy
brew install php56-tidy
PHP-FPM
Om PHP-FPM op te starten dienen de volgende commando’s uitgevoerd te worden:
ln -sfv /usr/local/opt/php56/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
Met behulp van het volgende commando kan vervolgens bekeken worden of PHP-FPM luistert naar poort 9000.
lsof -Pni4 | grep LISTEN | grep php
MariaDB
Ook MariaDB kan via Homebrew geïnstalleerd worden met behulp van het volgende commando:
brew install mariadb
Als het goed is gaat Homebrew vervolgens MariaDB installeren en vermeld het de volgende kanttekeningen:
To have launchd start mariadb at login: ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents Then to load mariadb now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist Or, if you don't want/need launchctl, you can just run: mysql.server start
Aangezien MariaDB van mij opgestart mag worden bij het inloggen heb ik vervolgens het volgende commando uitgevoerd:
ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents
Om MariaDB na installatie op te starten heb ik het volgende commando uitgevoerd:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
Om de MySQL installatie te beveiligen kan het volgende commando uitgevoerd worden:
mysql_secure_installation
Mocht je je root wachtwoord vergeten zijn dan kun je de volgende pagina van MariaDB volgen: https://mariadb.com/blog/how-reset-root-password-mariadb-linux.
Mocht je eerder al MySQL geïnstalleerd hebben dan kun je via de volgende stappen MySQL verwijderen: http://stackoverflow.com/questions/1436425/how-do-you-uninstall-mysql-from-mac-os-x.
phpMyAdmin
Voor het installeren van phpMyAdmin kan het volgende commando uitgevoerd worden:
brew install phpmyadmin
Na de installatie zal Homebrew de volgende kanttekeningen melden:
Note that this formula will NOT install mysql. It is not required since you might want to get connected to a remote database server. Webserver configuration example (add this at the end of your /etc/apache2/httpd.conf for instance) : Alias /phpmyadmin /usr/local/share/phpmyadmin Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all Then, open http://localhost/phpmyadmin More documentation : file:///usr/local/Cellar/phpmyadmin/4.2.8/share/phpmyadmin/doc/ Configuration has been copied to /usr/local/etc/phpmyadmin.config.inc.php Don't forget to: - change your secret blowfish - uncomment the configuration lines (pma, pmapass ...)
Apache uitschakelen
Binnen een Mac wordt Apache vaak standaard opgestart, met het volgende commando kan Apache uitgeschakeld worden:
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
Bron: http://stackoverflow.com/a/20439859
Nginx
Nginx kan geïnstalleerd worden met het volgende commando:
brew install nginx
Na de installatie zal Homebrew de volgende kanttekeningen melden:
Docroot is: /usr/local/var/www The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo. To have launchd start nginx at login: ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents Then to load nginx now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist Or, if you don't want/need launchctl, you can just run: nginx
Na installatie zal er een standaard Nginx configuratie bestand ingesteld zijn. Aangezien in dit bestand veel commentaar staat is het niet heel overzichtelijk. Daarom verwijderen we dit bestand volledig en voegen we een eigen configuratie bestand toe.
rm /usr/local/etc/nginx/nginx.conf
nano /usr/local/etc/nginx/nginx.conf
In het nieuwe configuratie bestand plaatsen we het volgende:
worker_processes 1; error_log /usr/local/etc/nginx/logs/error.log debug; events { worker_connections 256; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /usr/local/etc/nginx/logs/access.log main; sendfile on; keepalive_timeout 65; index index.html index.php; include /usr/local/etc/nginx/sites-enabled/*; }
Op de Nginx documentatie websites staat meer informatie over de verschillende directives:
- http://nginx.org/en/docs/ngx_core_module.html#include
- http://nginx.org/en/docs/ngx_core_module.html#worker_connections
- http://nginx.org/en/docs/http/ngx_http_core_module.html#http
- http://nginx.org/en/docs/http/ngx_http_core_module.html#sendfile
Voor de logs en configuratie bestanden maken we een aantal maken aan:
mkdir -p /usr/local/etc/nginx/logs mkdir -p /usr/local/etc/nginx/sites-available mkdir -p /usr/local/etc/nginx/sites-enabled mkdir -p /usr/local/etc/nginx/conf.d
Composer
brew install composer
WP-CLI
brew install wp-cli
Dnsmasq
Met behulp van Dnsmasq kunnen we er voor zorgen dat elk request naar bijvoorbeeld .dev domeinnamen doorverwezen worden naar je lokale IP-adres 127.0.0.1. Hiermee hoef je dus niet voor elke ontwikkelomgeving een extra regel toe te voegen aan je host bestand (/etc/hosts).
brew install dnsmasq
Na het installeren van Dnsmasq geeft Brew de volgende kanttekeningen:
To configure dnsmasq, copy the example configuration to /usr/local/etc/dnsmasq.conf and edit to taste. cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf To have launchd start dnsmasq at startup: sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons Then to load dnsmasq now: sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
t
Bronnen
- https://mariadb.com/kb/en/mariadb/documentation/getting-started/compiling-mariadb-from-source/building-mariadb-on-mac-os-x-using-homebrew/
- http://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/
- http://elytra.net/hello-world/
- http://learnaholic.me/2012/10/10/installing-nginx-in-mac-os-x-mountain-lion/
- https://coderwall.com/p/dgwwuq
- https://rtcamp.com/tutorials/mac/osx-brew-php-mysql-nginx/
- http://mallinson.ca/osx-web-development/
- http://passingcuriosity.com/2013/dnsmasq-dev-osx/
- http://idevit.nl/node/97
- https://www.digitalocean.com/community/tutorials/how-to-configure-the-nginx-web-server-on-a-virtual-private-server
- https://coderwall.com/p/os6woq