Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# 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:"
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;"
sudo mysql -uroot -p$mysqlrootpass -e"$SQL"
# download Wordpress
sudo wget -O -n /usr/local/src/wordpress.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
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>
ServerName $site_url
DocumentRoot /var/www/$vhost_name/
<Directory />
Options None
AllowOverride None
Order deny,allow
deny from all
<Directory /var/www/$vhost_name>
Order allow,deny
allow from all
AllowOverride FileInfo
Options +FollowSymLinks
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
# 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:\nusername: $ftpuser\npass: $ftppass\n\nMySQL:\nserver: localhost\ndatabase name:$dbname\nuser: $dbuser\npass: $dbpass"

This comment has been minimized.

Copy link

commented Oct 2, 2017

i use whmcs
i want install wordpress after user sell host and domain automatic,
can help me about that,
thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.