diff --git a/docs/websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/Multiple_WordPress.png b/docs/websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/Multiple_WordPress.png new file mode 100644 index 00000000000..6d9ddc1b55a Binary files /dev/null and b/docs/websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/Multiple_WordPress.png differ diff --git a/docs/websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/index.md b/docs/websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/index.md index d87dc1d3568..7d9e85de296 100644 --- a/docs/websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/index.md +++ b/docs/websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/index.md @@ -5,7 +5,8 @@ author: description: 'This guide shows how to configure Apache Virtual Hosts to serve multiple WordPress sites from the same Linode.' keywords: ["install WordPress", "WordPress on Linode", "multiple WordPress", "how to configure WordPress"] license: '[CC BY-ND 4.0](https://creativecommons.org/licenses/by-nd/4.0)' -modified: 2017-10-27 +aliases: ['websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/'] +modified: 2018-12-17 modified_by: name: Linode contributor: @@ -16,167 +17,208 @@ external_resources: - '[WordPress.org](http://wordpress.org)' - '[WordPress Codex](http://codex.wordpress.org)' - '[WordPress Support](http://wordpress.org/support)' -- '[Apache Virtual Host documentation](http://httpd.apache.org/docs/current/vhosts/)' +- '[Apache virtual host documentation](http://httpd.apache.org/docs/current/vhosts/)' --- -![WordPress on Apache](Multiple_WordPress.jpg) +![Set Up Apache to Run Multiple WordPress Sites on a Single Linode](Multiple_WordPress.jpg) ## What is WordPress? -WordPress is a popular, dynamic, content management system that makes it easy to build anything from blogs to complete websites and online stores. This guide shows you how to configure your system to run multiple WordPress sites on a single Linode, using Apache Virtual Hosts. +WordPress is a popular, dynamic, content management system that makes it easy to build anything from blogs to complete websites and online stores. This guide shows you how to configure your system to run multiple WordPress sites on a single Linode running Ubuntu 18.04. ## Before You Begin -- Configure a [LAMP](/docs/web-servers/lamp/install-lamp-stack-on-ubuntu-16-04/) web stack. +1. Familiarize yourself with our [Getting Started](/docs/getting-started) guide and complete the steps for setting your Linode’s hostname and timezone. -- This guide assumes you have followed the [Install WordPress on Ubuntu 16.04](/docs/websites/cms/install-wordpress-on-ubuntu-16-04/) guide, and are familiar with the procedures described there. +1. This guide will use sudo wherever possible. Complete the sections of our [Securing Your Server](/docs/security/securing-your-server) guide to create a standard user account, harden SSH access and remove unnecessary network services. -- Make sure MySQL has a database set up for each separate instance of WordPress that you wish to run. If you do not have a WordPress database, create one: +1. If you have not already, [assign Linode's name servers](/docs/platform/manager/dns-manager/#use-linode-s-name-servers-with-your-domain) to your domain at your domain name's registrar. - 1. Log in to the MySQL command line as the root user: +1. Update your system: - mysql -u root -p + apt-get update && apt-get upgrade - 2. Create the WordPress databases with a separate namespace: +## Install a LAMP Stack - CREATE DATABASE example1_wordpress; +WordPress can be deployed on a LAMP stack. A LAMP (Linux, Apache, MySQL, PHP) stack is a common, free, and open source web stack used for hosting web content in a Linux environment. - 3. Create a user and grant them privileges for the newly created `example1_wordpress` database, replacing `example1_wpuser` and `password` with the username and password you wish to use: +Install the LAMP stack using the Tasksel tool: - CREATE USER 'example1_wpuser' IDENTIFIED BY 'password1'; - GRANT ALL PRIVILEGES ON example1_wordpress.* TO 'example1_wpuser'; + sudo tasksel install lamp-server - 4. Repeat Steps 2 and 3 for each instance of WordPress that you want to run, replacing the `example` namespace with a keyword of your choice representing the additional sites: +## Create Your Site Databases and Users - CREATE USER 'example2_wpuser' IDENTIFIED BY 'password2'; - GRANT ALL PRIVILEGES ON example1_wordpress.* TO 'example2_wpuser'; +You will need a MySQL database for *each instance* of WordPress you intend to run. An example of a two-WordPress setup is shown below. Replace `example1` and `example2` with your respective website names. - 5. Exit MySQL: - - quit +| Domain | Database | Username | Password | +| ---------| ---------| ---------| -------- | +| example1.com | example1_wordpress | example1_wpuser | password1 | +| example2.com | example2_wordpress | example2_wpuser | password2 | -- This guide is written for a non-root user. Commands that require elevated privileges are prefixed with `sudo`. If you're not familiar with the `sudo` command, you can check our [Users and Groups](/docs/tools-reference/linux-users-and-groups/) guide. +1. Log in to the MySQL command line as the root user: - - All configuration files should be edited with elevated privileges. Remember to include `sudo` before running your text editor. + sudo mysql -u root -An example of a two WordPress setup is: +1. Create the WordPress databases: -| Hostname | Database | Username | Password | -| ---------| ---------| ---------| -------- | -| example1.com | example1_wordpress | example1_wpuser | password1 | -| example2.com | example2_wordpress | example2_wpuser | password2 | + CREATE DATABASE example1_wordpress; + CREATE DATABASE example2_wordpress; -Replace each instance of `example.com`, `example`, `example1`, `example2`, and the other example variables in this guide with your respective site's domain name and namespace keyword. +1. Create the database users, replacing `example1_wpuser` and `password` with a username and password of your own: -## Install Multiple WordPress Instances + CREATE USER 'example1_wpuser' IDENTIFIED BY 'password1'; + CREATE USER 'example2_wpuser' IDENTIFIED BY 'password2'; -The following steps are adapted from the [Install WordPress](/docs/websites/cms/install-wordpress-on-ubuntu-16-04/#install-wordpress) section of the [Install WordPress on Ubuntu 16.04](/docs/websites/cms/install-wordpress-on-ubuntu-16-04/) guide. +1. Grant the users privileges for their respective database: -1. Create the directory that will host your website and WordPress source files. In this guide, the home directory `/var/www/html/example1.com/` is used as an example. Navigate to that new directory: + GRANT ALL PRIVILEGES ON example1_wordpress.* TO 'example1_wpuser'; + GRANT ALL PRIVILEGES ON example1_wordpress.* TO 'example2_wpuser'; - sudo mkdir /var/www/html/example1.com/ - sudo mkdir /var/www/html/example2.com/ - cd /var/www/html/example1.com/ +1. Exit MySQL: -2. Create a directory called `src` under `/var/www/html/example1.com/`. Download and extract the latest version of WordPress: + quit - sudo mkdir /var/www/html/example1.com/src/ - cd /var/www/html/example1.com/src/ - sudo wget http://wordpress.org/latest.tar.gz - tar -zxvf latest.tar.gz +## Install Multiple WordPress Instances -3. Repeat the procedure for `example2.com`: +1. Create the directories that will host your websites and WordPress source files. In this guide, the home directories `/var/www/html/example1.com/` and `/var/www/html/example2.com/` are used as examples. - sudo mkdir /var/www/html/example2.com/src/ - cd /var/www/html/example2.com/src/ - sudo wget http://wordpress.org/latest.tar.gz - sudo tar -zxvf latest.tar.gz + sudo mkdir -p /var/www/html/{example1.com,example2.com}/public_html -4. Rename `latest.tar.gz` as `wordpress` followed by the date to store a backup of the original source files. This will be useful if you install new versions in the future and need to revert back to a previous release: +1. Create a `src` directory to hold the WordPress tarball and files: - sudo mv latest.tar.gz wordpress-`date "+%Y-%m-%d"`.tar.gz + sudo mkdir /var/www/html/src/ - Repeat this step in `/var/www/html/example2.com/src`. +1. Download and extract the latest version of WordPress to the `src` folder: -5. Set your web server's user, `www-data`, as the owner of your site's home directory: + cd /var/www/html/src/ + sudo wget http://wordpress.org/latest.tar.gz - sudo chown -R www-data:www-data /var/www/html/example1.com/ - sudo chown -R www-data:www-data /var/www/html/example2.com/ +1. Extract the tarball. To store a backup of the original source files, rename `latest.tar.gz` to `wordpress` followed by the date. This will be useful if you install new versions in the future and need to revert back to a previous release. -6. Copy the WordPress files to your `public_html` folder: + sudo tar -zxvf latest.tar.gz + sudo mv latest.tar.gz wordpress-`date "+%Y-%m-%d"`.tar.gz - sudo cp -R /var/www/html/example1.com/src/wordpress/* ../public_html/ - sudo cp -R /var/www/html/example2.com/src/wordpress/* ../public_html/ +1. Copy the WordPress files to your site's `public_html` folders: -7. Give your web server ownership of the `public_html` folder: + sudo cp -R /var/www/html/src/wordpress/* /var/www/html/example1.com/public_html/ + sudo cp -R /var/www/html/src/wordpress/* /var/www/html/example2.com/public_html/ - sudo chown -R www-data:www-data /var/www/html/example1.com/public_html - sudo chown -R www-data:www-data /var/www/html/example2.com/public_html +1. Give Apache ownership of your WordPress sites' home directories: -8. Repeat for each additional instance of WordPress that you want to run. + sudo chown -R www-data:www-data /var/www/html/{example1.com,example2.com}/ ## Configure Apache Virtual Hosts -Up until this point, the steps have been fairly straightforward and similar to setting up a single instance of WordPress. In this section, configure Apache Virtual Hosts so that a visitor to `example1.com` will be served the content in `/var/www/html/example1.com/public_html` and backed by the MySQL database `example1_wordpress`. +In this section, you will configure the Apache virtual hosts file so that a visitor to `example1.com` will be served the content in `/var/www/html/example1.com/public_html` and the MySQL database `example1_wordpress`. Visitors to `example2.com` will be served content in `/var/www/html/example2.com/public_html/` and its corresponding MySQL database. -1. Go to the Apache `sites-available` directory: +1. Create a virtual hosts configuration file for `example1.com` and add the example virtual host block into `/etc/apache2/sites-available/example1.com`. Be sure to replace all instances of `example1.com` with your own domain. - cd /etc/apache2/sites-available + {{< file "/etc/apache2/sites-available/example1.conf" apache >}} + + # The primary domain for this host + ServerName example1.com + # Optionally have other subdomains also managed by this Virtual Host + ServerAlias example1.com *.example1.com + DocumentRoot /var/www/html/example1.com/public_html + + Require all granted + # Allow local .htaccess to override Apache configuration settings + AllowOverride all + + # Enable RewriteEngine + RewriteEngine on + RewriteOptions inherit + + # Block .svn, .git + RewriteRule \.(svn|git)(/)?$ - [F] + + # Catchall redirect to www.example1.com + RewriteCond %{HTTP_HOST} !^www.example1\.com [NC] + RewriteCond %{HTTP_HOST} !^$ + RewriteRule ^/(.*) https://www.example1.com/$1 [L,R] + + # Recommended: XSS protection + + Header set X-XSS-Protection "1; mode=block" + Header always append X-Frame-Options SAMEORIGIN + + -2. Copy `000-default.conf` as needed: + {{}} - cp 000-default.conf example1.conf - cp 000-default.conf example2.conf +1. Enable the site. This will create a symlink to the `example1.com` Apache conf file in `/etc/apache2/sites-enabled/`: -3. Put the following contents in `example1.com`: + sudo a2ensite example1.conf - {{< file "example1.conf" apache >}} +1. Create a virtual hosts configuration file for your second WordPress site, `example2.com`. Be sure to replace all instances of `example2.com` with your own domain. + + {{< file "/etc/apache2/sites-available/example2.conf" apache >}} -# The primary domain for this host -ServerName example1.com -# Optionally have other subdomains also managed by this Virtual Host -ServerAlias example1.com *.example1.com -DocumentRoot /var/www/html/example1.com/public_html - -Require all granted -# Allow local .htaccess to override Apache configuration settings -AllowOverride all - -# Enable RewriteEngine -RewriteEngine on -RewriteOptions inherit - -# Block .svn, .git -RewriteRule \.(svn|git)(/)?$ - [F] - -# Catchall redirect to www.example1.com -RewriteCond %{HTTP_HOST} !^www.example1\.com [NC] -RewriteCond %{HTTP_HOST} !^$ -RewriteRule ^/(.*) https://www.example1.com/$1 [L,R] - -# Recommended: XSS protection - -Header set X-XSS-Protection "1; mode=block" -Header always append X-Frame-Options SAMEORIGIN - + # The primary domain for this host + ServerName example2.com + # Optionally have other subdomains also managed by this Virtual Host + ServerAlias example2.com *.example2.com + DocumentRoot /var/www/html/example2.com/public_html + + Require all granted + # Allow local .htaccess to override Apache configuration settings + AllowOverride all + + # Enable RewriteEngine + RewriteEngine on + RewriteOptions inherit + + # Block .svn, .git + RewriteRule \.(svn|git)(/)?$ - [F] + + # Catchall redirect to www.example2.com + RewriteCond %{HTTP_HOST} !^www.example2\.com [NC] + RewriteCond %{HTTP_HOST} !^$ + RewriteRule ^/(.*) https://www.example2.com/$1 [L,R] + + # Recommended: XSS protection + + Header set X-XSS-Protection "1; mode=block" + Header always append X-Frame-Options SAMEORIGIN + + {{}} -{{}} +1. Enable the site: + sudo a2ensite example2.conf -4. Enable the site. This will create a symlink to the `example.com` Apache conf file in `/etc/apache2/sites-enabled/`: + You can repeat Steps 1 and 2 for each WordPress site that you want to host on your Linode. - sudo a2ensite example1.conf +1. If the `rewrite_module` module is not enabled, you will need to enable it before reloading Apache to have your configurations take effect. To check which Apache modules are enabled, run the following command: + + sudo apache2ctl -M -5. Restart Apache to enable the changes: + Verify that you see `rewrite_module` in the list. If you do not see the module, enable it with the following command: - sudo systemctl restart apache2 + sudo a2enmod rewrite -6. Repeat Steps 2 through 5 for each WordPress site that you want to run. +1. For the new configurations to take effect, reload Apache: + + sudo systemctl reload apache2 ## Configure WordPress -Follow the steps from the [Configure WordPress](/docs/websites/cms/install-wordpress-on-ubuntu-16-04/#configure-wordpress) section of the [Install WordPress on Ubuntu 16.04](/docs/websites/cms/install-wordpress-on-ubuntu-16-04/) guide. +Follow the [Configure WordPress](/docs/websites/cms/install-wordpress-ubuntu-18-04/#configure-wordpress) section of our Install WordPress on Ubuntu 18.04 guide. + +If you do not yet have registered domains to use, you can still perform the WordPress installation using your Linode's IP address. For example: + +1. Verify your WordPress installation by using your Linode's IP address to load the WordPress installations in your browser: + + http://203.0.113.15/example1.com/public_html + http://203.0.113.15/example2.com/public_html + + You should see WordPress' set up page: + + ![WordPress setup-config.php](wp-config.png) + +1. You can begin configuring your WordPress sites. Follow the [Configure WordPress](/docs/websites/cms/install-wordpress-ubuntu-18-04/#configure-wordpress) section of our Install WordPress on Ubuntu 18.04 guide. +1. If you have not yet added DNS records for your Domains, follow the *Add DNS Records* steps in the [Host a Website on Ubuntu 18.04](/docs/websites/hosting-a-website-ubuntu-18-04/#add-dns-records) guide. diff --git a/docs/websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/wordpress-setup-config-php.png b/docs/websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/wordpress-setup-config-php.png new file mode 100644 index 00000000000..6174b3f9f56 Binary files /dev/null and b/docs/websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/wordpress-setup-config-php.png differ diff --git a/docs/websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/wp-config.png b/docs/websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/wp-config.png new file mode 100644 index 00000000000..f5fbf917775 Binary files /dev/null and b/docs/websites/cms/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/wp-config.png differ