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:
- Linux Server Access: SSH access to your Linux server (e.g., Ubuntu, CentOS).
- Domain Name: A registered domain name pointing to your servers.
- Server Requirements: A LAMP or LEMP stack is installed on your server.
- 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):
- Install Apache:
sudo apt install apache2 -y
- Install PHP:
sudo apt install php libapache2-mod-php php-mysql -y
- Install MySQL:
sudo apt install mysql-server -y
For Nginx (LEMP Stack):
- Install Nginx:
sudo apt install nginx -y
- Install PHP:
sudo apt install php-fpm php-mysql -y
- Install MySQL:
sudo apt install mysql-server -y
Step-3: Configure MySQL Database
- Log in to the MySQL shell:
sudo mysql
- Create a new database:
CREATE DATABASE wordpress;
- 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
- Navigate to the web root directory:
cd /var/www/html
- Download WordPress:
sudo wget https://wordpress.org/latest.tar.gz
- Extract the downloaded file:
sudo tar -xvzf latest.tar.gz
- Move WordPress files to the web root:
sudo mv wordpress/* . sudo rm -r wordpress latest.tar.gz
Step-5: Configure WordPress
- Copy the sample configuration file:
sudo cp wp-config-sample.php wp-config.php
- Edit the configuration file:
sudo nano wp-config.php
- Update the database settings:
define('DB_NAME', 'wordpress'); define('DB_USER', 'wpuser'); define('DB_PASSWORD', 'password'); define('DB_HOST', 'localhost'); - Save and exit (CTRL+O, ENTER, CTRL+X).
Step-6: Set Permissions
- Set correct ownership:
sudo chown -R www-data:www-data /var/www/html
- 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:
- Enable the rewrite module:
sudo a2enmod rewrite
- Restart Apache:
sudo systemctl restart apache2
For Nginx:
- Create a new server block file:
sudo nano /etc/nginx/sites-available/wordpress
- 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; } } - 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
- Open your browser and navigate to your domain or server IP (e.g., http://your_domain.com).
- Follow the WordPress installation wizard:
- Select your language.
- Enter site details like the site title, username, and password.
- Click “Install WordPress.”
Troubleshooting Tips
- Database Connection Error: Double-check wp-config.php for correct database credentials.
- Permission Denied Errors: Ensure ownership and permissions are correctly set.
- 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.



