Running a website on Linux starts with setting up WordPress, which requires a web server and database. This guide covers exactly how to install WordPress on Linux step by step, from server prep to final configuration. You don’t need to be a Linux expert—just follow these clear instructions.
WordPress powers over 40% of all websites, and Linux is its natural home. Installing it manually gives you full control and better performance than shared hosting. Let’s get your site live quickly.
Prerequisites For Installing WordPress On Linux
Before you start, make sure your Linux server meets these requirements. You’ll need root or sudo access to complete the installation.
Server Requirements
- A Linux distribution (Ubuntu 20.04/22.04, Debian 11/12, CentOS 7/8, or Rocky Linux)
- Apache or Nginx web server
- MySQL or MariaDB database server
- PHP 7.4 or higher (PHP 8.0+ recommended)
- At least 1 GB RAM (2 GB+ for production sites)
- A domain name pointed to your server IP
Basic Linux Skills Needed
- Using the terminal via SSH
- Running commands with sudo
- Editing text files with nano or vim
- Basic file permission knowledge
If you’re using a cloud provider like AWS, DigitalOcean, or Linode, you already have a fresh Linux server. This guide assumes you have SSH access and a non-root user with sudo privileges.
How To Install WordPress On Linux
Now we get to the core of this guide. Follow these steps exactly to install WordPress on your Linux server. The process takes about 20 minutes if everything goes smoothly.
Step 1: Update Your System
Always start with a clean, updated system. Run these commands:
sudo apt update(for Debian/Ubuntu) orsudo yum update(for CentOS/RHEL)sudo apt upgrade -yorsudo yum upgrade -y
This ensures all packages are current and reduces security risks.
Step 2: Install A Web Server (Apache Or Nginx)
Choose one web server. Apache is easier for beginners; Nginx offers better performance under high traffic.
Install Apache
sudo apt install apache2 -ysudo systemctl start apache2sudo systemctl enable apache2- Check status:
sudo systemctl status apache2
Install Nginx
sudo apt install nginx -ysudo systemctl start nginxsudo systemctl enable nginx- Test with:
sudo systemctl status nginx
Step 3: Install MySQL Or MariaDB
WordPress needs a database. MariaDB is a drop-in replacement for MySQL and often faster.
sudo apt install mariadb-server mariadb-client -ysudo systemctl start mariadbsudo systemctl enable mariadb- Secure the installation:
sudo mysql_secure_installation
During the security script, set a root password, remove anonymous users, disallow root login remotely, and remove test databases. Answer “Y” to all prompts.
Step 4: Install PHP And Required Extensions
WordPress requires PHP with several extensions. Install them all at once:
sudo apt install php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip -y- Restart your web server:
sudo systemctl restart apache2orsudo systemctl restart nginx
Verify PHP version: php -v. If below 7.4, add a newer PHP repository.
Step 5: Create A Database For WordPress
Log into MySQL/MariaDB and create a database and user:
sudo mysql -u root -p(enter your root password)- Run these SQL commands one by one:
CREATE DATABASE wordpress_db;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'strong_password_here';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace ‘strong_password_here’ with a secure password. Write it down—you’ll need it soon.
Step 6: Download WordPress
Navigate to your web root directory and download the latest WordPress package:
cd /var/www/html(Apache) orcd /var/www(Nginx)sudo wget https://wordpress.org/latest.tar.gzsudo tar -xzvf latest.tar.gz- This creates a
wordpressfolder with all files.
Step 7: Configure File Permissions
WordPress needs proper ownership and permissions to write files:
sudo chown -R www-data:www-data /var/www/html/wordpress(Apache) orsudo chown -R www-data:www-data /var/www/wordpress(Nginx)sudo chmod -R 755 /var/www/html/wordpress
The user “www-data” is the web server user on Debian/Ubuntu. On CentOS, use “apache” instead.
Step 8: Configure WordPress
Copy the sample config file and edit it:
cd /var/www/html/wordpresssudo cp wp-config-sample.php wp-config.phpsudo nano wp-config.php
Find these lines and update them with your database details:
define('DB_NAME', 'wordpress_db');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'strong_password_here');
define('DB_HOST', 'localhost');
Save and exit (Ctrl+X, then Y, then Enter in nano).
Step 9: Set Up Your Web Server Virtual Host (Nginx Example)
If using Apache, skip this step—the default configuration works. For Nginx, create a server block:
sudo nano /etc/nginx/sites-available/wordpress- Add this configuration (adjust server_name to your domain):
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/wordpress;
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;
}
}
- Enable the site:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/ - Test configuration:
sudo nginx -t - Reload Nginx:
sudo systemctl reload nginx
Step 10: Complete Installation Via Web Browser
Open your browser and go to http://yourdomain.com or your server’s IP address. You’ll see the WordPress setup wizard:
- Select your language
- Enter your Site Title, Username, Password, and Email
- Click “Install WordPress”
- Log in with your new credentials
That’s it! Your WordPress site is now live on Linux.
Post-Installation Security Tips
After installation, secure your site with these essential steps:
- Change the default “admin” username if you used it
- Install an SSL certificate using Let’s Encrypt (Certbot)
- Set strong file permissions:
chmod 644 wp-config.php - Disable file editing in WordPress by adding to wp-config.php:
define('DISALLOW_FILE_EDIT', true); - Install a security plugin like Wordfence or Sucuri
- Regularly update WordPress core, themes, and plugins
Troubleshooting Common Issues
Even with careful steps, problems can arise. Here are fixes for frequent issues:
White Screen Of Death
This usually means a PHP error. Enable debugging in wp-config.php:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
Check the wp-content/debug.log file for errors.
Database Connection Error
Verify your database credentials in wp-config.php. Ensure MySQL/MariaDB is running: sudo systemctl status mariadb.
404 Errors On Pages
For Nginx, ensure your server block includes the try_files line shown above. For Apache, enable mod_rewrite: sudo a2enmod rewrite and restart Apache.
File Upload Issues
Check folder permissions: sudo chmod -R 755 wp-content/uploads. Also verify PHP upload settings in php.ini.
Automating With Scripts (Optional)
If you install WordPress frequently, consider automation. A simple bash script can handle steps 2 through 8. Here’s a basic example:
#!/bin/bash
apt update && apt upgrade -y
apt install apache2 mariadb-server php php-mysql -y
systemctl start apache2 mariadb
mysql -u root -e "CREATE DATABASE wp_db; CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'pass'; GRANT ALL ON wp_db.* TO 'wp_user'@'localhost';"
cd /var/www/html && wget https://wordpress.org/latest.tar.gz && tar -xzvf latest.tar.gz
chown -R www-data:www-data wordpress
echo "WordPress files ready. Complete setup via browser."
Save as install-wp.sh, make executable with chmod +x install-wp.sh, and run with sudo.
Frequently Asked Questions
Can I Install WordPress On Linux Without A Domain?
Yes, use your server’s IP address in the browser. However, you’ll need a domain for email and SSL certificates.
What’s The Difference Between Installing WordPress On Ubuntu Vs CentOS?
Package managers differ (apt vs yum), but the steps are nearly identical. Ubuntu is more beginner-friendly due to larger community support.
Do I Need A Control Panel Like CPanel Or Plesk?
No, this guide shows manual installation without a control panel. Many developers prefer this for better performance and control.
How Long Does It Take To Install WordPress On Linux?
Around 15-30 minutes for a first-time installation. Experienced users can do it in under 10 minutes.
Is It Safe To Install WordPress On A VPS?
Yes, but you must maintain security updates yourself. Consider using a managed WordPress host if you prefer hands-off maintenance.
Conclusion
You now know how to install WordPress on Linux from scratch. The process involves setting up a LAMP or LEMP stack, downloading WordPress, configuring the database, and running the web installer. With practice, you can complete this in under 20 minutes.
Remember to keep your server updated and backup your site regularly. WordPress on Linux offers unmatched flexibility and performance for your website. If you encounter issues, refer back to the troubleshooting section or consult the WordPress Codex.
Now go ahead and build something amazing with your new WordPress site on Linux.