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 yoursite DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Create user with strong password:

CREATE USER 'yourusername'@'%' IDENTIFIED WITH mysql_native_password BY 'yourusername_mysql_password';

Grant permissions to user:

GRANT ALL ON yoursite.* TO 'yourusername'@'%';

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/yoursite.com

Assign ownership:

sudo chown -R $USER:$USER /var/www/yoursite.com

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

sudo nano /etc/apache2/sites-available/yoursite.com.conf

Paste in the following configuration:

<VirtualHost *:80>
    ServerName yoursite.com
    ServerAlias www.yoursite.com 
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/yoursite.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Change owner (chown) recursively (-R):

sudo chown -R www-data:www-data /var/www/yoursite.com

Change user (usermod), append (-a), group (-G):

sudo usermod -a -G www-data yourusername

Change group ownership (chgrp) recursively (-R):

sudo chgrp -R www-data /var/www/yoursite.com

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

sudo chmod -R g+w /var/www/yoursite.com

Change owner www:date to yourusername:

sudo chown -R yourusername /var/www/yoursite.com/wp-content/themes

Change permission for directory:

sudo find /var/www/yoursite.com/ -type d -exec chmod 755 {} \;

Change permission for files:

sudo find /var/www/yoursite.com/ -type f -exec chmod 644 {} \;

Edit WordPress config file:

sudo nano /var/www/yoursite.com/wp-config.php