Skip to content

Instantly share code, notes, and snippets.

@joshkersey
Created May 15, 2012 17:25
Show Gist options
  • Save joshkersey/2703467 to your computer and use it in GitHub Desktop.
Save joshkersey/2703467 to your computer and use it in GitHub Desktop.
WordPress setup Bash script
#!/bin/bash
# Installation script for a Wordpress 3.0 website on Ubuntu 10.04
#
# Josh Kersey
# Created: May 15, 2012
# Last Update: June 13, 2012
# get setup parameters
echo "apache vhost name (one word):"
read vhost_name
echo "site url (ex: mysite.cabedgedev.com):"
read site_url
echo "ftp username:"
read ftpuser
echo "mysql root password:"
read mysqlrootpass
echo "wordpress database name:"
read dbname
echo "wordpress database username:"
read dbuser
# Generate random passwords
ftppass=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 10`
dbpass=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 10`
# create the FTP user
sudo useradd -d /var/www/$vhost_name/ -s /usr/sbin/nologin $ftpuser
# Update the new users password
sudo usermod -p `echo $ftppass | openssl passwd -1 -stdin` $ftpuser
# create database and user for database
Q1="create database if not exists $dbname;"
Q2="grant all privileges on $dbname.* to $dbuser@'localhost' identified by '$dbpass';"
Q3="flush privileges;"
SQL="${Q1}${Q2}${Q3}"
sudo mysql -uroot -p$mysqlrootpass -e"$SQL"
# download Wordpress
sudo wget -O -n /usr/local/src/wordpress.tar.gz http://wordpress.org/latest.tar.gz
sudo tar -C /var/www/ -xvzf /usr/local/src/wordpress.tar.gz
sudo mv /var/www/wordpress /var/www/$vhost_name
# configure Wordpress
sudo cp /var/www/$vhost_name/wp-config-sample.php /var/www/$vhost_name/wp-config.php
sudo wget -O /usr/local/src/wp.keys https://api.wordpress.org/secret-key/1.1/salt/
sudo sed -i "s/database_name_here/$dbname/" /var/www/$vhost_name/wp-config.php
sudo sed -i "s/username_here/$dbuser/" /var/www/$vhost_name/wp-config.php
sudo sed -i "s/password_here/$dbpass/" /var/www/$vhost_name/wp-config.php
sudo sed -i '/#@-/r /usr/local/src/wp.keys' /var/www/$vhost_name/wp-config.php
sudo sed -i "/#@+/,/#@-/d" /var/www/$vhost_name/wp-config.php
# configure vhost
sudo bash -c "cat > /etc/apache2/sites-available/$vhost_name" <<EOF
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName $site_url
DocumentRoot /var/www/$vhost_name/
<Directory />
Options None
AllowOverride None
Order deny,allow
deny from all
</Directory>
<Directory /var/www/$vhost_name>
Order allow,deny
allow from all
AllowOverride FileInfo
Options +FollowSymLinks
</Directory>
ErrorLog "|/usr/bin/cronolog /atiba/apache/log/sites/$vhost_name/%Y/%Y-%m-%d-errors.log"
CustomLog "|/usr/bin/cronolog /atiba/apache/log/sites/$vhost_name/%Y/%Y-%m-%d-access.log" common
CustomLog "|/usr/bin/cronolog /atiba/apache/log/sites/all/%Y/%Y-%m-%d-access.log" commonvhost
</VirtualHost>
EOF
# set permissions for directory
sudo chown -R www-data:$ftpuser /var/www/$vhost_name
sudo chmod -R 775 /var/www/$vhost_name
# enable newly created virtualhost
sudo a2ensite $vhost_name
sudo /etc/init.d/apache2 restart
echo ""
echo ""
echo "====================================================="
echo -e "Setup Complete\n\nFTP:\nIP: 216.84.77.163\nusername: $ftpuser\npass: $ftppass\n\nMySQL:\nserver: localhost\ndatabase name:$dbname\nuser: $dbuser\npass: $dbpass"
@ehausen
Copy link

ehausen commented Nov 24, 2016

In line 42...
What does the the -n flag do? I don't find it in the wget documentation
https://gist.github.com/joshkersey/2703467#file-wordpress_setup-sh-L42

@ehausen
Copy link

ehausen commented Nov 24, 2016

never apache need .conf after the filename in sites-available
http://stackoverflow.com/questions/20591889/site-does-not-exist-error-for-a2ensite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment