WordPress itself is powerful enough to help you create not only a high-performance blog but also a fully-functioning static or dynamic website. The scope of use does not end here; you can create membership portals, forms, QnA sites, and run a WordPress Multisite network on Ubuntu.
Yes, a multisite network on Ubuntu.
The core WordPress files are capable enough to let you turn your single WordPress installation into a fully-functioning multisite network with a few tweaks in the code. For this tutorial, I will go through the LAMP stack installation, WordPress installation and then I will setup the WordPress multisite network on Ubuntu.
About the author: Vashishtha Kapoor is a Digital Marketing enthusiast and has over 5 years of experience in SEO, PPC, Website Management and WordPress development. Vashishtha writes about WordPress customizations, website designing, technology trends, and ad-tech topics.
PART 1: Installing LAMP Stack on Ubuntu
To install and setup your WordPress multisite network, first deploy an Ubuntu VPS.
After deploying an Ubuntu 18.04 VPS, SSH into your server as root and run the following commands.
Update and upgrade the packages. This will upgrade all the modules on your VPS to the latest version. The process will take a few minutes so you can go get a coffee and wait till the packages are updated and upgraded.
sudo apt update && sudo apt upgrade
Install apache2
sudo apt-get install apache2
Whenever it asks for Yes or No, simply press “Y” and then press “ENTER”
MySQL is one of the essential requirements to be able to host a WordPress or multisite network on your Ubuntu server.
sudo apt-get install mysql-server
Perform a secure installation of MySQL server and set up the essential preliminary factors.
sudo mysql_secure_installation
setup VALIDATE PASSWORD plugin? – No
New Password for database root – YOURTOUGHPASSWORD
Re-enter New Password for database root – YOURTOUGHPASSWORD
Remove anonymous users – Y
Disallow root login remotely – Y
Remove test database and access to it – Y
Reload privileges table now – Y
Login to your MySQL server as root with the new password
sudo mysql -u root -p
By default, the root user uses auth_socket plugin. You need to change that for the root user to be able to login using the MySQL native password.
mysql>
SELECT user,authentication_string,plugin,host FROM mysql.user;
Make root use mysql_native_password with the following command. Replace the password with your own tough password.
mysql>
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Check if the auth_socket is replaced with mysql_native_password with the command below.
mysql>
SELECT user,authentication_string,plugin,host FROM mysql.user;
Reload the privileges table and exit from the mysql console
mysql>
flush privileges; exit;
The latest version of PHP is recommended when hosting a WordPress multisite on your Ubuntu server.
The following command will install the ‘sofware-properties-common’ package which allows us to modify the existing apt repositories via add-apt-repository.
sudo apt-get install software-properties-common
Call the required repositories for php on your VPS
sudo add-apt-repository ppa:ondrej/php
Install all the required modules of php7.4-fpm
sudo apt-get install php7.4 php7.4-fpm php7.4-xml php7.4-mysql php7.4-gd php7.4-bz2 php7.4-cli php7.4-common php7.4-curl php7.4-json php7.4-mbstring php7.4-opcache php7.4-imagick php7.4-readline php7.4-zip libapache2-mod-php7.4 php-mysql
You need now to make sure that the apache server serves php files and its priority is on top. To do this, you need to edit the dir.conf file inside /etc/apache2/mods-enabled/ using the below command.
sudo nano /etc/apache2/mods-enabled/dir.conf
The file should look like this.
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
Add index.php to the front of the list under DirectoryIndex initiative.
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
Save and exit the file with CTRL + X , followed by Y and ENTER.
Reload the apache2 process
sudo systemctl restart apache2
Navigate to /var/www and remove the default html folder
cd /var/www/ sudo rm -r html
Create a new folder for your domain. The name of the folder is your choice. Replace the domain.com with your own domain name and run the command.
sudo mkdir domain.com
Give permissions to the www-data user on the directory /var/www/domain.com with the following command.
chown -R www-data:www-data /var/www/domain.com
To setup the virtual host and map your domain to /var/www/domain.com, create your own domain.conf in /etc/apache2/sites-available/
Replace domain with your domain name and run the command given below.
sudo nano /etc/apache2/sites-available/domain.conf
Paste the following content and replace your_domain with your domain name and domain.com with the name of folder you created earlier.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/domain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<Directory /var/www/domain.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Read more: How To Create Custom WordPress Templates
Test your apache virtual host configuration
sudo apache2ctl configtest
Enable domain.conf site to resolve on port 80 and server content from /var/www/domain.com
sudo a2ensite domain.conf
Disable the default site configuration file and remove it from sites-available folder
sudo a2dissite 000-default.conf sudo rm -r /etc/apache2/sites-available/000-default.conf
To make sure the install and setup of your WordPress is smooth, restart the apache server and test your configuration again
sudo systemctl reload apache2 sudo apache2ctl configtest
Create a PHP file on your server to test if it is working properly.
sudo nano /var/www/domain.com/info.php
Paste the following content in the editor.
<?php phpinfo(); ?>
Save and exit the file with CTRL + X , followed by Y and ENTER.
Check the configuration by opening http://yourdomain.com/info.php in your browser.
It should return a page like this with details of your php configuration.
Remove the info.php and index.html text files we created to test if apache2 is working properly.
sudo rm -r /var/www/domain.com/info.php sudo rm -r /var/www/domain.com/index.html
Two more parts until you’re done setting up your WordPress multisite network.
Part 2: Installing WordPress on LAMP Stack
Now you’re all set to install WordPress on your VPS/. But first, let’s set up the database for your WordPress installation.
Login to MySQL as root with the password.
sudo mysql -u root -p
Type your password and press ENTER
We’re now using the MySQL console which will allow us to create our database. Replace yourdatabasename with your desired database name.
mysql>
create database yourdatabasename;
Create a database user and set the password for it using the following command. Replace dbuser with your desired username and password with a strong password.
mysql>
create user ‘dbuser’@’localhost’ identified by ‘password’;
You can not access the database unless you grant permissions to the newly created user on the database. Grant permissions with this command:.
mysql>
grant all on databasename.* to ‘<strong>dbuser</strong>’@’localhost’;
Reload the privileges table and exit the MySQL console.
mysql>
flush privileges;
mysql>
exit
We have now set up the database and prepared it to be configured to a WordPress site. All you need now is to upload the WordPress core files in the document root of your domain.
Install zip and unzip as a preliminary feature to be able to unzip WordPress.
sudo apt install wget zip unzip
Change your directory to /var/www/domain.com/
cd /var/www/domain.com/
Once you’re in the document root of your domain, use the wget command to download the latest version of WordPress. The following command will download a file titled latest.zip to the current working directory.
sudo wget https://wordpress.org/latest.zip
Extract latest.zip and delete the zip file
sudo unzip latest.zip
sudo rm -r latest.zip
Now, you should see a folder named wordpress in your document root. You have to move all content that is inside this folder to your document root.
sudo mv wordpress/* /var/www/<strong>domain.com</strong>/
Remove the wordpress folder
sudo rm -r wordpress
Rename wp-config-sample.php to wp-config.php
sudo mv wp-config-sample.php wp-config.php
Open wp-config.php using the nano editor
sudo nano wp-config.php
Change the values marked with bold. You need to type the database name, database user and database password here.
/** The name of the database for WordPress */ define('DB_NAME', '<strong>database_name_here</strong>'); /** MySQL database username */ define('DB_USER', <strong>'username_here'</strong>); /** MySQL database password */ define('DB_PASSWORD', <strong>'password_here'</strong>);
Save and exit the file with CTRL + X , followed by Y and ENTER.
Enable rewrite module and restart apache2 so that permalinks will work properly. Otherwise, you will be entertained by a “404 not found” result on any post or page in WordPress.
sudo a2enmod rewrtite sudo systemctl restart apache2
Open yourdomain.com in your browser and complete the installation of WordPress.
Choose your preferred language and click continue.
On successful completion, you will see the SUCCESS screen. Click login and you will land into your WordPress dashboard.
You’re almost done setting up your WordPress multisite network on Ubuntu!
PART3: Configure and set up Multisite Network
Use nano editor to edit the wp-config. php file
sudo nano /var/www/domain.com/wp-config.php
Add the below line after define( ‘DB_COLLATE’, ” );
define( 'DB_COLLATE', '' ); define('WP_ALLOW_MULTISITE', true);
Go to Tools >> Network Setup
Configure the way you want your multisite network on Ubuntu to be set up.
Once you’re sure that you want sites to use a sub-domain or a sub-directory, choose a Network Title, add an Network Admin email and click INSTALL.
Note: You would need a wildcard * A record if you want your multisite network to use the sub-domain option. However, no DNS change would be required in case of a multisite network using sub-directories.
When you click install, the setup wizard will ask you to change the wp-config.php and .htaccess file like this.
Read more: 10 Must-Have WordPress Plugins For 2020
Edit wp-config.php with the nano editor and add the code above the line reading /* That’s all, stop editing! Happy publishing. */:
sudo nano /var/www/<strong>domain.com</strong>/wp-config.php define('MULTISITE', true); define('SUBDOMAIN_INSTALL', false); define('DOMAIN_CURRENT_SITE', 'vkapoor.co'); define('PATH_CURRENT_SITE', '/'); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1);
Save and exit the file with CTRL + X , followed by Y and ENTER.
Likewise, edit the .htaccess file, replace the whole content of the .htaccess file
sudo nano /var/www/domain.com/.htaccess RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L]
Save and exit the file with CTRL + X , followed by Y and ENTER.
Once you’re done editing the wp-config.php and .htaccess files, login to your WordPress site.
You should now be able to create multiple site in your WordPress multisite network from
Read more: Top CSS Frameworks For Web Development In 2020
My Sites >> Network Admin >> Sites
Enjoy your WordPress Multisite Network on Ubuntu
There it is! Now that you’ve properly installed and setup your WordPress Multisite network on Ubuntu, you can now enjoy efficient managing for your blogs or websites. By doing this, you are able to have more control and maximize the potential of using WordPress and your own server. How are you deciding to use your multisite network?