How to develop WordPress site locally

Mar 31, 2020 1:44 am
by Alex


I like to build my own virtual machine for local developing my WordPress sites, using this way I can run the virtual machine under any operating system.
You can also try XAMPP or local by flywheel
but building my own VMs is more stable, you can follow the steps below to build your own web server to run WordPress locally.
I like to use Ubuntu Desktop for my base environment, you can use any linux distro of your choice (Just change the package manager command)

First thing first

Update your system

sudo apt-get update
sudo apt-get upgrade -y

Install tasksel

sudo apt install tasksel
sudo tasksel install lamp-server
sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc

Edit host file to use the domain name

sudo nano /etc/hosts

>ip.ip.ip.ip [] []

Edit Apache2 Virtual host file

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/[].conf
sudo nano /etc/apache2/sites-available/[].conf

.conf file example

<Directory /var/www/[]>
    Require all granted
<VirtualHost *:80>
    ServerName []
    ServerAlias www.[]
    ServerAdmin [email protected]
    DocumentRoot /var/www/[]

Make the directory

sudo mkdir -p /var/www/[]

Enable virtual host config

sudo a2dissite 000-default.conf
sudo a2ensite [].conf
sudo systemctl reload apache2

Create Database

sudo mysql -u root
mysql> CREATE DATABASE database;
mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'user_password';
mysql> GRANT ALL PRIVILEGES ON database.* TO 'newuser'@'localhost';
mysql> quit

Create new user with root privilege

mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'the_password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user_name'@'localhost' WITH GRANT OPTION;
mysql> CREATE USER 'username'@'%' IDENTIFIED BY 'the_password';
mysql> SHOW GRANTS FOR username;

sudo mysql_secure_installation
sudo apt-get update
sudo apt-get install -y phpmyadmin


Reset root user password

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Export mysql database

mysqldump --user=admin_backup --password --lock-tables --databases db1 > /data/backup/db1.sql

Restore database

mysql -u admin_backup -p db_name < backup-file.sql

Enable apache rewrite for wordpress permalinks

sudo nano /etc/apache2/apache2.conf

Options Indexes FollowSymLinks
AllowOverride None
Require all granted

AllowOverride None
AllowOverride All

sudo a2enmod rewrite
sudo systemctl reload apache2

Config Apache2 PHP

sudo nano /etc/php/7.2/apache2/php.ini

max_input_time = 120
upload_max_filesize = 128M
post_max_size = 128M

$ sudo systemctl reload apache2

Install WordPress

$ sudo wget

Unpack the gz

$ sudo tar -xvf latest.tar.gz

move all files to the site root

cd wordpress
sudo mv * ..

remove wordpress folder and gz file

sudo rm -R wordpress
sudo rm latest.tar.gz

Copy sample config file

sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php

Edit the database user and password then remove the sample file
go to
replace salt secret

Add Permission to folders

sudo chown -R www-data:www-data /var/www/[]/*
sudo chmod -R 775 /var/www/[]
sudo systemctl reload apache2


Insatll Theme
+ DIVI Theme –
Install Plugins
+ FakerPress – install fake contents
+ UpdraftPlus – backup and restore
+ WP Data Access


Ubuntu file manager – Nautilus

sudo nano ~/.bashrc

Add the following line to use open as nautilus

alias open='nautilus'

to reload bash profile

$ source ~/.bashrc
$ . ~/.bashrc