How to Set Up a LAMP Stack for WordPress

Follow “How To Install WordPress on Ubuntu 20.04 with a LAMP Stack.”

Log into MySQL:
sudo mysql -u root

Update the root user’s password (replace new_password with a strong password):
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';

Create database:
CREATE DATABASE visualguiblog DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Create user with strong password:
CREATE USER 'donnytruong'@'%' IDENTIFIED WITH mysql_native_password BY 'donnytruong_mysql_password';

Grant permissions to user:
GRANT ALL ON visualguiblog.* TO 'donnytruong'@'%';

Creating a Virtual Host for your Website

Follow “How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 20.04.” Continue with step 4 to create a virtual host.

Create the directory for your_domain:
sudo mkdir /var/www/

Assign ownership:
sudo chown -R $USER:$USER /var/www/

Open a new configuration file in Apache’s sites-available directory using nano (command-line editor):
sudo nano /etc/apache2/sites-available/

Paste in the following configuration:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Change owner (chown) recursively (-R):
sudo chown -R www-data:www-data /var/www/

Change user (usermod), append (-a), group (-G):
sudo usermod -a -G www-data donnytruong

Change group ownership (chgrp) recursively (-R):
sudo chgrp -R www-data /var/www/

Change permissions with chmod command recursively (-R) with write permission for group (g+w)
sudo chmod -R g+w /var/www/

Change owner www:date to donnytruong:
sudo chown -R donnytruong /var/www/

Change permission for directory:
sudo find /var/www/ -type d -exec chmod 755 {} \;

Change permission for files:
sudo find /var/www/ -type f -exec chmod 644 {} \;

Edit WordPress config file:
sudo nano /var/www/