Install WordPress in 60 Seconds - Scalable Cloud Deployments
WordPress
WordPress is one of the most popular CMS platforms used to build websites today. In fact, according to WordPress.com, a whole lot of the internet in fact:
What Will I Learn?
In this tutorial I will describe a methodology by which you may deploy a working self-hosted WordPress instance in as little as 60 seconds.
Best of all, the instance you deploy is fully scalable so if your site grows and needs more power, you can login, click a few buttons, and be online with more memory and CPU in a few minutes. If you have a self-hosted WordPress site today, this infrastructure will give you far more reliability and this script makes it about as easy as it can get.
We will cover deployments on the DigitalOcean cloud platform and particularly the User Data functionality.
Requirements
You will need an account at https://www.digitalocean.com/ to deploy a cloud server. They are a well-established firm offering reliable cloud servers for as little as $5 per month. The best part is they allow you to resize your servers in a click to easily handle any growing traffic or performance needs. You'll never need to migrate your site again.
Difficulty
DigitalOcean deploys only Linux servers offering only command line access. That is inherently difficult even for the technically astute, however my exact implementation here is beyond basic.
- Basic
Tutorial Contents
Here's a quick overview of the areas we'll cover.
- Create Your Server
- Distribution
- Size
- Region
- User Data
- Finalize
- Final Steps
- User Data Script
Create Your Server
Once you have your account created, you can simply click the Create button and select Droplets from the menu.
Distribution
Next, we want to select CentOS 7.4 for our image.
Size
The size to choose is an 'it depends' question but the beauty of the cloud is that you can change your size later! I can confirm that WordPress will run on the smallest 512MB instance so I'd say start there.
When you resize an instance, you can never reduce your disk space so the initial size you pick will always be your minimum so I'd recommend starting small and growing as needed.
Region
Generally speaking, pick a datacenter geographically near the primary users of your website. Often, it's a mix so really this is a decision of personal preference.
User Data
This is where the magic happens. DigitalOcean offers functionality they call User Data that allows you to pass in a script to be executed at the time a server is deployed. This allows us to automate literally everything we need to get up and running, and is why we can deploy a server in 60 seconds.
This is a simple checkbox, that once selected reveals a textarea that we can paste our script into.
I've included the script at the end rather than inline for easy reading.
Finalize
You can set a hostname, no spaces or special characters, that will be set in your deployed server. This is generally not a major concern so leave the default or set as you feel appropriate.
Simply click the create button and the deploy will kick off.
You'll soon see the IP address of the newly deployed server:
Simply click to Copy that IP and paste it into your browser. As you will see, your server is live and ready to finalize the WordPress install!
Final Steps
You can finalize your setup using the IP address directly in your browser. When you are finished, just update DNS for your domain to point to this IP and you'll be online on your new server.
Everything I've outlined here assumes this is a brand new deployment of WordPress, however I realize you may be restoring from a prior version. All of that can be included in here, such as adding in a mysqldump from the existing server or even copying over the theme or other assets from the existing site. There's a lot of was to go about this so feel free to comment here and I can help you to include something like that in this script as well.
User Data Script
#!/bin/bash
####################
## USER VARIABLES ##
####################
SERVER_NAME="mydomain.com"
DATABASE_NAME='wordpress'
DATABASE_USER='wordpress'
DATABASE_PASSWORD='my_long_complex_password'
###############################
## APPLICATION SOURCE FILES ##
###############################
mkdir -p /var/www/$SERVER_NAME
#########################
## APACHE INSTALLATION ##
#########################
yum -y install httpd
systemctl enable httpd
apachectl start
######################
## PHP INSTALLATION ##
######################
cd /tmp
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y --enablerepo=remi,remi-php72 install httpd php php-common php-mysql
yum -y --enablerepo=remi,remi-php72 install php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml
#####################
## DISABLE SELINUX ##
#####################
setenforce 0
############################
## WORDPRESS INSTALLATION ##
############################
yum install -y wget
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xfz /tmp/latest.tar.gz
mv wordpress/* /var/www/$SERVER_NAME/
###########################
# SETUP WORDPRESS CONFIG ##
###########################
rm -f /var/www/$SERVER_NAME/wp-config.php
sed -e "s/database_name_here/$DATABASE_NAME/g" /var/www/$SERVER_NAME/wp-config-sample.php | sed -e "s/username_here/$DATABASE_USER/g" | sed -e "s/password_here/$DATABASE_PASSWORD/g" > /var/www/$SERVER_NAME/wp-config.php
chown -R apache:apache /var/www/$SERVER_NAME
##########################
## APACHE CONFIGURATION ##
##########################
touch /etc/httpd/conf/vhosts.conf
echo "" > /etc/httpd/conf/vhosts.conf
echo "<Directory "/var/www/*">" >> /etc/httpd/conf/vhosts.conf
echo " Options -Indexes +MultiViews +IncludesNOEXEC +FollowSymLinks +ExecCGI" >> /etc/httpd/conf/vhosts.conf
echo " AllowOverride All" >> /etc/httpd/conf/vhosts.conf
echo " XBitHack Off" >> /etc/httpd/conf/vhosts.conf
echo " DirectoryIndex index.html index.php" >> /etc/httpd/conf/vhosts.conf
echo " Require all granted" >> /etc/httpd/conf/vhosts.conf
echo "</Directory>" >> /etc/httpd/conf/vhosts.conf
echo "" >> /etc/httpd/conf/vhosts.conf
echo "<VirtualHost *:80>" >> /etc/httpd/conf/vhosts.conf
echo " ServerAdmin root@$SERVER_NAME" >> /etc/httpd/conf/vhosts.conf
echo " ServerName $SERVER_NAME" >> /etc/httpd/conf/vhosts.conf
echo " DocumentRoot /var/www/$SERVER_NAME/" >> /etc/httpd/conf/vhosts.conf
echo " CustomLog /var/log/httpd/$SERVER_NAME.com.log combined" >> /etc/httpd/conf/vhosts.conf
echo " ErrorLog /var/log/httpd/$SERVER_NAME.com_error_log" >> /etc/httpd/conf/vhosts.conf
echo "</VirtualHost>" >> /etc/httpd/conf/vhosts.conf
# Add the virtualhost file to the httpd.conf
echo 'Include /etc/httpd/conf/vhosts.conf' >> /etc/httpd/conf/httpd.conf
###################################
## INSTALL MYSQL FROM MySQL REPO ##
###################################
echo "installing mysql"
yum clean all
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
yum -y install mysql-server
systemctl enable mysqld
systemctl start mysqld
####################
## DATABASE SETUP ##
####################
# Create a basic database with a user and password. Only basic permissions
# are granted that would be useful for most applications. See the documentation
# http://dev.mysql.com/doc/refman/5.7/en/grant.html for all of the available grants
# use of mysql -Bse described here: http://stackoverflow.com/questions/7159727/delete-mysql-table-data-bash-script
echo "configuring database, user and permissions"
mysql -Bse "create database if not exists ${DATABASE_NAME};"
mysql -Bse "create user ${DATABASE_USER}@'%' identified by '${DATABASE_PASSWORD}';"
mysql -Bse "grant SELECT, INSERT, DELETE, UPDATE, CREATE TEMPORARY TABLES, EXECUTE on ${DATABASE_NAME}.* to ${DATABASE_USER}@'localhost' identified by '${DATABASE_PASSWORD}';"
###############################
## MySQL SECURE INSTALLATION ##
###############################
#Automatic mysql_secure_installation
#https://gist.github.com/enoch85/9cf2389df2b14569f063
echo "installing expect library"
yum -y install expect
SECURE_MYSQL=$(expect -c "
set timeout 10
spawn mysql_secure_installation
expect \"Enter current password for root:\"
send \"$MYSQL\r\"
expect \"Would you like to setup VALIDATE PASSWORD plugin?\"
send \"n\r\"
expect \"Change the password for root ?\"
send \"n\r\"
expect \"Remove anonymous users?\"
send \"y\r\"
expect \"Disallow root login remotely?\"
send \"y\r\"
expect \"Remove test database and access to it?\"
send \"y\r\"
expect \"Reload privilege tables now?\"
send \"y\r\"
expect eof
")
echo "running mysql secure installation"
echo "$SECURE_MYSQL"
###################
## Reboot Apache ##
###################
apachectl restart
Posted on Utopian.io - Rewarding Open Source Contributors










Hey @blervin I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
OMG! This is SUCH an AMAZING post! Thank you for sharing! I gave you a vote!!
Thanks for the upvote, I hope this script helps!
Great post. I think a ton of people will find it helpful that you posted the script for them.
I hope everyone finds this helpful, thanks for the resteem!
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]