Last active
February 8, 2016 09:54
-
-
Save rvdsteege/e4a4870ca9f7e86857d2 to your computer and use it in GitHub Desktop.
Script to set up an OS X development environment (Nginx + PHP + MariaDB + Dnsmasq + Homebrew + Composer + npm + wp-cli + grunt-cli + php-code-sniffer + phpmyadmin) easily and quickly. Result after running this script: folders in ~/www/ can be accessed at http://dirname.dev/ without modifying the hosts file. Script provided "AS IS", without any w…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# make executable: chmod +x file | |
echo -e "\033[7m INSTALL XCODE DEVELOPER TOOLS \033[27m" | |
xcode-select --install | |
echo -e "\033[7m HOMEBREW - INSTALL \033[27m" | |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
echo -e "\033[7m HOMEBREW - DOCTOR \033[27m" | |
brew doctor | |
echo -e "\033[7m HOMEBREW - UPDATE \033[27m" | |
brew update | |
echo -e "\033[7m HOMEBREW - UPGRADE PACKAGES \033[27m" | |
brew upgrade --all | |
echo -e "\033[7m HOMEBREW - TAPS \033[27m" | |
brew tap homebrew/dupes | |
brew tap homebrew/versions | |
brew tap homebrew/homebrew-php | |
echo -e "\033[7m HOMEBREW - INSTALL pkg-config \033[27m" | |
brew install pkg-config | |
echo -e "\033[7m HOMEBREW - INSTALL bzip2 \033[27m" | |
brew install bzip2 | |
echo -e "\033[7m HOMEBREW - INSTALL php56 \033[27m" | |
brew install php56 --with-fpm --with-homebrew-curl --with-homebrew-libxslt --with-homebrew-openssl --without-snmp | |
echo -e "\033[7m HOMEBREW - INSTALL php56-xdebug \033[27m" | |
brew install php56-xdebug | |
echo -e "\033[7m HOMEBREW - INSTALL php56-tidy \033[27m" | |
brew install php56-tidy | |
echo -e "\033[7m HOMEBREW - INSTALL mariadb \033[27m" | |
brew install mariadb | |
echo -e "\033[7m HOMEBREW - INSTALL phpmyadmin \033[27m" | |
brew install phpmyadmin | |
echo -e "\033[7m HOMEBREW - INSTALL composer \033[27m" | |
brew install composer | |
echo -e "\033[7m HOMEBREW - INSTALL wp-cli \033[27m" | |
brew install wp-cli | |
echo -e "\033[7m HOMEBREW - INSTALL npm \033[27m" | |
brew install npm | |
echo -e "\033[7m NPM - INSTALL grunt-cli \033[27m" | |
npm install -g grunt-cli | |
echo -e "\033[7m HOMEBREW - INSTALL php-code-sniffer \033[27m" | |
brew install php-code-sniffer | |
echo -e "\033[7m PHP-CODE-SNIFFER - CONFIG \033[27m" | |
git clone -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git /usr/local/Cellar/php-code-sniffer/2.2.0/CodeSniffer/Standards/WordPress | |
phpcs --config-set installed_paths /usr/local/Cellar/php-code-sniffer/2.2.0/CodeSniffer/Standards/WordPress/ | |
echo -e "\033[7m HOMEBREW - INSTALL dnsmasq \033[27m" | |
brew install dnsmasq | |
echo -e "\033[7m HOMEBREW - INSTALL nginx \033[27m" | |
brew install nginx | |
echo -e "\033[7m NGINX - CONFIG \033[27m" | |
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 | |
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 | |
sudo chown -vhR nobody:admin /usr/local/etc/nginx/logs | |
sudo mkdir -p /var/www | |
sudo chown :staff /var/www | |
sudo chmod 775 /var/www | |
mkdir -p ~/www | |
mkdir -p ~/www/hello | |
cat > ~/www/hello/index.php <<EOL | |
<?php | |
echo '<h1>Hello world!</h1> | |
<p>Server setup has been completed successfully.</p> | |
<p>Create new directories in <strong>/Users/$USER/</strong> to add sites. Sites can be reached at: <ul><li>http://dirname.dev/</li><li>http://dirname.app/</li><li>http://dirname.wp/</li><li>http://dirname.wt/</li></ul></p>'; | |
EOL | |
cat > /usr/local/etc/nginx/sites-available/default <<EOL | |
server { | |
listen 80; | |
server_name ~^(www\.)?(?<sname>.+?)\.(dev|app|wp|wt)$; | |
root /Users/$USER/www/\$sname; | |
access_log /usr/local/etc/nginx/logs/\$sname.access.log main; | |
error_log /usr/local/etc/nginx/logs/default.error.log debug; | |
location / { | |
include /usr/local/etc/nginx/conf.d/php-fpm; | |
try_files \$uri \$uri/ /index.php?\$args; | |
} | |
location = /info { | |
allow 127.0.0.1; | |
deny all; | |
rewrite (.*) /.info.php; | |
} | |
error_page 404 /index.php; | |
error_page 403 /403.html; | |
} | |
EOL | |
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 https://github.com/gil0mendes/nginx-virtual-host.git /var/www | |
rm -rf /var/www/.git | |
# Setup SSL | |
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 | |
# Config PHP FPM | |
curl -L https://gist.github.com/frdmn/7853158/raw/php-fpm -o /usr/local/etc/nginx/conf.d/php-fpm | |
# Enable sites | |
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 | |
echo -e "\033[7m DNSMASQ - CONFIG .dev .app .wp .wt \033[27m" | |
mkdir -pv $(brew --prefix)/etc/ | |
cat <<EOT>> $(brew --prefix)/etc/dnsmasq.conf | |
address=/dev/127.0.0.1 | |
address=/app/127.0.0.1 | |
address=/wp/127.0.0.1 | |
address=/wt/127.0.0.1 | |
EOT | |
sudo mkdir -pv /etc/resolver | |
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/dev' | |
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/app' | |
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/wp' | |
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/wt' | |
mkdir -p ~/Library/LaunchAgents | |
echo -e "\033[7m LOAD PHP - ~/Library/LaunchAgents/homebrew.mxcl.php56.plist \033[27m" | |
ln -sfv /usr/local/opt/php56/*.plist ~/Library/LaunchAgents | |
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php56.plist | |
echo -e "\033[7m LOAD MariaDB - ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist \033[27m" | |
ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents | |
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist | |
echo -e "\033[7m SECURE MYSQL \033[27m" | |
mysql_secure_installation | |
echo -e "\033[7m LOAD Nginx \033[27m" | |
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist | |
sudo ln -sfv /usr/local/opt/nginx/*.plist /Library/LaunchAgents | |
sudo chown root:staff /Library/LaunchAgents/homebrew.mxcl.nginx.plist | |
sudo launchctl load /Library/LaunchAgents/homebrew.mxcl.nginx.plist | |
echo -e "\033[7m LOAD DNSMASQ \033[27m" | |
sudo cp -v $(brew --prefix dnsmasq)/*.plist /Library/LaunchDaemons | |
sudo chown root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist | |
sudo launchctl unload -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist | |
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist | |
sudo discoveryutil udnsflushcaches | |
echo -e "\033[7m DNSMASQ - TEST PING\033[27m" | |
ping -c 1 test.dev; ping -c 1 test.app; ping -c 1 test.wp; ping -c 1 test.wt; | |
echo -e "\033[7m SETUP BASH ALIASES\033[27m" | |
echo " | |
### SERVER SERVICES ALIAS | |
# Nginx | |
alias nginx.start='sudo launchctl load /Library/LaunchAgents/homebrew.mxcl.nginx.plist' | |
alias nginx.stop='sudo launchctl unload /Library/LaunchAgents/homebrew.mxcl.nginx.plist' | |
alias nginx.restart='nginx.stop && nginx.start' | |
# PHP-FPM | |
alias php-fpm.start='launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist' | |
alias php-fpm.stop='launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist' | |
alias php-fpm.restart='php-fpm.stop && php-fpm.start' | |
# MySQL | |
alias mysql.start='launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist' | |
alias mysql.stop='launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist' | |
alias mysql.restart='mysql.stop && mysql.start' | |
# Nginx Logs | |
alias nginx.logs.error='tail -250f /usr/local/etc/nginx/logs/error.log' | |
alias nginx.logs.access='tail -250f /usr/local/etc/nginx/logs/access.log' | |
alias nginx.logs.default.access='tail -250f /usr/local/etc/nginx/logs/default.access.log' | |
alias nginx.logs.default-ssl.access='tail -250f /usr/local/etc/nginx/logs/default-ssl.access.log' | |
alias nginx.logs.phpmyadmin.access='tail -250f /usr/local/etc/nginx/logs/phpmyadmin.access.log'" >> ~/.bash_profile | |
echo -e "\033[7m TEST URLs \033[27m" | |
echo "http://hello.dev - Hello world from /Users/$USER/www/hello/index.php" | |
echo "http://localhost - Nginx works page" | |
echo "http://localhost/info - phpinfo()" | |
echo "http://localhost/nope - Not found page" | |
echo "https://localhost:443 - Nginx works page (SSL)" | |
echo "https://localhost:443/info - phpinfo() (SSL)" | |
echo "https://localhost:443/nope - Not found page (SSL)" | |
echo "https://localhost:306 - phpMyAdmin (SSL)" | |
open -a safari http://hello.dev | |
open -a safari http://localhost | |
open -a safari http://localhost/info | |
open -a safari http://localhost/nope | |
open -a safari https://localhost:443 | |
open -a safari https://localhost:443/info | |
open -a safari https://localhost:443/nope | |
open -a safari https://localhost:306 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment