Setup WordPress LAMP , Ubuntu 22.04

Step1 , Install Apache

sudo apt install apache2 -y

Step 2 , Install Mysql

sudo apt install mysql-server -y

sudo mysql_secure_installation

Step 3 :- Create Virtual Host for your website

Use the Below Command to Create the directory , this is where you must keep the WordPress files :-

sudo mkdir /var/www/<your website directory>

Using Below Create the HTTP Virtual Host in Apache Sites :-

sudo nano /etc/apache2/sites-available/Domain_Name.conf
<VirtualHost *:80>
    ServerName Domain_Name
    ServerAlias www.Domain_Name
    ServerAdmin webmaster@Domain_Name
    DocumentRoot /var/www/<your website directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory /var/www/<your website directory>>
        AllowOverride All
    </Directory>
</VirtualHost>

Use Below to Enable the New Created Site :-

sudo a2ensite Domain_Name

For Changes to Reflect use below :-

sudo systemctl reload apache2

Your Site shoud be UP now

Install WordPress

Create a Database in Mysql :- (sudo mysql)

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;CREATE USER 'wordpressuser'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT ALL ON wordpress.* TO 'wordpressuser'@'%';
FLUSH PRIVILEGES;
EXIT;

WordPress Requires More PHP Extensions , Dowload them using below :-

sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip

Restart Apache to apply new plugins :- sudo systemctl restart apache2

Enable the Rewrite Module to be able to use permalinks in wordpress :- sudo a2enmod rewrite

Make sure to restart now even if you have restarted earlier in this tutorial: sudo systemctl restart apache2

After moving all the correct WordPresss Files to the Website Direcotry , run below Commands to fix permissions:-

sudo chown -R www-data:www-data /var/www/<your website directory>
sudo find /var/www/<your website directory>/ -type d -exec chmod 750 {} \;
sudo find /var/www/<your website directory>/ -type f -exec chmod 640 {} \;

Once All is done Proceed to Wp-config file and setup your database credentials

The End

References :-

Leave a Comment

Your email address will not be published. Required fields are marked *