├── .gitignore ├── README ├── files ├── iptables.up.rules ├── mydomain.com ├── php-fastcgi ├── php-fastcgi-rc ├── wp.conf └── wp_super_cache.conf ├── server-setup.sh ├── tmp └── tmp-directory-info └── wordpress-setup.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | UPDATE (4/26/2011): Have started getting a number of questions from folks about if these scripts are still fresh (eg. still work). They still work great on Slicehost using latest Ubuntu and Ubuntu LTS. There are many additional features that would be great to add, however we have not done so simply as a result of relying on Wordpress less. Pull requests welcome though. 2 | 3 | 4 | ABOUT 5 | ============================ 6 | This set of script is designed to automate the deployment of Wordpress sites on a fresh server installation using an Nginx stack. The first script (vps-setup.sh) sets up and configures the server and deployment stack. The second (wordpress-setup.sh) installs a Wordpress site on this server. The Wordpress install script can be run multiple times on a given server if you would like to host multiple Wordpress sites on the same server. 7 | 8 | 9 | SERVER-SETUP.SH OVERVIEW 10 | ============================ 11 | This script requires a fresh Ubuntu server Slice. It installs and configures the required OS packages and the MySQL/Nginx/PHP/Postfix deployment stack for Wordpress. All packages are installed through aptitude for future upgrade ease. 12 | 13 | NOTE: The script disables SSH root login, sets up a sudo user, and changes the SSH port for server security. At the top of the script, you can see the variable that are to be set prior to running the script. All variable should have value, otherwise the script will not run. 14 | 15 | 16 | WORDPRESS-SETUP.SH OVERVIEW 17 | ============================ 18 | This script is meant to be run after completing the server-setup.sh script. It completely sets up a new Wordpress installation on the server. It first creates the Nginx vhost for the site, then adds a MySQL database for the site, and finally downloads and unpacks the latest version of Wordpress. From there, you can simply visit the site and use the Wordpress web interface to finish the install. 19 | 20 | 21 | SLICE SETUP 22 | ============================ 23 | Before you run the script, login into Slicemanager, click "DNS" tab and "Reverse DNS". Replace the server's record with: server.domain.com (REPLACE server.domain.com with the correct host name). The script has been tested on a 1 GB slice running Ubuntu Karmic and seems to be performing very well running 10 relatively low traffic Wordpress sites. It should work fine on any Ubuntu Slice. 24 | 25 | 26 | SERVER SETUP/CONFIGURATION 27 | ============================ 28 | 1. Download the script files from the GitHub repo as a tar file. 29 | 2. Upload the tar file to /root. 30 | 3. Login to the server as root and unzip the file: 31 | - tar -xzvf wordpress-slice-setup.tar.gz 32 | 4. Enter setup directory: 33 | - cd worpress-slice-setup 34 | 5. Edit script variables for your configuration: 35 | - nano server-setup.sh 36 | - Edit the first three lines to match your needs 37 | - ctrl + o to save changes, ctrl + x to exit 38 | 5. sh server-setup.sh 39 | 6. At the prompts, do the following: 40 | - Please provide the prefix of Imagemagick installation [autodetect] : {PRESS ENTER} 41 | - MySQL root password dialog: {ENTER A PASSWORD} 42 | - Enter current password for root (enter for none): {ENTER THE MYSQL PASSWORD YOU JUST SETUP} 43 | - Change the root password? [Y/n]: n 44 | - Remove anonymous users? [Y/n]: y 45 | - Disallow root login remotely? [Y/n]: y 46 | - Remove test database and access to it? [Y/n]: y 47 | - Reload privilege tables now? [Y/n]: y 48 | - Postfix setup dialog, first prompt: select "Internet Site" 49 | - Postfix setup dialog, second prompt: {REPLACE LOCALHOST WITH SERVER HOSTNAME} 50 | 51 | 52 | SERVER SETUP COMPLETION 53 | ============================ 54 | DO NOT LOG OUT of your root session. Once the script has completed, the root user can no longer SSH into the server. You need to use the login for the sudo_user you setup in the script variables. So, start a new SSH session and try to login using the account of the sudo_user. Once you have confirmed you can login successfully, you can close the root session. 55 | 56 | 57 | WORDPRESS INSTALLATION 58 | ============================ 59 | Log into the server as the sudo_user you setup in the server setup script. You will see a wp-setup folder has been added in your home directory. Go to that folder and then simply modify the script variables, su to root, and run the script. 60 | - cd wp-setup 61 | - nano wordpress-setup.sh (edit the variables at teh top of the script to meet your needs, then save and exit) 62 | - sudo su (enter your password) 63 | - sh wordpress-setup.sh 64 | 65 | 66 | WORDPRESS SETUP COMPLETION 67 | ============================ 68 | To finish the installation, just visit the domain you just setup and follow the web-based prompts. Finished! You are running a high-performance Wordpress site. 69 | 70 | 71 | LICENSE 72 | ============================ 73 | Copyright (c) 2011 by Workpapers.com LLC 74 | 75 | This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. 76 | 77 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 78 | 79 | -------------------------------------------------------------------------------- /files/iptables.up.rules: -------------------------------------------------------------------------------- 1 | *filter 2 | 3 | 4 | # Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0 5 | -A INPUT -i lo -j ACCEPT 6 | -A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT 7 | 8 | 9 | # Accepts all established inbound connections 10 | -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 11 | 12 | 13 | # Allows all outbound traffic 14 | # You can modify this to only allow certain traffic 15 | -A OUTPUT -j ACCEPT 16 | 17 | 18 | # Allows HTTP and HTTPS connections from anywhere (the normal ports for websites) 19 | -A INPUT -p tcp --dport 80 -j ACCEPT 20 | -A INPUT -p tcp --dport 443 -j ACCEPT 21 | -A INPUT -p tcp --dport 25 -j ACCEPT 22 | 23 | # Allows SSH connections 24 | # 25 | # THE -dport NUMBER IS THE SAME ONE YOU SET UP IN THE SSHD_CONFIG FILE 26 | # 27 | -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT 28 | 29 | 30 | # Allow ping 31 | -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT 32 | 33 | 34 | # log iptables denied calls 35 | -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7 36 | 37 | 38 | # Reject all other inbound - default deny unless explicitly allowed policy 39 | -A INPUT -j REJECT 40 | -A FORWARD -j REJECT 41 | 42 | COMMIT 43 | -------------------------------------------------------------------------------- /files/mydomain.com: -------------------------------------------------------------------------------- 1 | server { 2 | 3 | listen 80; 4 | server_name www.mydomain.com; 5 | rewrite ^/(.*) http://mydomain.com/$1 permanent; 6 | 7 | } 8 | 9 | 10 | server { 11 | 12 | listen 80; 13 | server_name mydomain.com; 14 | 15 | access_log /home/public_html/mydomain.com/log/access.log; 16 | error_log /home/public_html/mydomain.com/log/error.log; 17 | 18 | location / { 19 | 20 | root /home/public_html/mydomain.com/public/; 21 | index index.php index.html; 22 | 23 | # Basic version of Wordpress parameters, supporting nice permalinks. 24 | include /etc/nginx/conf/wp.conf; 25 | # Advanced version of Wordpress parameters supporting nice permalinks and WP Super Cache plugin 26 | include /etc/nginx/conf/wp_super_cache.conf; 27 | } 28 | 29 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 30 | # 31 | location ~ \.php$ { 32 | fastcgi_pass 127.0.0.1:9000; 33 | fastcgi_index index.php; 34 | include /etc/nginx/fastcgi_params; 35 | fastcgi_param SCRIPT_FILENAME /home/public_html/mydomain.com/public/$fastcgi_script_name; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /files/php-fastcgi: -------------------------------------------------------------------------------- 1 | # 2 | # Settings for php-cgi in external FASTCGI Mode 3 | # 4 | 5 | # Should php-fastcgi run automatically on startup? (default: no) 6 | 7 | START=yes 8 | 9 | # Which user runs PHP? (default: www-data) 10 | 11 | EXEC_AS_USER=www-data 12 | 13 | # Host and TCP port for FASTCGI-Listener (default: localhost:9000) 14 | 15 | FCGI_HOST=localhost 16 | FCGI_PORT=9000 17 | 18 | # Environment variables, which are processed by PHP 19 | 20 | PHP_FCGI_CHILDREN=5 21 | PHP_FCGI_MAX_REQUESTS=1000 22 | 23 | -------------------------------------------------------------------------------- /files/php-fastcgi-rc: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: php-fastcgi 4 | # Required-Start: $all 5 | # Required-Stop: $all 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # Short-Description: Start and stop php-cgi in external FASTCGI mode 9 | # Description: Start and stop php-cgi in external FASTCGI mode 10 | ### END INIT INFO 11 | 12 | # Author: Kurt Zankl 13 | 14 | # Do NOT "set -e" 15 | 16 | PATH=/sbin:/usr/sbin:/bin:/usr/bin 17 | DESC="php-cgi in external FASTCGI mode" 18 | NAME=php-fastcgi 19 | DAEMON=/usr/bin/php-cgi 20 | PIDFILE=/var/run/$NAME.pid 21 | SCRIPTNAME=/etc/init.d/$NAME 22 | 23 | # Exit if the package is not installed 24 | [ -x "$DAEMON" ] || exit 0 25 | 26 | # Read configuration variable file if it is present 27 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME 28 | 29 | # Load the VERBOSE setting and other rcS variables 30 | #. /lib/init/vars.sh 31 | 32 | # Define LSB log_* functions. 33 | # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. 34 | . /lib/lsb/init-functions 35 | 36 | # If the daemon is not enabled, give the user a warning and then exit, 37 | # unless we are stopping the daemon 38 | if [ "$START" != "yes" -a "$1" != "stop" ]; then 39 | log_warning_msg "To enable $NAME, edit /etc/default/$NAME and set START=yes" 40 | exit 0 41 | fi 42 | 43 | # Process configuration 44 | export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS 45 | DAEMON_ARGS="-q -b $FCGI_HOST:$FCGI_PORT" 46 | 47 | 48 | do_start() 49 | { 50 | # Return 51 | # 0 if daemon has been started 52 | # 1 if daemon was already running 53 | # 2 if daemon could not be started 54 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ 55 | || return 1 56 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \ 57 | --background --make-pidfile --chuid $EXEC_AS_USER --startas $DAEMON -- \ 58 | $DAEMON_ARGS \ 59 | || return 2 60 | } 61 | 62 | do_stop() 63 | { 64 | # Return 65 | # 0 if daemon has been stopped 66 | # 1 if daemon was already stopped 67 | # 2 if daemon could not be stopped 68 | # other if a failure occurred 69 | start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE > /dev/null # --name $DAEMON 70 | RETVAL="$?" 71 | [ "$RETVAL" = 2 ] && return 2 72 | # Wait for children to finish too if this is a daemon that forks 73 | # and if the daemon is only ever run from this initscript. 74 | # If the above conditions are not satisfied then add some other code 75 | # that waits for the process to drop all resources that could be 76 | # needed by services started subsequently. A last resort is to 77 | # sleep for some time. 78 | start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON 79 | [ "$?" = 2 ] && return 2 80 | # Many daemons don't delete their pidfiles when they exit. 81 | rm -f $PIDFILE 82 | return "$RETVAL" 83 | } 84 | 85 | case "$1" in 86 | start) 87 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" 88 | do_start 89 | case "$?" in 90 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 91 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 92 | esac 93 | ;; 94 | stop) 95 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" 96 | do_stop 97 | case "$?" in 98 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 99 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 100 | esac 101 | ;; 102 | restart|force-reload) 103 | log_daemon_msg "Restarting $DESC" "$NAME" 104 | do_stop 105 | case "$?" in 106 | 0|1) 107 | do_start 108 | case "$?" in 109 | 0) log_end_msg 0 ;; 110 | 1) log_end_msg 1 ;; # Old process is still running 111 | *) log_end_msg 1 ;; # Failed to start 112 | esac 113 | ;; 114 | *) 115 | # Failed to stop 116 | log_end_msg 1 117 | ;; 118 | esac 119 | ;; 120 | *) 121 | echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 122 | exit 3 123 | ;; 124 | esac 125 | 126 | : 127 | -------------------------------------------------------------------------------- /files/wp.conf: -------------------------------------------------------------------------------- 1 | # WordPress pretty URLs: (as per dominiek.com) 2 | if (-f $request_filename) { 3 | break; 4 | } 5 | if (-d $request_filename) { 6 | break; 7 | } 8 | rewrite ^(.+)$ /index.php?q=$1 last; 9 | 10 | 11 | # Enable nice permalinks for WordPress: (as per Yawn.it) 12 | error_page 404 = //index.php?q=$uri; 13 | -------------------------------------------------------------------------------- /files/wp_super_cache.conf: -------------------------------------------------------------------------------- 1 | # if the requested file exists, return it immediately 2 | if (-f $request_filename) { 3 | break; 4 | } 5 | 6 | set $supercache_file ''; 7 | set $supercache_uri $request_uri; 8 | 9 | if ($request_method = POST) { 10 | set $supercache_uri ''; 11 | } 12 | 13 | # Using pretty permalinks, so bypass the cache for any query string 14 | if ($query_string) { 15 | set $supercache_uri ''; 16 | } 17 | 18 | if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) { 19 | set $supercache_uri ''; 20 | } 21 | 22 | # if we haven't bypassed the cache, specify our supercache file 23 | if ($supercache_uri ~ ^(.+)$) { 24 | set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html; 25 | } 26 | 27 | # only rewrite to the supercache file if it actually exists 28 | if (-f $document_root$supercache_file) { 29 | rewrite ^(.*)$ $supercache_file break; 30 | } 31 | 32 | # all other requests go to Wordpress 33 | if (!-e $request_filename) { 34 | rewrite . /index.php last; 35 | } 36 | -------------------------------------------------------------------------------- /server-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #-- User Defined Variables --# 4 | hostname='' #Your hostname (e.g. server.example.com) 5 | sudo_user='' #Your username 6 | sudo_user_passwd='' #your password 7 | root_passwd='' #Your new root password 8 | ssh_port='22' #Your SSH port if you wish to change it from the default 9 | #-- UDV End --# 10 | 11 | set_locale() 12 | { 13 | echo -n "Setting up system locale..." 14 | { locale-gen en_US.UTF-8 15 | unset LANG 16 | /usr/sbin/update-locale LANG=en_US.UTF-8 17 | } > /dev/null 2>&1 18 | export LANG=en_US.UTF-8 19 | echo "done." 20 | } 21 | 22 | set_hostname() 23 | { 24 | if [ -n "$hostname" ] 25 | then 26 | echo -n "Setting up hostname..." 27 | hostname $hostname 28 | echo $hostname > /etc/hostname 29 | echo "127.0.0.1 $hostname" >> /etc/hostname 30 | echo "done." 31 | fi 32 | } 33 | 34 | change_root_passwd() 35 | { 36 | if [ -n "$root_passwd" ] 37 | then 38 | echo -n "Changing root password..." 39 | echo "$root_passwd\n$root_passwd" > tmp/rootpass.$$ 40 | passwd root < tmp/rootpass.$$ > /dev/null 2>&1 41 | echo "done." 42 | fi 43 | } 44 | 45 | create_sudo_user() 46 | { 47 | if [ -n "$sudo_user" -a -n "$sudo_user_passwd" ] 48 | then 49 | id $sudo_user > /dev/null 2>&1 && echo "Cannot create sudo user! User $sudo_user already exists!" && touch tmp/sudofailed.$$ && return 50 | echo -n "Creating sudo user..." 51 | useradd -d /home/$sudo_user -s /bin/bash -m $sudo_user 52 | echo "$sudo_user_passwd\n$sudo_user_passwd" > tmp/sudopass.$$ 53 | passwd $sudo_user < tmp/sudopass.$$ > /dev/null 2>&1 54 | echo "$sudo_user ALL=(ALL) ALL" >> /etc/sudoers 55 | { echo 'export PS1="\[\e[32;1m\]\u\[\e[0m\]\[\e[32m\]@\h\[\e[36m\]\w \[\e[33m\]\$ \[\e[0m\]"' 56 | echo 'alias ll="ls -la"' 57 | echo 'alias a2r="sudo /etc/init.d/apache2 stop && sleep 2 && sudo /etc/init.d/apache2 start"' 58 | echo 'alias n2r="sudo /etc/init.d/nginx stop && sleep 2 && sudo /etc/init.d/nginx start"' 59 | echo 'alias ver="cat /etc/lsb-release"' 60 | } >> /home/$sudo_user/.bashrc 61 | echo "done." 62 | fi 63 | } 64 | 65 | config_ssh() 66 | { 67 | conf='/etc/ssh/sshd_config' 68 | echo -n "Configuring SSH..." 69 | sed -i -r 's/\s*X11Forwarding\s+yes/X11Forwarding no/g' $conf 70 | sed -i -r 's/\s*UsePAM\s+yes/UsePAM no/g' $conf 71 | sed -i -r 's/\s*UseDNS\s+yes/UseDNS no/g' $conf 72 | grep -q "UsePAM no" $conf || echo "UsePAM no" >> $conf 73 | grep -q "UseDNS no" $conf || echo "UseDNS no" >> $conf 74 | if [ -n "$ssh_port" ] 75 | then 76 | sed -i -r "s/\s*Port\s+[0-9]+/Port $ssh_port/g" $conf 77 | cp files/iptables.up.rules tmp/fw.$$ 78 | sed -i -r "s/\s+22\s+/ $ssh_port /" tmp/fw.$$ 79 | fi 80 | if id $sudo_user > /dev/null 2>&1 && [ ! -e tmp/sudofailed.$$ ] 81 | then 82 | sed -i -r 's/\s*PermitRootLogin\s+yes/PermitRootLogin no/g' $conf 83 | echo "AllowUsers $sudo_user" >> $conf 84 | fi 85 | echo "done." 86 | } 87 | 88 | setup_firewall() 89 | { 90 | echo -n "Setting up firewall..." 91 | cp tmp/fw.$$ /etc/iptables.up.rules 92 | iptables -F 93 | iptables-restore < /etc/iptables.up.rules > /dev/null 2>&1 && 94 | sed -i 's%pre-up iptables-restore < /etc/iptables.up.rules%%g' /etc/network/interfaces 95 | sed -i -r 's%\s*iface\s+lo\s+inet\s+loopback%iface lo inet loopback\npre-up iptables-restore < /etc/iptables.up.rules%g' /etc/network/interfaces 96 | /etc/init.d/ssh reload > /dev/null 2>&1 97 | echo "done." 98 | } 99 | 100 | install_pkg() 101 | { 102 | echo "Installing packages." 103 | sleep 1 104 | aptitude update 105 | aptitude -y safe-upgrade 106 | aptitude -y full-upgrade 107 | aptitude -y install screen build-essential php5-common php5-dev php5-mysql php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-cgi php5-mcrypt php5-curl php5-gd php5-memcache php5-mhash php5-pspell php5-snmp php5-sqlite libmagick9-dev php5-cli 108 | aptitude -y install make php-pear 109 | echo "Installing ImageMagick PHP module. Just press at prompt.\n" 110 | sleep 1 111 | pecl install imagick 112 | echo "extension=imagick.so" >> /etc/php5/cgi/php.ini 113 | sed -i -r 's/\s*memory_limit\s+=\s+16M/memory_limit = 48M/g' /etc/php5/cgi/php.ini 114 | aptitude -y install mysql-server mysql-client libmysqlclient15-dev 115 | mysql_secure_installation 116 | aptitude -y install subversion git-core vsftpd 117 | echo "Installing Postfix mail server\n" 118 | echo "Select 'Internet Site', and then for 'System mail name:' -> $hostname\n". 119 | sleep 2 120 | aptitude -y install dnsutils postfix telnet mailx 121 | grep "root: $sudo_user" /etc/aliases > /dev/null 2>&1 || echo "root: $sudo_user" >> /etc/aliases 122 | newaliases 123 | aptitude -y install nginx 124 | aptitude -y install libfcgi0 125 | echo "Done." 126 | } 127 | 128 | config_web() 129 | { 130 | mkdir /etc/nginx/conf/ 131 | cp files/wp.conf /etc/nginx/conf/ 132 | cp files/wp_super_cache.conf /etc/nginx/conf/ 133 | cp files/php-fastcgi /etc/default/ 134 | cp files/php-fastcgi-rc /etc/init.d/php-fastcgi 135 | chmod +x /etc/init.d/php-fastcgi 136 | mkdir /home/public_html 137 | groupadd webmasters 138 | usermod -G webmasters $sudo_user 139 | usermod -G webmasters www-data 140 | chown -R $sudo_user.webmasters /home/public_html 141 | chmod -R g+w /home/public_html 142 | find /home/public_html -type d -exec chmod g+s {} \; 143 | /etc/init.d/nginx start 144 | /etc/init.d/php-fastcgi start 145 | } 146 | 147 | copy_site_setup_files() 148 | { 149 | mkdir /home/$sudo_user/wp-setup 150 | cp wordpress-setup.sh /home/$sudo_user/wp-setup/wordpress-setup.sh 151 | mkdir /home/$sudo_user/wp-setup/files 152 | cp files/mydomain.com /home/$sudo_user/wp-setup/files/mydomain.com 153 | mkdir /home/$sudo_user/wp-setup/tmp 154 | chown -R $sudo_user /home/$sudo_user 155 | chmod -R +x /home/$sudo_user 156 | } 157 | 158 | check_vars() 159 | { 160 | if [ -n "$hostname" -a -n "$sudo_user" -a -n "$sudo_user_passwd" -a -n "$root_passwd" -a -n "$ssh_port" ] 161 | then 162 | return 163 | else 164 | echo "Value of variables cannot be empty." 165 | fi 166 | } 167 | 168 | cleanup() 169 | { 170 | rm -rf tmp/* 171 | } 172 | 173 | #-- Function calls and flow of execution --# 174 | 175 | # clean up tmp 176 | cleanup 177 | 178 | # check value of all UDVs 179 | check_vars 180 | 181 | # set host name of server 182 | set_hostname 183 | 184 | # set system locale 185 | set_locale 186 | 187 | # change root user password 188 | change_root_passwd 189 | 190 | # create and configure sudo user 191 | create_sudo_user 192 | 193 | # configure ssh 194 | config_ssh 195 | 196 | # set up and activate firewall 197 | setup_firewall 198 | 199 | # install packages 200 | install_pkg 201 | 202 | # configure nginx web server 203 | config_web 204 | 205 | # copy over site setup files 206 | copy_site_setup_files 207 | 208 | # clean up tmp 209 | cleanup 210 | -------------------------------------------------------------------------------- /tmp/tmp-directory-info: -------------------------------------------------------------------------------- 1 | This directory is used in the install process. Just ignore it, it is automatically cleaned out by the script. -------------------------------------------------------------------------------- /wordpress-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #-- User Defined Variables --# 4 | site='' #Domain of the site you want to host 5 | site_db='' #Name of the MySQL wordpress database 6 | site_db_user='' #Database user account 7 | site_db_passwd='' #Database password 8 | mysql_host='localhost' #MySQL host (usually localhost unless you have a seperate database server) 9 | mysql_root_user='root' #MySQL root user (usually leave this as root) 10 | mysql_root_passwd='' #Root password for MySQL you setup during server setup 11 | sudo_user='' #Your server username 12 | #-- UDVs End --# 13 | 14 | check_vars() 15 | { 16 | if [ -n "$site" -a -n "$site_db" -a -n "$site_db_user" -a -n "$site_db_passwd" -a -n "$mysql_host" -a -n "$mysql_root_user" -a -n "$mysql_root_passwd" -a -n "$sudo_user" ] 17 | then 18 | return 19 | else 20 | echo "Value of variables cannot be empty." 21 | exit 22 | fi 23 | } 24 | 25 | cleanup() 26 | { 27 | rm -rf tmp/* 28 | } 29 | 30 | create_site() 31 | { 32 | local opt="" 33 | if [ -e "/home/public_html/$site" -a -e "/etc/nginx/sites-available/$site" ] 34 | then 35 | echo "Site is already created on Nginx!" 36 | echo "Do you want to continue?" 37 | echo "WARNING: all current files in /home/public_html/$site/public will be deleted if you continue!!!" 38 | while [ "$opt" != "y" -a "$opt" != "Y" -a "$opt" != "n" -a "$opt" != "N" ] 39 | do 40 | read -p "[y/n] : " opt 41 | if [ "$opt" = "N" -o "$opt" = "n" ]; then 42 | echo "Wordpress installation aborted!" 43 | exit 44 | fi 45 | if [ "$opt" = "Y" -o "$opt" = "y" ]; then 46 | echo -n "Cleaning up /home/public_html/$site/public/..." 47 | rm -rf /home/public_html/$site/public/* 48 | echo "done." 49 | fi 50 | done 51 | else 52 | echo -n "Creating site on nginx..." 53 | mkdir /home/public_html/$site && cd /home/public_html/$site && mkdir public private log backup && cd - 54 | chown -R $sudo_user.webmasters /home/public_html 55 | find /home/public_html -type d -exec chmod g+s {} \; > /dev/null 2>&1 56 | cp files/mydomain.com tmp/domain.$$ 57 | sed -i -r "s/mydomain.com/$site/g" tmp/domain.$$ 58 | cp tmp/domain.$$ /etc/nginx/sites-available/$site 59 | ln -s /etc/nginx/sites-available/$site /etc/nginx/sites-enabled/$site 60 | /etc/init.d/nginx restart > /dev/null 2>&1 61 | echo "done." 62 | fi 63 | } 64 | 65 | setup_wp() 66 | { 67 | if [ -d /var/lib/mysql/$site_db ]; then 68 | echo "Database $site_db aready exists! Wordpress installation aborted!" 69 | exit 70 | fi 71 | echo -n "Installing Wordpress..." 72 | cd tmp 73 | wget http://wordpress.org/latest.tar.gz 74 | tar xzf latest.tar.gz > /dev/null 2>&1 75 | mv wordpress/* /home/public_html/$site/public/ 76 | cd .. 77 | mysqladmin -u $mysql_root_user -p$mysql_root_passwd create $site_db 78 | { echo "use mysql;" 79 | echo grant all on ${site_db}.* to "$site_db_user"@'localhost' identified by "'${site_db_passwd}';" 80 | echo "flush privileges;" 81 | } > tmp/sql.$$ 82 | mysql -u $mysql_root_user -p$mysql_root_passwd $site_db < tmp/sql.$$ 83 | chown -R www-data.webmasters /home/public_html/$site 84 | chmod -R g+w /home/public_html/$site 85 | echo "done." 86 | } 87 | 88 | print_report() 89 | { 90 | echo "WP install script: http://$site/" 91 | echo "Database to be used: $site_db" 92 | echo "Database user: $site_db_user" 93 | echo "Database user password: $site_db_passwd" 94 | } 95 | 96 | # clean up tmp 97 | cleanup 98 | 99 | # check value of all UDVs 100 | check_vars 101 | 102 | # create the site on nginx 103 | create_site 104 | 105 | # setup Wordpress 106 | setup_wp 107 | 108 | # print WP installation report 109 | print_report 110 | 111 | # clean up tmp 112 | cleanup 113 | --------------------------------------------------------------------------------