Last active
November 8, 2017 10:46
-
-
Save janoka/57ecdaaf25ff6d9f5881c4b12994e608 to your computer and use it in GitHub Desktop.
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 | |
#Config | |
LOCAL_DEV_PATH="$HOME/www/project/web" | |
LOCAL_DEV_URL='project.dev' | |
PHP_VERSION='7.1' | |
USER=$(whoami) | |
# Install | |
#PHP_SHORT_VERSION=$(echo $PHP_VERSION | sed '' 's/\.//g') | |
brew update | |
brew upgrade | |
brew tap homebrew/php | |
brew install php71 nginx mysql vim git composer php71-xdebug php71-ssh2 php71-mcrypt | |
# brew install node nvm | |
# Setup NGINX | |
sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/ | |
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist | |
# Start: | |
# Create nginx folders. | |
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 | |
# Save the original file. | |
cp /usr/local/etc/nginx/nginx.conf /usr/local/etc/nginx/nginx.conf.original | |
# NGINX settings. | |
cat > /usr/local/etc/nginx/nginx.conf <<EOF | |
user $(whoami) staff; | |
worker_processes 1; | |
events { | |
worker_connections 1024; | |
} | |
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; | |
error_log /usr/local/etc/nginx/logs/error.log debug; | |
sendfile on; | |
keepalive_timeout 65; | |
index index.html index.php; | |
include /usr/local/etc/nginx/sites-enabled/*; | |
} | |
EOF | |
# NGINX site config, please check and update your correct path to CTECH. | |
cat > /usr/local/etc/nginx/sites-available/$LOCAL_DEV_URL.conf <<EOF | |
server { | |
listen 80; | |
server_name $LOCAL_DEV_URL; | |
root $LOCAL_DEV_PATH; | |
access_log /usr/local/var/log/nginx/$LOCAL_DEV_URL.access.log; | |
# access_log off; | |
error_log /usr/local/var/log/nginx/$LOCAL_DEV_URL.error.log; | |
# error_log off; | |
include /usr/local/etc/nginx/conf.d/drupal-8.conf; | |
} | |
EOF | |
ln -s /usr/local/etc/nginx/sites-available/$LOCAL_DEV_URL.conf /usr/local/etc/nginx/sites-enabled/$LOCAL_DEV_URL.conf | |
# Drupal8 NGINX config | |
cat > /usr/local/etc/nginx/conf.d/drupal-8.conf <<EOF | |
# NGINX webserver Drupal 8. config. | |
# See: http://wiki.nginx.org/Drupal | |
index index.html index.php; | |
location ~ /\.ht { | |
deny all; | |
} | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
location = /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
# Very rarely should these ever be accessed outside of your lan | |
location ~* \.(txt|log)\$ { | |
deny all; | |
} | |
location ~ \..*/.*\.php\$ { | |
return 403; | |
} | |
location / { | |
# This is cool because no php is touched for static content | |
try_files \$uri @rewrite; | |
} | |
location @rewrite { | |
# Some modules enforce no slash (/) at the end of the URL | |
# Else this rewrite block wouldn't be needed (GlobalRedirect) | |
rewrite ^/(.*)\$ /index.php?q=\$1; | |
} | |
# Php settings. | |
include /usr/local/etc/nginx/conf.d/php-fpm.conf; | |
# Fighting with ImageCache? This little gem is amazing. | |
location ~ ^/sites/.*/files/imagecache/ { | |
try_files \$uri @rewrite; | |
} | |
# Catch image styles for D7 too. | |
location ~ ^/sites/.*/files/styles/ { | |
try_files \$uri @rewrite; | |
} | |
location ~* \.(js|css|png|jpg|jpeg|gif|ico)\$ { | |
expires max; | |
# log_not_found off; | |
} | |
EOF | |
sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.nginx.plist | |
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist | |
# PhpFPM | |
brew services stop $(brew services list | grep php | grep started) | |
cat > /usr/local/etc/nginx/conf.d/php-fpm.conf <<EOF | |
# NGINX configuration file for PHP-FPM | |
location ~ \.php\$ { | |
try_files \$uri = 404; | |
fastcgi_pass 127.0.0.1:9001; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
EOF | |
#PHP | |
PHP_INI='/usr/local/etc/php/7.1/php.ini' | |
cp $PHP_INI $PHP_INI.original | |
mkdir -p ~/Library/LaunchAgents | |
ln -sfv /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/ | |
sed -i '' 's/^memory_limit.*$/memory_limit = 512M/g' $PHP_INI | |
sed -i '' 's/^max_input_time.*$/max_input_time = 120/g' $PHP_INI | |
sed -i '' 's/^max_execution_time.*$/max_execution_time = 60/g' $PHP_INI | |
cat > /usr/local/etc/php/7.1/php-fpm.conf <<EOF | |
[global] | |
error_log = /usr/local/var/log/php-fpm.log | |
daemonize = no | |
[www] | |
user = $USER | |
group = staff | |
listen = 127.0.0.1:9001 | |
listen.mode = 0666 | |
pm = dynamic | |
pm.max_children = 10 | |
pm.start_servers = 3 | |
pm.min_spare_servers = 2 | |
pm.max_spare_servers = 5 | |
EOF | |
# Xdebug | |
cat > /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini <<EOF | |
[xdebug] | |
zend_extension="/usr/local/opt/php71-xdebug/xdebug.so" | |
xdebug.idekey=PHPSTORM | |
xdebug.remote_enable = On | |
xdebug.remote_connect_back = On | |
xdebug.profiler_enable_trigger = On | |
xdebug.profiler_output_name = profiler.%t.%R | |
xdebug.trace_enable_trigger = On | |
xdebug.trace_output_name = trace.%t.%R | |
EOF | |
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist | |
#Host file | |
sudo sed -i "" "/127\.0\.0\.1 $LOCAL_DEV_URL/d" /etc/hosts | |
sudo sh -c "echo '127.0.0.1 $LOCAL_DEV_URL' >> /etc/hosts" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment