How to Install WordPress on a Linux Server

How to Install WordPress on a Linux Server? Step-by-Step Guide

To install WordPress on a Linux server, you first need a working LAMP (Linux, Apache, MySQL/MariaDB, PHP) or LEMP (Linux, Nginx, MySQL/MariaDB, PHP) stack. Once your server environment is ready, download the latest WordPress package from the official website, extract it into your web server’s root directory, and create a MySQL database and user for WordPress. Next, configure the wp-config.php file with your database details, set proper file permissions, and complete the installation by visiting your server’s domain or IP in a browser, where you can finalize setup with your site title, username, and password.

Prerequisites

Before you begin, ensure the following:

  1. Linux Server Access: SSH access to your Linux server (e.g., Ubuntu, CentOS).
  2. Domain Name: A registered domain name pointing to your servers.
  3. Server Requirements: A LAMP or LEMP stack is installed on your server.
  4. SSH Client: Use an SSH client like PuTTY or the terminal on Linux/Mac.

Step-by-Step Guide How to Install WordPress on a Linux Server

Step-1: Update the System

Let’s update your server to ensure all packages are current:

sudo apt update && sudo apt upgrade -y

This command updates the package lists and upgrades any outdated software.

Step-2: Install the LAMP/LEMP Stack

For Apache (LAMP Stack):

  1. Install Apache:
    sudo apt install apache2 -y
  2. Install PHP:
    sudo apt install php libapache2-mod-php php-mysql -y
  3. Install MySQL:
    sudo apt install mysql-server -y

For Nginx (LEMP Stack):

  1. Install Nginx:
    sudo apt install nginx -y
  2. Install PHP:
    sudo apt install php-fpm php-mysql -y
  3. Install MySQL:
    sudo apt install mysql-server -y

Step-3: Configure MySQL Database

  1. Log in to the MySQL shell:
    sudo mysql
  2. Create a new database:
    CREATE DATABASE wordpress;
  3. Create a new MySQL user and grant privileges:
    CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;

Replace ‘password’ with a strong password.

Step-4: Download WordPress

  1. Navigate to the web root directory:
    cd /var/www/html
  2. Download WordPress:
    sudo wget https://wordpress.org/latest.tar.gz
  3. Extract the downloaded file:
    sudo tar -xvzf latest.tar.gz
  4. Move WordPress files to the web root:
    sudo mv wordpress/* .
    
    sudo rm -r wordpress latest.tar.gz

Step-5: Configure WordPress

  1. Copy the sample configuration file:
    sudo cp wp-config-sample.php wp-config.php
  2. Edit the configuration file:
    sudo nano wp-config.php
  3. Update the database settings:
    define('DB_NAME', 'wordpress');
    define('DB_USER', 'wpuser');
    define('DB_PASSWORD', 'password');
    define('DB_HOST', 'localhost');
  4. Save and exit (CTRL+O, ENTER, CTRL+X).

Step-6: Set Permissions

  1. Set correct ownership:
    sudo chown -R www-data:www-data /var/www/html
  2. Set permissions:
    sudo find /var/www/html -type d -exec chmod 755 {} \;
    sudo find /var/www/html -type f -exec chmod 644 {} \;

Step-7: Configure Apache or Nginx

For Apache:

  1. Enable the rewrite module:
    sudo a2enmod rewrite
  2. Restart Apache:
    sudo systemctl restart apache2

For Nginx:

  1. Create a new server block file:
    sudo nano /etc/nginx/sites-available/wordpress
  2. Add the following configuration:
    server {
    listen 80;
    server_name your_domain.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:/var/run/php/php7.4-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    }
  3. Enable the configuration:
    sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
    sudo nginx -t
    sudo systemctl reload nginx

Step-8: Complete the Installation in the Browser

  1. Open your browser and navigate to your domain or server IP (e.g., http://your_domain.com).
  2. Follow the WordPress installation wizard:
    • Select your language.
    • Enter site details like the site title, username, and password.
    • Click “Install WordPress.”

Troubleshooting Tips

  1. Database Connection Error: Double-check wp-config.php for correct database credentials.
  2. Permission Denied Errors: Ensure ownership and permissions are correctly set.
  3. Blank Page or PHP Errors: Verify PHP version compatibility and error logs.

Conclusion

Congratulations! You have successfully installed/setup WordPress on your Linux server. From here, you can customize your site, install plugins, and create content to suit your needs. Continue updating WordPress, themes, & plugins to maintain security & performance.

Scroll to Top