🎉 Hello guys I'm back again and in this guide, we’re spinning up a full WordPress server using Vagrant on an Ubuntu box powered by the mighty LAMP stack (Linux, Apache, MySQL, PHP). Whether you're just getting started or practicing your automation skills, this walk-through is designed to be as fun as it is functional.
🧰 Prerequisites
Before you begin make sure you’ve got the following installed:
- ✅ Vagrant
- ✅ VirtualBox
- Basic knowledge of Linux terminal (GIT)
🔧 Step 1: Spin Up Your Vagrant Box
Open your terminal, let’s create a new project folder and initialize our Ubuntu environment:
mkdir wordpress
cd wordpress
vagrant init ubuntu/focal64
Now at this point a vagrant file has been created, lets tweak your Vagrantfile
. First run vim Vagrantfile
and edit your script like so:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.network "private_network", ip: "192.168.56.18"
config.vm.network "public_network"
config.vm.boot_timeout = 300
#300 seconds =5mins
#Set RAM to 2gb to the VM
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
Summary
Base Image: Ubuntu 20.04 LTS (ubuntu/focal64)
Networking:
Private network with static IP 192.168.56.18 (host-only access)
Public network (bridged mode for LAN access)
Boot Timeout: 5 minutes (300 seconds) to allow for slower VM startups
Next let's bring up the VM and ssh into it. On your terminal run:
Vagrant up && ssh
All set? Let’s automate the rest! 💻
🧪 Step 2: Installing LAMP Dependencies
Now switcht to root user sudo -i
and run the following commands to update packages and install everything WordPress needs:
# Update packages
sudo apt update
# Install Apache, MySQL, PHP, and required modules
sudo apt install apache2 ghostscript libapache2-mod-php mysql-server php php-bcmath php-curl php-imagick php-intl php-json php-mbstring php-mysql php-xml php-zip -y
You just brought the entire LAMP stack to life.🔥
📦 Step 3: Download & Install WordPress
Now let’s grab the latest version of WordPress and put it in the right place:
sudo mkdir -p /srv/www
sudo chown www-data: /srv/www
curl http://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/www
We’re staging WordPress in /srv/www
so it’s ready for Apache to serve.
🌐 Step 4: Configure Apache for WordPress
Set up a virtual host for WordPress so it’s properly served from Apache. First open the Apache conf file in vim.
vim /etc/apache2/sites-available/wordpress.conf
Then paste the following content
<VirtualHost *:80>
DocumentRoot /srv/www/wordpress
<Directory /srv/www/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /srv/www/wordpress/wp-content>
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
Save and close the file: Esc
:wq
Next enable the site and modules, and reload Apache:
# Enable the new site and modules
sudo a2ensite wordpress
sudo a2enmod rewrite
sudo a2dissite 000-default
# Apply changes
sudo systemctl reload apache2
And yeah, Apache is ready with WordPress! 🌐
🛢️ Step 5: Configure MySQL
Let’s set up the database and user that WordPress will use:
Connect to MySQL:
sudo mysql -u root
Run these commands to create a database and user for WordPress (replace admin123 with your own password):
mysql -u root -e 'CREATE DATABASE wordpress;'
mysql -u root -e 'CREATE USER wordpress@localhost IDENTIFIED BY "admin123";'
mysql -u root -e 'GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON wordpress.* TO wordpress@localhost;'
mysql -u root -e 'FLUSH PRIVILEGES;'
Exit MySQL quit;
You’ve just given WordPress its own playground in MySQL. 🎯
🧩 Step 6: Connect WordPress to the Database
Now, let’s wire up the wp-config.php
:
sudo -u www-data cp /srv/www/wordpress/wp-config-sample.php /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/database_name_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/username_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/password_here/admin123/' /srv/www/wordpress/wp-config.php
🔐 Important: Replace the secret keys with real, secure ones from this link:
WordPress Secret Keys
Paste them into wp-config.php
to boost your site's security. 🛡️
sudo -u www-data vim /srv/www/wordpress/wp-config.php
Ensure to save and close.
🎨 Step 7: Final WordPress Setup (via Browser)
To set up on the browser we need to get the Ip Address by running
ip addr show
-
We will be using the public Ip to access it on the web. Complete the WordPress installer:
- Choose a site title
- Create an admin username and password
- Enter your email
- And click Install! 🎉
✅ That’s a Wrap!
You’ve successfully automated the deployment of a full LAMP-based WordPress site using Vagrant! 🙌
🛠️ Skills Gained
VM Provisioning with Vagrant: Learned how to spin up and configure a reproducible Ubuntu virtual machine using Vagrant and VirtualBox.
- LAMP Stack Setup: Installed Apache, MySQL, and PHP to run web apps.
- WordPress Deployment: Set up WordPress manually on a local server.
- Apache Virtual Hosts: Configured Apache to point to the correct website folder.
- MySQL Setup: Created a secure database and user for WordPress.
- Security: Secured WordPress with unique keys in the config file.
- Local Environment: Learned how to build and manage local dev setups.
so yeah keep experimenting, break things, and build again - that’s the DevOps way 💥
Top comments (1)
I didn’t know setting up WordPress with Vagrant and Apache could be this clean. Picked up a few tricks here, nice work👌🏽.”
Some comments may only be visible to logged-in visitors. Sign in to view all comments.