Step by step how to setup Web server

Preface

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 [testing.com] [www.testing.com]

Edit Apache2 Virtual host file

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

.conf file example

<Directory /var/www/[testing.com]>
    Require all granted
</Directory>
<VirtualHost *:80>
    ServerName [testing.com]
    ServerAlias www.[testing.com]
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/[testing.com]
</VirtualHost>

Make the directory

sudo mkdir -p /var/www/[testing.com]

Enable virtual host config

sudo a2dissite 000-default.conf
sudo a2ensite [testing.com].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> GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;
mysql> SHOW GRANTS FOR username;
mysql> FLUSH PRIVILEGES;
sudo mysql_secure_installation
sudo apt-get update
sudo apt-get install -y phpmyadmin

http://localhost/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

Find
Options Indexes FollowSymLinks
AllowOverride None
Require all granted

Change
AllowOverride None
To
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 https://wordpress.org/latest.tar.gz

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 https://api.wordpress.org/secret-key/1.1/salt/
replace salt secret

Add Permission to folders


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

Finally

Insatll Theme
+ DIVI Theme – https://www.elegantthemes.com/affiliates/idevaffiliate.php?id=58138_1_1_5
Install Plugins
+ FakerPress – install fake contents
+ UpdraftPlus – backup and restore
+ WP Data Access

Notes

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
or
$ . ~/.bashrc

Log In

How to Use Docker + Webtop to Secure Your Online Activities