📝 Install WordPress on a Linux VPS

Complete guide to install WordPress on your Linux VPS with LAMP (Linux, Apache, MySQL, PHP) or LEMP (Linux, Nginx, MySQL, PHP). Complete and secure configuration.

📝 Install WordPress on a Linux VPS

This guide explains how to install WordPress on your Linux VPS. WordPress is the world's most popular content management system (CMS), used by millions of websites.

⚠️ Important Warning

Important : For WordPress sites, it is especially recommended to take web hosting with Infrawire. Shared or dedicated web hosting offers many advantages:

  • Optimal stability : Environment optimized and maintained for WordPress
  • Automatic backups : Your data is backed up regularly
  • Specialized support : Technical assistance dedicated to WordPress
  • Managed updates : Security and performance updates
  • Enhanced security : Protection against common attacks
  • Optimized performance : Server configuration adapted to WordPress

However, if you want a non-shared and dedicated environment with full control over your server, you can install WordPress on an Infrawire VPS. This guide explains how to proceed.

📋 Prerequisites

  • A Linux VPS with root or sudo access
  • At least 1 GB of RAM (2 GB recommended for WordPress)
  • At least 10 GB of free disk space
  • A domain name pointing to your VPS IP
  • Ports 80 (HTTP) and 443 (HTTPS) open in your firewall

💡 Infrastructure Recommendation

For optimal WordPress performance, we recommend our NVMe VPS for moderate traffic sites, or our Performance VPS for high-traffic sites requiring significant CPU resources. NVMe drives significantly accelerate page loading and database operations.

🔧 Method 1: Installation with LAMP (Apache)

Step 1: Update the system

# Update package list sudo apt update # Update installed packages sudo apt upgrade -y

Step 2: Install Apache

# Install Apache sudo apt install -y apache2 # Start Apache sudo systemctl start apache2 # Enable Apache on boot sudo systemctl enable apache2 # Check status sudo systemctl status apache2

Step 3: Install MySQL

# Install MySQL Server sudo apt install -y mysql-server # Start MySQL sudo systemctl start mysql # Enable MySQL on boot sudo systemctl enable mysql # Secure MySQL installation sudo mysql_secure_installation

During securing, you will need to:

  • Set a root password for MySQL
  • Remove anonymous users
  • Disable remote root login
  • Remove test database
  • Reload privileges

Step 4: Create WordPress database

# Connect to MySQL sudo mysql -u root -p

In MySQL, run the following commands:

-- Create database CREATE DATABASE wordpress_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- Create user for WordPress CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'YourSecurePassword123!'; -- Grant all privileges to user GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost'; -- Apply changes FLUSH PRIVILEGES; -- Exit MySQL EXIT;

Important : Replace YourSecurePassword123! with a strong and unique password.

Step 5: Install PHP and required extensions

# Install PHP and extensions required for WordPress sudo apt install -y php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip libapache2-mod-php # Check PHP version php -v

WordPress requires PHP 7.4 or higher. To install a specific version:

# For PHP 8.1 (recommended) sudo apt install -y php8.1 php8.1-mysql php8.1-curl php8.1-gd php8.1-mbstring php8.1-xml php8.1-xmlrpc php8.1-soap php8.1-intl php8.1-zip libapache2-mod-php8.1

Step 6: Download WordPress

# Go to temporary directory cd /tmp # Download latest WordPress version curl -O https://wordpress.org/latest.tar.gz # Extract archive tar xzf latest.tar.gz # Copy WordPress to web directory sudo cp -r wordpress/* /var/www/html/ # Set correct permissions sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/html

Step 7: Configure WordPress

# Create configuration file cd /var/www/html sudo cp wp-config-sample.php wp-config.php # Edit configuration file sudo nano wp-config.php

Modify the following lines with your database information:

define( 'DB_NAME', 'wordpress_db' ); define( 'DB_USER', 'wordpress_user' ); define( 'DB_PASSWORD', 'YourSecurePassword123!' ); define( 'DB_HOST', 'localhost' );

Also add these security lines (generate unique keys):

define('AUTH_KEY', 'generate-unique-key-here'); define('SECURE_AUTH_KEY', 'generate-unique-key-here'); define('LOGGED_IN_KEY', 'generate-unique-key-here'); define('NONCE_KEY', 'generate-unique-key-here'); define('AUTH_SALT', 'generate-unique-key-here'); define('SECURE_AUTH_SALT', 'generate-unique-key-here'); define('LOGGED_IN_SALT', 'generate-unique-key-here'); define('NONCE_SALT', 'generate-unique-key-here');

You can generate unique keys at: https://api.wordpress.org/secret-key/1.1/salt/

Step 8: Configure Apache for WordPress

# Enable rewrite module sudo a2enmod rewrite # Edit Apache configuration sudo nano /etc/apache2/sites-available/000-default.conf

Add or modify the <Directory /var/www/html> section:

<Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>

Restart Apache:

sudo systemctl restart apache2

Step 9: Complete installation via web interface

  1. Open your browser
  2. Go to: http://YOUR_IP or http://yourdomain.com
  3. Follow the WordPress installation wizard:
    • Choose your language
    • Fill in site information (title, admin user, email, password)
    • Click Install WordPress

🔧 Method 2: Installation with LEMP (Nginx)

Step 1: Install Nginx

# Install Nginx sudo apt install -y nginx # Start Nginx sudo systemctl start nginx # Enable Nginx on boot sudo systemctl enable nginx

Step 2: Install MySQL (same as LAMP method)

Follow steps 3 and 4 of the LAMP method to install MySQL and create the database.

Step 3: Install PHP-FPM

# Install PHP-FPM and extensions sudo apt install -y php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip # For PHP 8.1 sudo apt install -y php8.1-fpm php8.1-mysql php8.1-curl php8.1-gd php8.1-mbstring php8.1-xml php8.1-xmlrpc php8.1-soap php8.1-intl php8.1-zip

Step 4: Download WordPress

Follow step 6 of the LAMP method to download and install WordPress.

Step 5: Configure Nginx for WordPress

# Create configuration file for your site sudo nano /etc/nginx/sites-available/wordpress

Add the following configuration (replace yourdomain.com with your domain):

server { listen 80; listen [::]:80; server_name yourdomain.com www.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:/var/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }

Enable the site:

# Create symbolic link sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/ # Test configuration sudo nginx -t # Restart Nginx sudo systemctl restart nginx

Step 6: Configure WordPress

Follow steps 7 and 9 of the LAMP method to configure WordPress.

🔒 Securing WordPress

1. Change file permissions

# Permissions for files sudo find /var/www/html -type f -exec chmod 644 {} \; # Permissions for directories sudo find /var/www/html -type d -exec chmod 755 {} \; # Special permissions for wp-config.php sudo chmod 600 /var/www/html/wp-config.php

2. Install SSL certificate with Let's Encrypt

# Install Certbot sudo apt install -y certbot python3-certbot-apache # For Nginx: sudo apt install -y certbot python3-certbot-nginx # Get SSL certificate sudo certbot --apache -d yourdomain.com -d www.yourdomain.com # For Nginx: sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com # Automatic renewal sudo certbot renew --dry-run

3. Configure firewall

# Allow HTTP and HTTPS sudo ufw allow 'Apache Full' # For Nginx: sudo ufw allow 'Nginx Full' # Or manually sudo ufw allow 80/tcp sudo ufw allow 443/tcp

4. Limit login attempts

Install a WordPress security plugin like:

  • Wordfence Security
  • iThemes Security
  • Sucuri Security

5. Disable file editing via interface

Add in wp-config.php:

define('DISALLOW_FILE_EDIT', true);

🔄 WordPress Updates

Via WordPress interface

  1. Log in to WordPress admin
  2. Go to DashboardUpdates
  3. Click Update Now

Via WP-CLI (command line)

# Install WP-CLI curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp # Update WordPress cd /var/www/html sudo -u www-data wp core update sudo -u www-data wp plugin update --all sudo -u www-data wp theme update --all
  • Yoast SEO : Search engine optimization
  • Wordfence Security : Security and protection
  • UpdraftPlus : Automatic backups
  • W3 Total Cache : Caching to improve performance
  • Contact Form 7 : Contact forms

❓ Common Issues

Error "Error establishing a database connection"

Solutions:

  1. Check credentials in wp-config.php
  2. Check MySQL is started: sudo systemctl status mysql
  3. Test connection: mysql -u wordpress_user -p wordpress_db

For Apache:

# Check mod_rewrite is enabled sudo a2enmod rewrite sudo systemctl restart apache2

For Nginx: Check that the try_files configuration is correct.

Permission problems

# Fix permissions sudo chown -R www-data:www-data /var/www/html sudo find /var/www/html -type d -exec chmod 755 {} \; sudo find /var/www/html -type f -exec chmod 644 {} \;

📝 Useful Commands

# Check service status sudo systemctl status apache2 # or nginx sudo systemctl status mysql # Restart services sudo systemctl restart apache2 # or nginx sudo systemctl restart mysql # View Apache logs sudo tail -f /var/log/apache2/error.log # View Nginx logs sudo tail -f /var/log/nginx/error.log # View PHP-FPM logs sudo tail -f /var/log/php8.1-fpm.log

📞 Need Help?

If you encounter difficulties installing WordPress, please contact Infrawire support. Our team is available to help you.


Note : For a better WordPress experience with dedicated support, automatic backups and pre-configured optimizations, consider our WordPress dedicated web hosting.