Last active
August 29, 2015 13:57
-
-
Save aaroneaton/9769817 to your computer and use it in GitHub Desktop.
Quickly add a new WP install to your server
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/sh | |
# This script assumes a few things | |
# 1. You are running Nginx | |
# 2. WP-CLI is installed | |
# 3. Your user is part of the www-data group | |
# 4. Nginx_ensite is installed (https://github.com/perusio/nginx_ensite) | |
# 5. nginx-wp-common.conf is installed at `/etc/nginx/nginx-wp-common.conf` | |
# How to use | |
# 1. Place this file in your www root | |
# 2. Make this file executable `chmod +x new-site.sh` | |
# 3. Create a database for the new install | |
# 4. Run `sudo ./new-site.sh` | |
# 5. Follow the prompts | |
# 6. Point the domain to your server | |
# 7. Have fun! | |
echo "Domain: " | |
read domain | |
echo "Importing? (y|n)" | |
read importing | |
echo "MySQL Database:" | |
read db_name | |
echo "MySql User:" | |
read db_user | |
echo "MySQL Password:" | |
read db_pass | |
echo "Database Prefix:" | |
read db_prefix | |
if [ $importing = "n" ]; then | |
echo "Site Title:" | |
read site_title | |
echo "Admin User:" | |
read admin_user | |
echo "Admin Password:" | |
read admin_password | |
echo "Admin Email:" | |
read admin_email | |
fi | |
mkdir -pv $domain/public $domain/log | |
cd $domain/public | |
wp core download --path=/var/www/$domain/public | |
wp core config --dbname=$db_name --dbuser=$db_user --dbpass=$db_pass --dbprefix=$db_prefix | |
if [ $importing = "n" ]; then | |
wp core install --url=$domain --title="$site_title" --admin_user=$admin_user --admin_password=$admin_password --admin_email=$admin_email | |
fi | |
cd /var/www | |
chown -R www-data $domain | |
chgrp -R www-data $domain | |
find $domain -type d -exec chmod 775 {} \; | |
find $domain -type f -exec chmod 664 {} \; | |
touch /etc/nginx/sites-available/$domain | |
cat > /etc/nginx/sites-available/$domain <<EOL | |
server { | |
listen 80; | |
server_name $domain; | |
root /var/www/$domain/public; | |
include /etc/nginx/nginx-wp-common.conf; | |
} | |
EOL | |
nginx_ensite /etc/nginx/sites-available/$domain | |
service nginx reload |
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
# nginx-wp-common.conf | |
# | |
# Contains a common configuration for use by nginx on a WordPress | |
# installation. This file should be included in any WordPress site | |
# nginx config with the following line: | |
# | |
# include /etc/nginx/nginx-wp-common.conf; | |
# | |
# See local-nginx-example.conf-sample for a full example | |
location / { | |
index index.php; | |
try_files $uri $uri/ /index.php?$args; | |
} | |
# Weird things happened to me when I had gzip on, may need to try | |
# again in the future as it could have been related to many other | |
# factors - JF | |
gzip off; | |
# Add trailing slash to */wp-admin requests. | |
rewrite /wp-admin$ $scheme://$host$uri/ permanent; | |
# Handle all static assets by serving the file directly. Add directives | |
# to send expires headers and turn off 404 error logging. | |
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { | |
expires 24h; | |
log_not_found off; | |
} | |
# this prevents hidden files (beginning with a period) from being served | |
location ~ /\. { access_log off; log_not_found off; deny all; } | |
# Pass uploaded files to wp-includes/ms-files.php. | |
rewrite /files/$ /index.php last; | |
if ($uri !~ wp-content/plugins) { | |
rewrite /files/(.+)$ /wp-includes/ms-files.php?file=$1 last; | |
} | |
# Rewrite multisite in a subdirectory '.../wp-.*' and '.../*.php'. | |
if (!-e $request_filename) { | |
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last; | |
rewrite ^/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ $1 last; | |
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last; | |
} | |
location ~ \.php$ { | |
client_max_body_size 500M; | |
try_files $uri =404; | |
# Include the fastcgi_params defaults provided by nginx | |
include /etc/nginx/fastcgi_params; | |
fastcgi_read_timeout 3600s; | |
# SCRIPT_FILENAME is a required parameter for things to work properly, | |
# but was missing in the default fastcgi_params on upgrade to nginx 1.4. | |
# We define it here to be sure that it exists. | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
# Use the upstream for php5-fpm that we defined in nginx.conf | |
fastcgi_pass php; | |
# And get to serving the file! | |
fastcgi_index index.php; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment