How to Install WordPress on Ubuntu

πŸš€ How to Install WordPress on Ubuntu 24.04 LTS with Nginx and PHP-FPM (Step-by-Step)

In this detailed guide, you will learn how to install WordPress on Ubuntu 24.04 LTS with the Nginx web server and PHP-FPM processor. Every command is explained clearly to ensure you can follow even if you’re a beginner!


πŸ”Ή Step 1: Update and Upgrade Your Ubuntu System

First, always make sure your server is updated to the latest packages and security patches.

sudo apt update
sudo apt upgrade -y

πŸ”Ή Step 2: Install Nginx Web Server 🌐

Nginx will serve your WordPress site to visitors.

sudo apt install nginx -y

Start and enable the Nginx service:

sudo systemctl start nginx
sudo systemctl enable nginx

πŸ”Ή Step 3: Install PHP-FPM and Essential PHP Extensions 🐘

WordPress is built in PHP, so we need PHP-FPM and some required extensions for proper functionality.

sudo apt install php-fpm php-mysql php-curl php-xml php-gd php-mbstring php-zip php-bcmath -y

βœ… PHP-FPM will handle PHP processing efficiently with Nginx.


πŸ”Ή Step 4: Install MariaDB Server πŸ—„οΈ

MariaDB is the database engine where WordPress will store all your posts, pages, and user information.

sudo apt install mariadb-server mariadb-client -y

Then, secure your database:

sudo mysql_secure_installation

Follow the prompts to set a root password, remove anonymous users, disallow remote root login, and remove test databases.


πŸ”Ή Step 5: Create a WordPress Database and User πŸ“‚

Now, we create a separate database and user for WordPress.

sudo mysql -u root -p

Inside the MariaDB shell, execute:

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

βœ… Replace your_strong_password with a very strong password!


πŸ”Ή Step 6: Download and Set Up WordPress πŸ“

Move into the web root directory and download WordPress.

cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz

Extract the archive and clean up:

sudo tar -xvzf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz

Set correct ownership and permissions:

sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

βœ… This ensures Nginx can access WordPress files properly.


πŸ”Ή Step 7: Configure wp-config.php βš™οΈ

Copy the sample configuration file:

cp wp-config-sample.php wp-config.php

Open it for editing:

sudo nano wp-config.php

Find and set your database configuration:

define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wordpressuser' );
define( 'DB_PASSWORD', 'your_strong_password' );
define( 'DB_HOST', 'localhost' );

πŸ” Adding WordPress Security Salts

Visit this WordPress Salt Generator and copy the generated lines.

Replace these lines in wp-config.php:

define('AUTH_KEY',         'your unique phrase');
define('SECURE_AUTH_KEY',  'your unique phrase');
define('LOGGED_IN_KEY',    'your unique phrase');
define('NONCE_KEY',        'your unique phrase');
define('AUTH_SALT',        'your unique phrase');
define('SECURE_AUTH_SALT', 'your unique phrase');
define('LOGGED_IN_SALT',   'your unique phrase');
define('NONCE_SALT',       'your unique phrase');

βœ… Salts help protect your site against hacking attempts.


πŸ”Ή Step 8: Configure Nginx for WordPress πŸ›‘οΈ

Create a new Nginx server block:

sudo nano /etc/nginx/sites-available/wordpress

Add the following configuration:

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

    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:/run/php/php8.2-fpm.sock;
    }

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

Enable the configuration and reload Nginx:

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

βœ… Remember to replace yourdomain.com with your actual domain name!


πŸ”Ή Step 9: Complete WordPress Setup in Browser 🌍

Open your web browser and visit:

http://yourdomain.com

Fill out the installation form β€” Site Title, Admin Username, Password, and Email β€” and click Install WordPress.


πŸŽ‰ Success! WordPress Installed on Ubuntu 24.04! πŸŽ‰

Congratulations! You now have a fully working WordPress website, backed by a powerful Nginx server and secured with PHP-FPM and proper database configurations.

➑️ Next steps: Configure SSL (HTTPS), install themes and plugins, and start publishing your amazing content!

Please follow and like us:
error0
fb-share-icon20
Tweet 20
fb-share-icon20

Comments

Leave a Reply

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