InfrawireInfrawire LogoDocumentation
Appeler

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 VPS Ryzen 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
1# Update package list 2sudo apt update 3 4# Update installed packages 5sudo apt upgrade -y

Step 2: Install Apache

Bash
1# Install Apache 2sudo apt install -y apache2 3 4# Start Apache 5sudo systemctl start apache2 6 7# Enable Apache on boot 8sudo systemctl enable apache2 9 10# Check status 11sudo systemctl status apache2

Step 3: Install MySQL

Bash
1# Install MySQL Server 2sudo apt install -y mysql-server 3 4# Start MySQL 5sudo systemctl start mysql 6 7# Enable MySQL on boot 8sudo systemctl enable mysql 9 10# Secure MySQL installation 11sudo 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
1# Install PHP and extensions required for WordPress 2sudo 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 3 4# Check PHP version 5php -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
1# Go to temporary directory 2cd /tmp 3 4# Download latest WordPress version 5curl -O https://wordpress.org/latest.tar.gz 6 7# Extract archive 8tar xzf latest.tar.gz 9 10# Copy WordPress to web directory 11sudo cp -r wordpress/* /var/www/html/ 12 13# Set correct permissions 14sudo chown -R www-data:www-data /var/www/html 15sudo chmod -R 755 /var/www/html

Step 7: Configure WordPress

Bash
1# Create configuration file 2cd /var/www/html 3sudo cp wp-config-sample.php wp-config.php 4 5# Edit configuration file 6sudo 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
1# Enable rewrite module 2sudo a2enmod rewrite 3 4# Edit Apache configuration 5sudo 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
1# Install Nginx 2sudo apt install -y nginx 3 4# Start Nginx 5sudo systemctl start nginx 6 7# Enable Nginx on boot 8sudo 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
1# Install PHP-FPM and extensions 2sudo apt install -y php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip 3 4# For PHP 8.1 5sudo 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
1# Create symbolic link 2sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/ 3 4# Test configuration 5sudo nginx -t 6 7# Restart Nginx 8sudo 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
1# Permissions for files 2sudo find /var/www/html -type f -exec chmod 644 {} \; 3 4# Permissions for directories 5sudo find /var/www/html -type d -exec chmod 755 {} \; 6 7# Special permissions for wp-config.php 8sudo chmod 600 /var/www/html/wp-config.php

2. Install SSL certificate with Let's Encrypt

Bash
1# Install Certbot 2sudo apt install -y certbot python3-certbot-apache 3# For Nginx: sudo apt install -y certbot python3-certbot-nginx 4 5# Get SSL certificate 6sudo certbot --apache -d yourdomain.com -d www.yourdomain.com 7# For Nginx: sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com 8 9# Automatic renewal 10sudo certbot renew --dry-run

3. Configure firewall

Bash
1# Allow HTTP and HTTPS 2sudo ufw allow 'Apache Full' 3# For Nginx: sudo ufw allow 'Nginx Full' 4 5# Or manually 6sudo ufw allow 80/tcp 7sudo 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 DashboardUpdates
  3. Click Update Now

Via WP-CLI (command line)

Bash
1# Install WP-CLI 2curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar 3chmod +x wp-cli.phar 4sudo mv wp-cli.phar /usr/local/bin/wp 5 6# Update WordPress 7cd /var/www/html 8sudo -u www-data wp core update 9sudo -u www-data wp plugin update --all 10sudo -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
1# Check service status 2sudo systemctl status apache2 # or nginx 3sudo systemctl status mysql 4 5# Restart services 6sudo systemctl restart apache2 # or nginx 7sudo systemctl restart mysql 8 9# View Apache logs 10sudo tail -f /var/log/apache2/error.log 11 12# View Nginx logs 13sudo tail -f /var/log/nginx/error.log 14 15# View PHP-FPM logs 16sudo 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.