Nginx
{% include JB/setup %}
macOS
Install NGINX with PHP7-FPM on Mac OS X with Homebrew
Install
brew tap homebrew/dupes
brew tap homebrew/php
brew install nginx
brew info php71
brew options php71
brew install php71 --with-imap --without-apache --with-debug --with-phpdbg --with-postgresql
ln -sfv /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/
php -v
php-fpm -v
lsof -Pni4 | grep LISTEN | grep php
sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
Load PHP (Deprecated)
Option 1 (suggested)
sudo gem install lunchy
lunchy list
lunchy stop php
lunchy start php
Option 2
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
Stop
nginx -s stop
Configure
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/www
rm /usr/local/etc/nginx/nginx.conf
curl -L https://gist.github.com/frdmn/7853158/raw/nginx.conf -o /usr/local/etc/nginx/nginx.conf
curl -L https://gist.github.com/frdmn/7853158/raw/php-fpm -o /usr/local/etc/nginx/conf.d/php-fpm
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-ssl
curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_phpmyadmin -o /usr/local/etc/nginx/sites-available/phpmyadmin
git clone http://git.frd.mn/frdmn/nginx-virtual-host.git /var/www
mkdir -p /usr/local/etc/nginx/ssl
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.crt
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=State/L=Town/O=Office/CN=phpmyadmin" -keyout /usr/local/etc/nginx/ssl/phpmyadmin.key -out /usr/local/etc/nginx/ssl/phpmyadmin.crt
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-ssl
ln -sfv /usr/local/etc/nginx/sites-available/phpmyadmin /usr/local/etc/nginx/sites-enabled/phpmyadmin
sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
"Nginx works" page: http://localhost phpinfo(): http://localhost/info "Not Found" page: http://localhost/nope "Nginx works" page (SSL): https://localhost:443 phpinfo() (SSL): https://localhost:443/info "Not Found" page (SSL): https://localhost:443/nope
Default configuration: /usr/local/etc/nginx/nginx.conf.default
Control
curl -L https://gist.github.com/frdmn/7853158/raw/bash_aliases -o /tmp/.bash_aliases
cat /tmp/.bash_aliases >> ~/.bash_aliases
echo "source ~/.bash_aliases" >> ~/.zshrc
Start, stop and restart Nginx with
nginx.start
nginx.stop
nginx.restart
Quickly tail the latest error or access logs
nginx.logs.access
nginx.logs.default.access
nginx.logs.phpmyadmin.access
nginx.logs.default-ssl.access
nginx.logs.error
nginx.logs.phpmyadmin.error
Check config
sudo nginx -t
phpMyAdmin
brew install autoconf
echo 'PHP_AUTOCONF="'$(which autoconf)'"' >> ~/.zshrc && . ~/.zshrc
brew install phpmyadmin
cp /usr/local/etc/phpmyadmin.config.inc.php /usr/local/etc/phpmyadmin.config.inc.php.bak
vi /usr/local/etc/phpmyadmin.config.inc.php
Change this AllowNoPassword
to true
$cfg['Servers'][$i]['AllowNoPassword'] = true;
Login with root without password phpMyAdmin (SSL): https://localhost:306 phpMyAdmin setup (SSL): https://localhost:306/setup/
Ubuntu
Nginx
How To Install Linux, nginx, MySQL, PHP (LEMP) stack on Ubuntu 12.04
Install
sudo apt-get install nginx
sudo apt-get install php5-fpm
Configure PHP
sudo cp /etc/php5/fpm/php.ini /etc/php5/fpm/php.ini.bak
sudo vi /etc/php5/fpm/php.ini
Find the line, cgi.fix_pathinfo=1, and change the 1 to 0
cgi.fix_pathinfo=0
Restart PHP
sudo service php5-fpm restart
Configure Nginx
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak
Add index.php to the index line
Change the server_name from local host to your domain name or IP address (replace the example.com in the configuration)
Change the correct lines in
location ~ \.php$ {
sectionComment the line
#fastcgi_pass 127.0.0.1:9000;
phpinfo
vi /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
Restart Nginx
sudo service nginx restart
If error occur, try
sudo nginx -t