English

Install WordPress on a Linux VPS

3 min
VPS/VDS Hosting

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 VPS High Performance 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

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

Step 2: Install Apache

Bash
# 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

Bash
# 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

Bash
# Connect to MySQL sudo mysql -u root -p

In MySQL, run the following commands:

SQL
1-- Create database 2CREATE DATABASE wordpress_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 3 4-- Create user for WordPress 5CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'YourSecurePassword123!'; 6 7-- Grant all privileges to user 8GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost'; 9 10-- Apply changes 11FLUSH PRIVILEGES; 12 13-- Exit MySQL 14EXIT;

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

Step 5: Install PHP and required extensions

Bash
# 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:

Bash
# 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

Bash
# 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

Bash
# 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:

PHP
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):

PHP
1define('AUTH_KEY', 'generate-unique-key-here'); 2define('SECURE_AUTH_KEY', 'generate-unique-key-here'); 3define('LOGGED_IN_KEY', 'generate-unique-key-here'); 4define('NONCE_KEY', 'generate-unique-key-here'); 5define('AUTH_SALT', 'generate-unique-key-here'); 6define('SECURE_AUTH_SALT', 'generate-unique-key-here'); 7define('LOGGED_IN_SALT', 'generate-unique-key-here'); 8define('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

Bash
# 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:

Apache
1<Directory /var/www/html> 2 Options Indexes FollowSymLinks 3 AllowOverride All 4 Require all granted 5</Directory>

Restart Apache:

Bash
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

Bash
# 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

Bash
# 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

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

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

Nginx
1server { 2 listen 80; 3 listen [::]:80; 4 server_name yourdomain.com www.yourdomain.com; 5 root /var/www/html; 6 index index.php index.html index.htm; 7 8 location / { 9 try_files $uri $uri/ /index.php?$args; 10 } 11 12 location ~ \.php$ { 13 include snippets/fastcgi-php.conf; 14 fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; 15 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 16 include fastcgi_params; 17 } 18 19 location ~ /\.ht { 20 deny all; 21 } 22}

Enable the site:

Bash
# 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

Bash
# 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

Bash
# 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

Bash
# 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:

PHP
define('DISALLOW_FILE_EDIT', true);

🔄 WordPress Updates

Via WordPress interface

  1. Log in to WordPress admin
  2. Go to Dashboard → Updates
  3. Click Update Now

Via WP-CLI (command line)

Bash
# 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:

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

For Nginx: Check that the try_files configuration is correct.

Permission problems

Bash
# 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

Bash
# 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.

Stay up to date with the latest offers, discounts and special promotions.

View promotions

We use cookies

We use analytics cookies to improve your experience on our site. No data is sold to third parties. Learn more in our privacy policy.