Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added the wordpress setup script to setup new wordpress sites on the …

…configured server
  • Loading branch information...
commit 9977e3f37ccea74f809cb2a447493bebd46b3b05 1 parent 079ea01
Dan Zitting authored
Showing with 115 additions and 42 deletions.
  1. +11 −2 README
  2. +3 −3 files/mydomain.com
  3. +11 −10 server-setup.sh
  4. +90 −27 wordpress-setup.sh
View
13 README
@@ -12,7 +12,7 @@ NOTE: The script disables SSH root login, sets up a sudo user, and changes the S
WORDPRESS-SETUP.SH OVERVIEW
============================
-TO BE COMPLETED
+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.
SLICE SETUP
@@ -53,7 +53,16 @@ DO NOT LOG OUT of your root session. Once the script has completed, the root use
WORDPRESS INSTALLATION
============================
-TO BE COMPLETED
+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.
+ - cd wp-setup
+ - nano wordpress-setup.sh (edit the variables at teh top of the script to meet your needs, then save and exit)
+ - sudo su (enter your password)
+ - sh wordpress-setup.sh
+
+
+WORDPRESS SETUP COMPLETION
+============================
+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.
LICENSE
View
6 files/mydomain.com
@@ -1,8 +1,8 @@
server {
listen 80;
- server_name mydomain.com;
- rewrite ^/(.*) http://www.mydomain.com/$1 permanent;
+ server_name www.mydomain.com;
+ rewrite ^/(.*) http://mydomain.com/$1 permanent;
}
@@ -10,7 +10,7 @@ server {
server {
listen 80;
- server_name www.mydomain.com;
+ server_name mydomain.com;
access_log /home/public_html/mydomain.com/log/access.log;
error_log /home/public_html/mydomain.com/log/error.log;
View
21 server-setup.sh
@@ -136,6 +136,7 @@ config_web()
mkdir /home/public_html
groupadd webmasters
usermod -G webmasters $sudo_user
+ usermod -G webmasters www-data
chown -R $sudo_user.webmasters /home/public_html
chmod -R g+w /home/public_html
find /home/public_html -type d -exec chmod g+s {} \;
@@ -145,20 +146,15 @@ config_web()
copy_site_setup_files()
{
- mkdir /home/$sudo_user/setup
- cp wordpress-setup.sh /home/$sudo_user/setup/wordpress-setup.sh
- mkdir /home/$sudo_user/setup/files
- cp files/mydomain.com /home/$sudo_user/setup/files/mydomain.com
- mkdir /home/$sudo_user/setup/tmp
+ mkdir /home/$sudo_user/wp-setup
+ cp wordpress-setup.sh /home/$sudo_user/wp-setup/wordpress-setup.sh
+ mkdir /home/$sudo_user/wp-setup/files
+ cp files/mydomain.com /home/$sudo_user/wp-setup/files/mydomain.com
+ mkdir /home/$sudo_user/wp-setup/tmp
chown -R dan /home/$sudo_user
chmod -R +x /home/$sudo_user
}
-cleanup()
-{
- rm -rf tmp/*
-}
-
check_vars()
{
if [ -n "$hostname" -a -n "$sudo_user" -a -n "$sudo_user_passwd" -a -n "$root_passwd" -a -n "$ssh_port" ]
@@ -169,6 +165,11 @@ check_vars()
fi
}
+cleanup()
+{
+ rm -rf tmp/*
+}
+
#-- Function calls and flow of execution --#
# clean up tmp
View
117 wordpress-setup.sh
@@ -1,48 +1,111 @@
-site_domain='' #Your wordpress domain (e.g. example.com)
-database_name='' #Your wordpress database name
+#!/bin/bash
+#-- User Defined Variables --#
+site='' #Domain of the site you want to host
+site_db='' #Name of the MySQL wordpress database
+site_db_user='' #Database user account
+site_db_passwd='' #Database password
+mysql_host='localhost' #MySQL host (usually localhost unless you have a seperate database server)
+mysql_root_user='root' #MySQL root user (usually leave this as root)
+mysql_root_passwd='' #Root password for MySQL you setup during server setup
+sudo_user='' #Your server username
+#-- UDVs End --#
-setup_site()
+check_vars()
{
- mkdir /home/public_html/$1 && cd /home/public_html/$1 && mkdir public private log backup && cd -
- find /home/public_html -type d -exec chmod g+s {} \;
- cp files/mydomain.com tmp/domain.$$
- sed -i -r "s/mydomain.com/$1/g" tmp/domain.$$
- cp tmp/domain.$$ /etc/nginx/sites-available/$1
- ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/$1
- /etc/init.d/nginx restart
+ 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" ]
+ then
+ return
+ else
+ echo "Value of variables cannot be empty."
+ exit
+ fi
}
-wordpress_setup()
+cleanup()
{
- cd tmp
- wget http://wordpress.org/latest.tar.gz
- tar -xzvf latest.tar.gz
- mv wordpress/* /home/public_html/$site_domain/public
-
+ rm -rf tmp/*
}
-check_vars()
+create_site()
{
- if [ -n "$site_domain" ]
+ local opt=""
+ if [ -e "/home/public_html/$site" -a -e "/etc/nginx/sites-available/$site" ]
then
- return
+ echo "Site is already created on Nginx!"
+ echo "Do you want to continue?"
+ echo "WARNING: all current files in /home/public_html/$site/public will be deleted if you continue!!!"
+ while [ "$opt" != "y" -a "$opt" != "Y" -a "$opt" != "n" -a "$opt" != "N" ]
+ do
+ read -p "[y/n] : " opt
+ if [ "$opt" = "N" -o "$opt" = "n" ]; then
+ echo "Wordpress installation aborted!"
+ exit
+ fi
+ if [ "$opt" = "Y" -o "$opt" = "y" ]; then
+ echo -n "Cleaning up /home/public_html/$site/public/..."
+ rm -rf /home/public_html/$site/public/*
+ echo "done."
+ fi
+ done
else
- echo "You must set the site_domain variable to your domain name."
+ echo -n "Creating site on nginx..."
+ mkdir /home/public_html/$site && cd /home/public_html/$site && mkdir public private log backup && cd -
+ chown -R $sudo_user.webmasters /home/public_html
+ find /home/public_html -type d -exec chmod g+s {} \; > /dev/null 2>&1
+ cp files/mydomain.com tmp/domain.$$
+ sed -i -r "s/mydomain.com/$site/g" tmp/domain.$$
+ cp tmp/domain.$$ /etc/nginx/sites-available/$site
+ ln -s /etc/nginx/sites-available/$site /etc/nginx/sites-enabled/$site
+ /etc/init.d/nginx restart > /dev/null 2>&1
+ echo "done."
fi
}
-cleanup()
+setup_wp()
{
- rm -rf tmp/*
+ if [ -d /var/lib/mysql/$site_db ]; then
+ echo "Database $site_db aready exists! Wordpress installation aborted!"
+ exit
+ fi
+ echo -n "Installing Wordpress..."
+ cd tmp
+ wget http://wordpress.org/latest.tar.gz
+ tar xzf latest.tar.gz > /dev/null 2>&1
+ mv wordpress/* /home/public_html/$site/public/
+ cd ..
+ mysqladmin -u $mysql_root_user -p$mysql_root_passwd create $site_db
+ { echo "use mysql;"
+ echo grant all on ${site_db}.* to "$site_db_user"@'localhost' identified by "'${site_db_passwd}';"
+ echo "flush privileges;"
+ } > tmp/sql.$$
+ mysql -u $mysql_root_user -p$mysql_root_passwd $site_db < tmp/sql.$$
+ chown -R $www-data.webmasters /home/public_html
+ echo "done."
}
+print_report()
+{
+ echo "WP install script: http://$site/"
+ echo "Database to be used: $site_db"
+ echo "Database user: $site_db_user"
+ echo "Database user password: $site_db_passwd"
+}
+
+# clean up tmp
+cleanup
+
+# check value of all UDVs
+check_vars
+
+# create the site on nginx
+create_site
-# set up a domain on nginx
-setup_site $site_domain
+# setup Wordpress
+setup_wp
-# install wordpress
-wordpress_setup $site_domain
+# print WP installation report
+print_report
# clean up tmp
-cleanup
+cleanup
Please sign in to comment.
Something went wrong with that request. Please try again.