Install WordPress Locally – The Easy-way
July 16, 2020 | DEV-OPS, Linux Administration, Shell Scripting | No Comments

1. Introduction
This is a very short post which guides you how to install WordPress on Oracle Virtual box using a automated script.
2. Setup the environment
We will use virtual box as out hypervisor where our WordPress virtual machine is going to hosted.
Download Virtual Box: https://www.virtualbox.org/wiki/Downloads
We will use vagrant to manage and build virtual machines on the hypervisor.
Download Vagrant: https://www.vagrantup.com/downloads
Installation scripts can be found as a git repository. We shall install git to clone this repository.
Git for widows: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
Git for MacOS: https://sourceforge.net/projects/git-osx-installer/files/
A complete guide [optional] to install git: https://www.atlassian.com/git/tutorials/install-git
3. Clone the git Repository
At this point it has been assumed that Oracle virtual box, Vagrant and git applications are installed in your local machine.
git clone https://github.com/krishanthisera/WP-EZY.git
In this case you may use the terminal(on Linux, OSX) or CMD(for windows).
4. Bootstrap the Server
CD in to the cloned directory (WP-EZY).
cd WP-EZY
Bootstrap the server.
vagrant up
Now you may wait until the bootstrapping process complete it may take some time depending on your internet connection.
5. Verify the installation
URL: http://192.168.5.50/blog/wp-admin/
User Name: admin
Password: password
–Enjoy–

6. Note
You may change the configuration using install.sh file. For an example,
- MySQL configuration
- IP Configuration
- Apache2 Configuration
If you are OSX user, you might encounter an error when you ought to install VirtualBox.
-> Go to your system preference

- -> Unlock to make the changes

- -> Allow VIrtual Box as a system app

Install.sh
#Install dependencies
sudo apt-get
DB_ROOT_PASS=root-pass
DB_WP_PASS=wp-pass
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password ${DB_PASS}'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password ${DB_PASS}'
sudo apt-get update -y
sudo apt-get install -y wordpress php libapache2-mod-php mysql-server php-mysql apache2 mysql-client ufw
sudo service mysql start
mkdir -p /etc/apache2/sites-available
#Configure mysql
mysql -u "root" -p'$DB_ROOT_PASS' -e "CREATE DATABASE wordpress;"
mysql -u "root" -p'$DB_ROOT_PASS' -e "GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON wordpress.* TO wordpress@localhost IDENTIFIED BY '${DB_WP_PASS}';"
mysql -u "root" -p'$DB_ROOT_PASS' -e "FLUSH PRIVILEGES;"
#Configure Apache2 server
cat <<EOF | sudo tee /etc/apache2/sites-available/wordpress.conf
Alias /blog /usr/share/wordpress
<Directory /usr/share/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Order allow,deny
Allow from all
</Directory>
<Directory /usr/share/wordpress/wp-content>
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
EOF
mkdir -p /etc/wordpress
cat <<EOF | sudo tee /etc/wordpress/config-localhost.php
<?php
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpress');
define('DB_PASSWORD', '${DB_WP_PASS}');
define('DB_HOST', 'localhost');
define('DB_COLLATE', 'utf8_general_ci');
define('WP_CONTENT_DIR', '/usr/share/wordpress/wp-content');
?>
EOF
sudo service mysql start
sudo a2ensite wordpress
sudo a2enmod rewrite
sudo service apache2 reload
Thank you 🙂