Install WordPress on Ubuntu 22.04 with Nginx and MariaDB

You are currently viewing Install  WordPress on Ubuntu 22.04 with Nginx and MariaDB

Welcome to our comprehensive guide on setting up install WordPress on Ubuntu 22.04 with Nginx and MariaDB. This powerful combination of software provides a robust platform for your website, ensuring speed, security, and scalability. Whether you’re a seasoned webmaster or taking your first steps into web hosting, this tutorial will walk you through the process step-by-step. By the end of this guide, you’ll have a fully functional WordPress website ready to welcome visitors from around the globe

Prerequisites

Before you begin, ensure you have:

  • A server running Ubuntu 22.04.
  • Root user privileges or a user with sudo access.
  • A domain name pointed to your server’s IP address. i will create a topic to explain how to do that via cloudflare

Step 1: Update System Packages

sudo apt update && sudo apt upgrade -y

Step 2: Install Nginx, MariaDB, and PHP

Install Nginx:

sudo apt install nginx -y

Install MariaDB:

sudo apt install mariadb-server -y

Secure MariaDB:

sudo mysql_secure_installation

Install PHP and extensions:

sudo apt install php-fpm php-mysql php-xml php-xmlrpc php-gd php-opcache php-mbstring -y

Step 3: Configure Nginx and PHP

Edit the PHP configuration file to increase limits and execution time as needed for WordPress.

you can add this step for more secure your web site

  1. Locate Your PHP Configuration File (php.ini) The php.ini file is the default configuration file for running applications that require PHP. It is used to control variables such as upload sizes, file timeouts, and resource limits.
  2. Access Your php.ini File You can access this file by connecting to your server via SSH or FTP. The location of your php.ini file can vary depending on your hosting provider. Common paths include /etc/php/8.1/fpm/php.ini or /etc/php/8.1/cli/php.ini.
  3. Edit the php.ini File Open the php.ini file with a text editor. Look for the following lines and edit them as needed for your WordPress site:
    • upload_max_filesize = 64M
    • post_max_size = 64M
    • max_execution_time = 300

Step 4: Create a Database and User for WordPress

Access the MariaDB shell:

sudo mariadb

Create a new database and user, and grant privileges:

SQL

CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;

or if you have a website you can tax it directly on if needed you can contact me

Step 5: Install WordPress

Download the latest WordPress and extract it to your web directory:

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
sudo cp -a /tmp/wordpress/. /var/www/html/yourdomain

Set the correct permissions:

sudo chown -R www-data:www-data /var/www/html/yourdomain

Step 6: Configure WordPress

Rename and edit the WordPress configuration file:

mv /var/www/html/yourdomain/wp-config-sample.php /var/www/html/yourdomain/wp-config.php
nano /var/www/html/yourdomain/wp-config.php

Update the database details in the wp-config.php file.

Step 7: Configure Nginx Server Block

Create a new server block for your WordPress site:

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    root /var/www/html/yourdomain;
    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/php8.1-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

if you need to use https please try to update this config i give you the example of my web site don’t compy and past this


# this is a file of my web site web.estoreab.com visite here
server {
    listen 80;
    listen [::]:80;
    server_name  web.estoreab.com; #  change here put your domaine name 

    # Redirection HTTP vers HTTPS
    return 301 https://$server_name$request_uri;
}


server {
listen 443 ssl;
listen [::]:443;
root /var/www/sites;  #  change here
index index.php index.html index.htm;
server_name web.estoreab.com;  #  change here
# Path to your SSL certificate and private key
ssl_certificate /etc/ssl/certs/estoreab.com.pem; #  change here
ssl_certificate_key /etc/ssl/private/estoreab.com.key; #  change here

     # Additional SSL Configurations
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256';

access_log /var/log/nginx/web.estoreab.com-access.log; #  change here
error_log /var/log/nginx/web.estoreab.com-error.log; #  change here

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

location = /favicon.ico {
    log_not_found off;
    access_log off;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires max;
    log_not_found off;
}

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

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

}

Enable the new site configuration and restart Nginx:

sudo ln -s /etc/nginx/sites-available/yourdomain /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Step 8: Complete the WordPress Installation

Visit your domain to complete the WordPress installation through the web interface.

thank you for visite guide of Install WordPress on Ubuntu 22.04 with Nginx and MariaDB

In conclusion, setting up install WordPress on Ubuntu 22.04 with Nginx and MariaDB might seem daunting at first, but with the right guidance, it’s a straightforward process. We’ve covered everything from server preparation to the final WordPress installation steps. By following this guide, you’ve laid the foundation for a website that’s not only fast and reliable but also secure. Now, it’s time to unleash your creativity and start crafting content that resonates with your audience

Install WordPress on Ubuntu 22.04 with Nginx and MariaDB

This Post Has 3 Comments

Comments are closed.