How to Install WordPress with LEMP On Ubuntu 20.04

How to Install WordPress with LEMP On Ubuntu

To install WordPress with LEMP (Linux, Nginx, MySQL, PHP) on Ubuntu 20.04, follow these steps:

Step 1: Update Package List

sudo apt update

Step 2: Install Nginx

sudo apt install nginx

Step 3: Install MySQL Server

sudo apt install mysql-server

During the installation, you’ll be prompted to set a password for the MySQL root user.

Step 4: Install PHP and Required Extensions

sudo apt install php-fpm php-mysql

Step 5: Configure PHP-FPM

Edit the PHP-FPM configuration file:

sudo nano /etc/php/7.4/fpm/php.ini

Find the line ;cgi.fix_pathinfo=1 and change it to:

cgi.fix_pathinfo=0

Save and close the file. Then, restart PHP-FPM:

sudo systemctl restart php7.4-fpm

Step 6: Configure Nginx for WordPress

Create a new Nginx server block configuration for your WordPress site:

sudo nano /etc/nginx/sites-available/yourdomain.com

Replace yourdomain.com with your actual domain name, and add the following configuration:

server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com;

index index.php index.html index.htm;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}

error_log /var/log/nginx/yourdomain.com_error.log;
access_log /var/log/nginx/yourdomain.com_access.log;
}

Create a symbolic link to enable the site:

sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/

Test the Nginx configuration:

sudo nginx -t

If the test is successful, restart Nginx:

sudo systemctl restart nginx

Step 7: Create MySQL Database and User for WordPress

Login to MySQL:

sudo mysql

Create a new database:

CREATE DATABASE wordpressdb;

Create a new user and grant privileges:

CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wordpressuser'@'localhost'; FLUSH PRIVILEGES; EXIT;

Replace 'your_password' with a strong password.

Step 8: Download and Configure WordPress

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz
sudo mv wordpress /var/www/yourdomain.com

Update ownership and permissions:

sudo chown -R www-data:www-data /var/www/yourdomain.com
sudo chmod -R 755 /var/www/yourdomain.com

Copy the default configuration file:

sudo cp /var/www/yourdomain.com/wp-config-sample.php /var/www/yourdomain.com/wp-config.php

Edit the WordPress configuration file:

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

Update the database connection details:

define('DB_NAME', 'wordpressdb');
define('DB_USER', 'wordpressuser');
define('DB_PASSWORD', 'your_password');

Replace 'your_password' with the password you set for the MySQL user.

Step 9: Complete WordPress Installation

Visit http://yourdomain.com in your web browser to complete the WordPress installation. Follow the on-screen instructions, and you’ll be prompted to provide the database information and set up the admin user.

Once the installation is complete, you can log in to the WordPress admin dashboard.

That’s it! You’ve successfully installed WordPress with LEMP on Ubuntu 20.04. Adjust the configurations based on your specific requirements.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.