keepcalculator

06 Numbers and Powers

Host Multiple WordPress Domains on Apache VPS

Card No. 06·70156 · Updated · Standard formula, shown below

This guide walks you through hosting multiple WordPress websites on a single VPS using Apache. You’ll learn how to configure virtual hosts so each domain points to its own WordPress installation, making efficient use of your server resources. By the end, you’ll have a clear, repeatable process for adding new sites to your server.

What You’ll Need

  • A VPS running a Linux distribution (Ubuntu 20.04/22.04 or Debian 10/11 recommended) with root or sudo access.
  • Apache web server installed and running.
  • MySQL or MariaDB database server installed.
  • PHP installed with the necessary extensions (php-mysql, php-xml, php-curl, etc.).
  • At least two domain names pointing to your server’s IP address via DNS A records.
  • SSH client (like PuTTY on Windows or terminal on macOS/Linux).
  • Basic familiarity with the command line and file editing.

Step-by-Step

  1. Connect to your VPS via SSH: ssh user@your-server-ip. Update your system packages: sudo apt update && sudo apt upgrade -y (or use your distribution’s package manager).
  2. Install required packages if not already installed. For Ubuntu/Debian: sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php php-xml php-curl php-zip php-gd php-mbstring.
  3. Create directory structure for each site. For example, for example.com and example.org: sudo mkdir -p /var/www/example.com/public_html and sudo mkdir -p /var/www/example.org/public_html.
  4. Set permissions so your user can manage files: sudo chown -R $USER:$USER /var/www/example.com/public_html (repeat for each site).
  5. Download WordPress into each site’s directory. For the first site: cd /var/www/example.com/public_html, then wget https://wordpress.org/latest.tar.gz, tar -xzvf latest.tar.gz, mv wordpress/* ., rmdir wordpress, and rm latest.tar.gz. Repeat for each domain.
  6. Create databases and users for each WordPress installation. Log into MySQL: sudo mysql. Then run (replace example_com and password with your own):
    CREATE DATABASE example_com;
    CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'strong-password';
    GRANT ALL PRIVILEGES ON example_com.* TO 'example_user'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;

    Repeat for each site with a unique database name and user.

  7. Configure Apache virtual hosts. Create a config file for each site: sudo nano /etc/apache2/sites-available/example.com.conf. Add the following (adjust paths and domain):
    <VirtualHost *:80>
        ServerAdmin admin@example.com
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/example.com/public_html
        <Directory /var/www/example.com/public_html>
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
        CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
    </VirtualHost>

    Save and exit. Repeat for each domain.

  8. Enable the sites and the necessary Apache modules: sudo a2ensite example.com.conf (repeat for each), sudo a2enmod rewrite, and sudo systemctl restart apache2.
  9. Run WordPress installer for each site. Open your browser and go to http://example.com. Follow the WordPress setup wizard, entering the database name, user, and password you created for that site. Complete the installation for each domain.
  10. Enable HTTPS (optional but recommended) using Let’s Encrypt: sudo apt install certbot python3-certbot-apache, then run sudo certbot --apache and follow the prompts to secure each domain.

Common Mistakes

  • Forgetting to enable mod_rewrite – WordPress permalinks won’t work without it.
  • Using the same database for multiple sites – causes table prefix conflicts and data mixing.
  • Incorrect file permissions – WordPress may not be able to write to wp-content/uploads, causing upload failures.
  • Not setting ServerAlias – visitors using www.example.com may see the default Apache page.
  • DNS not propagated – if you just changed DNS, give it time or use a local hosts file for testing.

Tips

  • Use a separate database user per site to improve security and isolation.
  • Keep WordPress and plugins updated regularly to avoid vulnerabilities.
  • Consider using a caching plugin (like W3 Total Cache) to improve performance, especially on a VPS with limited resources.
  • Set up regular backups of both files and databases. Tools like UpdraftPlus can automate this.
  • Use SSH keys instead of passwords for more secure server access.

Troubleshooting

  • Site shows the default Apache page – Check that the virtual host file is correctly named and enabled (sudo a2ensite example.com.conf), and that DNS points to your server.
  • WordPress installation asks for FTP credentials – This usually means file permissions are wrong. Ensure the web server user (www-data) has write access to wp-content: sudo chown -R www-data:www-data /var/www/example.com/public_html.
  • 404 errors on pages other than the homepage – Enable mod_rewrite (sudo a2enmod rewrite) and restart Apache. Also check that the <Directory> block has AllowOverride All.
  • Database connection errors – Double-check the database name, user, and password in wp-config.php. Ensure the database exists and the user has privileges.
  • One site works, another doesn’t – Verify that each virtual host file has unique ServerName and DocumentRoot, and that the directories exist with correct permissions.
  • PHP errors or blank pages – Check the Apache error logs: sudo tail -f /var/log/apache2/error.log. Common fixes include installing missing PHP extensions.

Frequently Asked Questions

Can I use the same database for multiple WordPress sites?

Technically yes, but it’s not recommended. WordPress uses table prefixes (like wp_), and you could set different prefixes per site, but it’s messy and increases the risk of data corruption. Separate databases are cleaner and more secure.

How many WordPress sites can I host on one VPS?

It depends on your VPS resources (CPU, RAM, disk) and the traffic each site receives. A small VPS with 2GB RAM can comfortably handle 3-5 low-traffic sites. Monitor your server’s load and upgrade if needed.

Do I need a static IP for my VPS?

Yes, it’s strongly recommended. A static IP ensures that your DNS records always point to the correct server. Most VPS providers offer a static IP by default.

Can I host subdomains as separate WordPress sites?

Absolutely. Just create a virtual host with ServerName like blog.example.com and follow the same steps. You’ll need to create a DNS A record for the subdomain pointing to your server.

What if I want to use Nginx instead of Apache?

Nginx uses a different configuration approach (server blocks) and often has better performance. The process is similar but you’d need to adapt the configuration syntax. This guide focuses on Apache, but the concepts transfer.

How do I add a new site later?

Simply repeat steps 3-10: create the directory, download WordPress, create a database, create a virtual host file, enable it, and run the installer. It’s a straightforward process once you’ve done it once.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →