Para instalar Nginx, PHP-FPM y MariaDB utilizaremos Homebrew.
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"Chequeamos si hay algún conflicto.
$ brew doctorFinalmente actualizamos Homebrew y realizamos upgrade
$ brew update && brew upgradeHomebrew no tiene por defecto la formula para PHP-FPM, por lo tanto necesitamos agregar esto primero:
$ brew tap homebrew/dupes
$ brew tap homebrew/phpAhora lo instalamos con los siguientes argumentos:
$ brew install --without-apache --with-fpm --with-mysql php56El proceso de instalación podrá durar varios minutos
# If you use Bash
echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile
. ~/.bash_profileConfiguración para el inicio automático
$ mkdir -p ~/Library/LaunchAgents
$ ln -sfv /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/E iniciamos PHP-FPM
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plistAsegurese que PHP-FPM este escuchando el puerto 9000
$ lsof -Pni4 | grep LISTEN | grep phpSalida:
php-fpm 42205 andres 6u IPv4 0x580b0a517df80913 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 42206 andres 0u IPv4 0x580b0a517df80913 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 42207 andres 0u IPv4 0x580b0a517df80913 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 42208 andres 0u IPv4 0x580b0a517df80913 0t0 TCP 127.0.0.1:9000 (LISTEN)$ brew install mariadb$ unset TMPDIR
$ mysql_install_dbConfiguración para el inicio automático
$ ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plistSeguridad y cambio de clave usuario root:
$ mysql_secure_installationTest de conexión:
$ mysql -uroot -p$ brew install nginx$ sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/
$ sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plistTest servidor web:
Iniciamos el servicio
$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plistHacemos un petición con curl:
$ curl -IL http://127.0.0.1:8080Deveriamos ver la siguiente salida desde la terminal:
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Mon, 19 Oct 2014 19:07:47 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Mon, 19 Oct 2014 19:01:32 GMT
Connection: keep-alive
ETag: "5444dea7-264"
Accept-Ranges: bytesDetenemos el servicio:
$ sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.nginx.plistContinuamos con la configuración:
nginx.conf
creamos algunas carpetas:
$ 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
$ mkdir -p /usr/local/etc/nginx/ssl
$ sudo mkdir -p /var/www
$ sudo chown :staff /var/www
$ sudo chmod 775 /var/wwwReemplazamos el archivo nginx.conf:
$ rm /usr/local/etc/nginx/nginx.conf
$ curl -L https://gist.github.com/frdmn/7853158/raw/nginx.conf -o /usr/local/etc/nginx/nginx.confLoad PHP FPM
$ curl -L https://gist.github.com/frdmn/7853158/raw/php-fpm -o /usr/local/etc/nginx/conf.d/php-fpmCreamos Virtual Host por defecto:
$ curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_default -o /usr/local/etc/nginx/sites-available/default
$ curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_default-ssl -o /usr/local/etc/nginx/sites-available/default-sslClonamos un ejemplo de virtual host:
$ git clone http://git.frd.mn/frdmn/nginx-virtual-host.git /var/www
$ rm -rf /var/www/.gitSetup SSL
$ mkdir -p /usr/local/etc/nginx/sslGeneramos un certificado ssl (4096bit RSA)
$ openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=State/L=Town/O=Office/CN=localhost" -keyout /usr/local/etc/nginx/ssl/localhost.key -out /usr/local/etc/nginx/ssl/localhost.crtHabilitamos Virtual Hosts:
$ ln -sfv /usr/local/etc/nginx/sites-available/default /usr/local/etc/nginx/sites-enabled/default
$ ln -sfv /usr/local/etc/nginx/sites-available/default-ssl /usr/local/etc/nginx/sites-enabled/default-sslIniciamos Nginx:
$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plistTest final
- http://localhost → “Nginx works” page
- http://localhost/info → phpinfo()
- http://localhost/nope → ” Not Found” page
- https://localhost:443 → “Nginx works” page (SSL)
- https://localhost:443/info → phpinfo() (SSL)
- https://localhost:443/nope → “Not Found” page (SSL)
- https://localhost:306 → phpMyAdmin (SSL)
$ curl -L https://gist.github.com/frdmn/7853158/raw/bash_aliases -o /tmp/.bash_aliases
$ cat /tmp/.bash_aliases >> ~/.bash_aliases
# If you use Bash
$ echo "source ~/.bash_aliases" >> ~/.bash_profile$ source ~/.bash_profileNginx
Iniciar, detener y reiniciar nginx:
$ nginx.start
$ nginx.stop
$ nginx.restartTail rápido a logs de acceso/error:
$ nginx.logs.access
$ nginx.logs.default.access
$ nginx.logs.phpmyadmin.access
$ nginx.logs.default-ssl.access
$ nginx.logs.error
$ nginx.logs.phpmyadmin.errorPara chequear la configuración:
$ sudo nginx -tPHP-FPM
Iniciar, detener y reiniciar php-fpm:
$ php-fpm.start
$ php-fpm.stop
$ php-fpm.restartPara chequear la configuración:
$ php-fpm -tMySQL
$ mysql.server start
$ mysql.server stop
$ mysql.server restart$ brew install imagemagick
$ brew install php56-imagickPara asegurarnos que el path de PHP este correcto:
$ echo $PATH | grep php56
$ export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH"No reconoce el comando mysql, mysql_install_db, ni ningún comando de MySQL/MariaDB
Para solucionar este inconveniente nos cambiamos al directorio /usr/local/bin/
$ cd /usr/local/bin/Y creamos los links simbólicos de cada archivo que se encuentra en /usr/local/Cellar/mariadb/versionx/bin/
Ejemplo:
$ ln -s /usr/local/Cellar/mariadb/10.1.14/bin/* .Rails on OSX 10.11 El Capitan: Library not loaded: libmysqlclient.18.dylib
Solución:
$ cd /usr/local/opt/
$ mkdir mariadb
$ cd mariadb
$ ln -s /usr/local/Cellar/mariadb/10.1.14/lib .