There are multiple ways to run websites using WordPress… some use WordPress on a single host server while others might choose to run multiple versions of WordPress using sub-domains… One popular and easy way to run WordPress is via a feature it has called Multisite…
WordPress Multisite feature allows webmasters to host multiple WordPress websites or blogs on a single WordPress installation…
An example would be creating a web host on example.com domain and installing WordPress on it… With Multisite feature enabled, you can then create site1.example.com, site2.example.com WordPress sites and so forth…
With the setup above, you can then configure a DNS and domain mapping in WordPress to point whatever domain to site1.example.com or site2.example.com… this is done in the background without the user knowing it..
This feature is great and when done properly, you’d not need multiple hosts to how multiple domains and websites..
The steps below will show students and new users how to setup WordPress Multiple site with Nginx, MariaDB, PHP 7.2 on Ubuntu servers….
Step 1: Install WordPress Primary Site
WordPress need a webserver, so run the commands below to install Nginx…
sudo apt update sudo apt install nginx
After installing Nginx, the commands below can be used to stop, start and enable Nginx service to always start up with the server boots.
sudo systemctl stop nginx.service sudo systemctl start nginx.service sudo systemctl enable nginx.service
WordPress also needs a database server… so run the commands below to install MariaDB…
sudo apt-get install mariadb-server mariadb-client
After installing, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.
Run these on Ubuntu 16.04 LTS
sudo systemctl stop mysql.service sudo systemctl start mysql.service sudo systemctl enable mysql.service
Run these on Ubuntu 17.10 and 18.04 LTS
sudo systemctl stop mariadb.service sudo systemctl start mariadb.service sudo systemctl enable mariadb.service
After that, run the commands below to secure MariaDB server by creating a root password and disallowing remote root access.
sudo mysql_secure_installation
When prompted, answer the questions below by following the guide.
- Enter current password for root (enter for none): Just press the Enter
- Set root password? [Y/n]: Y
- New password: Enter password
- Re-enter new password: Repeat password
- Remove anonymous users? [Y/n]: Y
- Disallow root login remotely? [Y/n]: Y
- Remove test database and access to it? [Y/n]: Y
- Reload privilege tables now? [Y/n]: Y
WordPress requires PHP to function… however, PHP 7.2-FPM may not be available on Ubuntu… to install PHP 7.2, run the commands below…
sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php
Then update and upgrade to PHP 7.2-FPM
sudo apt update
sudo apt install php7.2-fpm php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-gd php7.2-xml php7.2-mysql php7.2-cli php7.2-zip php7.2-curl
After install PHP 7.2, run the commands below to open PHP-FPM default file.
sudo nano /etc/php/7.2/fpm/php.ini
Then make the changes on the following lines below in the file and save. The value below are great settings to apply in your environments.
file_uploads = On allow_url_fopen = On memory_limit = 256M upload_max_filesize = 100M cgi.fix_pathinfo=0 max_execution_time = 360 date.timezone = America/Chicago
Now that you’ve install all the packages that are required, continue below to start configuring the servers. First run the commands below to create a blank WordPress database.
To logon to MariaDB database server, run the commands below.
sudo mysql -u root -p
Then create a database called wpdb
CREATE DATABASE wpdb;
Create a database user called wpuser with new password
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'new_password_here';
Then grant the user full access to the database.
GRANT ALL ON wpdb.* TO 'wpuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
Finally, save your changes and exit.
FLUSH PRIVILEGES; EXIT;
Next, visit WordPress site and download the latest version….
After downloading, run the commands below to extract the downloaded file and move it into a new WordPress root directory.
cd /tmp && wget https://wordpress.org/latest.tar.gz tar -zxvf latest.tar.gz sudo mv wordpress /var/www/html/wordpress
Then run the commands below to set the correct permissions for WordPress to function.
sudo chown -R www-data:www-data /var/www/html/wordpress/ sudo chmod -R 755 /var/www/html/wordpress/
Finally, configure Nginx site configuration file for WordPress. This file will control how users access WordPress content. Run the commands below to create a new configuration file called wordpress
sudo nano /etc/nginx/sites-available/wordpress
Then copy and paste the content below into the file and save it. Replace the highlighted line with your own domain name and directory root location.
server {
listen 80;
listen [::]:80;
root /var/www/html/wordpress;
index index.php index.html index.htm;
server_name example.com *.example.com example.net example.org;
client_max_body_size 100M;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Save the file and exit.
After configuring the VirtualHost above, enable it by running the commands below….
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
To load all the settings above, restart Nginx by running the commands below.
sudo systemctl restart nginx.service
Now that Nginx is configured, run the commands below to create WordPress wp-config.php file.
sudo mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
Then run the commands below to open WordPress configuration file.
sudo nano /var/www/html/wordpress/wp-config.php
Enter the highlighted text below that you created for your database and save.
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wpdb'); /** MySQL database username */ define('DB_USER', 'wpuser'); /** MySQL database password */ define('DB_PASSWORD', 'user_password_here'); /** MySQL hostname */ define('DB_HOST', 'localhost'); /** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8'); /** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', '');
After that, open your browser and browse to your domain name to launch WordPress configuration wizard.
You should see WordPress setup wizard to complete. Please follow the wizard carefully and complete the installation… You’ll be asked to create an admin account and website name…
Step 2: Configure WordPress Multisite
Now that WordPress installed, reopen WordPress configuration file by running the commands below…
sudo nano /var/www/html/wordpress/wp-config.php
Then enable WordPress Multisite feature by adding the line below into the file just above, then save the file…
*/
define('WP_DEBUG', false);
define('WP_ALLOW_MULTISITE', true);
/* That's all, stop editing! Happy blogging. */
This will enable WordPress Multisite… save the file and exit..
After Mutisite is enabled, go back to WordPress admin dashboard and select Tools –> Network Setup
Then install Multisite with subdomain… To use a subdomain configuration, you must have a wildcard entry in your DNS. This usually means adding a * hostname record pointing at your web server in your DNS configuration tool.
When your domain is correctly configured… you can continue below with the setup…
After installing, you’ll be given a configure code to use in the .htaccess file in your root directory… copy the code and replace the one in the file below with it…
Add the following to your wp-config.php file in /var/www/html/wordpress/ above the line reading /* That’s all, stop editing! Happy blogging. */:
sudo nano /var/www/html/wordpress/wp-config.php
Then add the highlighted block of code below…
*/
define('WP_DEBUG', false);
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'example.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
define('WP_ALLOW_MULTISITE', true);
/* That's all, stop editing! Happy blogging. */
Save the file and exit.
Step 3: Create Multisite Sites
Now that the network configuration is done… go to Sites –> Add New to begin adding your sites…
Add the site you want to create…
Next, go to My Sites -> Network Admin -> Sites, click edit button of the newly-created subsite. In the Site Address field, replace the URL with the top-level domain you want to map.
Save and you’re done…
When your visitors type in http://example.net, they will be redirected to the subdomain site1.example.com without the
them knowing about the switch…
This is how to configure WordPress with Multisites….
Enjoy!
You may also like the post below:
Drupal Updates Released to Fix Highly Critical Bug – Here’s How to Install on Ubuntu
Hi I am following the tutorial and getting this error when I am trying to being the WordPress install steps
xxx@xxx:~$ sudo mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
mv: cannot stat ‘/var/www/html/wordpress/wp-config-sample.php’: No such file or directory
Hi,
I’m following your guide and i encountered the following when adding PHP repoitory:
CAVEATS:
1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
2. If you are using apache2, you are advised to add ppa:ondrej/apache2
3. If you are using nginx, you are advise to add ppa:ondrej/nginx-mainline
or ppa:ondrej/nginx
Should I still use ppa:ondrej/php or better use ppa:ondrej/nginx or ppa:ondrej/nginx-mainline
Thanks!
Oh and btw I detected a typo that unless corrected will throw 502 Bad gateway error from Nginx due to bad server block config:
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
>
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
Please repair the last step. Its confusing. It make my site automatically redirect to example.com . Please tell to change it first. You make me so curious after implement the last step. Then i might think that my domain is not for used commersial. DAMN
Thanks for the guide, there are only a few with mariadb in mind out there. just a few things to point out:
GRANT ALL ON wpdb.* TO ‘wpdbuser…
#Should be actually:
GRANT ALL ON wpdb.* TO ‘wpuser…
#Also I recommend to unlink the default nginx site:
sudo unlink /etc/nginx/sites-enabled/default
#Also I recommend to change the permissions separately for directories and files
find /var/www/html -type f -exec chmod 644 ‘{}’ +
find /var/www/html -type d -exec chmod 755 ‘{}’ +
Thanks, updated
Where to insert the wordpress rewrite rules? It asks to insert rules in .htaccess but .htaccess doesn’t exist in Nginx
Just ignore those rewrite rules for Nginx.