WordPress Multisite Domain setup

From PheonixSolutions
Jump to navigation Jump to search

1. Backup Files and DB

[edit]

Backup the main site directory.

[edit]
  1. cd /var/www
  1. cp -pr html html_bkp_July2020

Get DB details from wp-config.php and take a DB backup. 


[edit]
  1. mysqldump -u root DBname > DBbackupfile.sql

2.Multisite setup

[edit]

Step 1 : Edit wp-config.php File

[edit]

cd /var/www/html

Find this line: /* That’s all, stop editing! Happy blogging. */ (usually at the end of the file). Then add the following line to enable the Network feature.

define('WP_ALLOW_MULTISITE', true);

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_aaafcc7376574425875643b60c700801-media-image1.png

save the file.

Step 2: Network setup

[edit]

Open the wp-admin in browser and goto tools->Network Setup and click install.

Go to your WordPress Dashboard in your Web browser. You now see a new item, labeled Network Setup, under the Tools menu. Click the Network Setup link in the Tools menu. If you have any plugins activated, please deactivate them for a moment.

Please make sure which plugins you deactivate take screenshot.

Step 3: Deactivate Plugins

[edit]

Please make a note of active plugins first.

After click install and you will get, complete the steps to enable the features for creating a network of sites. After you complete the steps enable the deactivated plugins.

Note: Please make sure the activated plugins once completed Step 4.

Step 4: Update wp-config.php and .htaccess

[edit]


Network Admin--->Settings--->Network Setup---> Select Sub Directory--->ClickInstall.

We can wp-config.php and .htaccess details from this NetworkSetup

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_aaafcc7376574425875643b60c700801-media-image3.png

Update config

[edit]

Add the following to your wp-config.php file in /var/www/html/ above the line reading /* That’s all, stop editing! Happy blogging. */:

define('MULTISITE', true);

define('SUBDOMAIN_INSTALL', false);

define('DOMAIN_CURRENT_SITE', 'domain.com');

define('PATH_CURRENT_SITE', '/');

define('SITE_ID_CURRENT_SITE', 1);

define('BLOG_ID_CURRENT_SITE', 1);

define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST']);

define( 'BP_ENABLE_MULTIBLOG', true );

replace the domain.com into your domain.

Update .htaccess

[edit]

Add the following to your .htaccess file in /var/www/html/, replacing other WordPress rules:

RewriteEngine On

RewriteBase /

RewriteRule ^index\.php$ - [L]

  1. 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]

and delete the existing rule on this file and add this new file and save it.

Step 5: Add Subsite

[edit]

Create new site in the network

With the WordPress Network now fully enabled and configured, you see a new link in the menu at the top right of your WordPress Dashboard called My Sites. To create a new site, go to My Sites -> Network Admin -> Sites.

https://wiki.pheonixsolutions.com/images/f/f0/Vertopal_aaafcc7376574425875643b60c700801-media-image2.png

Click Add New button and enter site URL, site title, admin email.

Step 6: Update WordPress

[edit]

In the network admin dashboard, click on Sites to show the listing of all the subsites, and then click on edit for the subsite you want to map to. In our example, this is subsite1.mynetwork.com.

In the Site Address (URL) field, enter the full URL to the domain name you’re mapping – https://mappeddomain.org – and click save.

Step 7:Edit wp-config.php

[edit]

If you get an error about cookies being blocked when you try to log in to your network subsite (or log in fails with no error message), open your wp-config.php file and add this line after the other code you added to create the network:

define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST']);

3. Install letsencrypt SSL

[edit]

Note: This steps can be used only in ubuntu / debian OS. If you are having using CentOS, you need to adjust your configuration accordingly and install SSL packages.

SSL installation for main site:



Step 1. Installing Certbot
:

[edit]
  1. sudo add-apt-repository ppa:certbot/certbot

  1. sudo apt-get update

  1. sudo apt-get install python-certbot-apache

You got error pls refer this link for Apache
https://certbot.eff.org/lets-encrypt/ubuntubionic-apache

You got error pls refer this link for Nginx
https://certbot.eff.org/lets-encrypt/centosrhel7-nginx

Step 2. Setup virtual Hosts for domain:

[edit]

1.Modifying the default configuration file located at /etc/apache2/sites-available/000-default.conf directly, let’s make a new one at /etc/apache2/sites-available/your_domain.conf. OR copy this 000-default.conf and rename it for your_domain.conf.

sudo nano /etc/apache2/sites-available/your_domain.conf

Add the following to the new file :(Replace your domain name )

<VirtualHost *:80>

ServerAdmin webmaster@localhost

ServerName your_domain

ServerAlias www.your_domain

DocumentRoot /var/www/your_domain

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Save and close the file when you are finished.

2.Let’s enable the file with the a2ensite tool:

sudo a2ensite your_domain.conf

3.Disable the default site defined in 000-default.conf:

sudo a2dissite 000-default.conf

4.let’s test for configuration errors:

sudo apache2ctl configtest

You should see the following output:

Output

Syntax OK

5.Restart Apache to implement your changes:

sudo systemctl restart apache2

6.Set Up the SSL Certificate:

#sudo certbot --apache -d your_domain

output like :

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.


1: No redirect - Make no further changes to the webserver configuration.

2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for

new sites, or if you're confident your site works on HTTPS. You can undo this

change by editing your web server's configuration.


Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

select no direct option (1) and Enter.

output like :

IMPORTANT NOTES:

- Congratulations! Your certificate and chain have been saved at:

/etc/letsencrypt/live/your_domain/fullchain.pem

Your key file has been saved at:

/etc/letsencrypt/live/your_domain/privkey.pem

Your cert will expire on 2018-07-23. To obtain a new or tweaked

version of this certificate in the future, simply run certbot again

with the "certonly" option. To non-interactively renew *all* of

your certificates, run "certbot renew"

- Your account credentials have been saved in your Certbot

configuration directory at /etc/letsencrypt. You should make a

secure backup of this folder now. This configuration directory will

also contain certificates and private keys obtained by Certbot so

making regular backups of this folder is ideal.

- If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate

Donating to EFF: https://eff.org/donate-le

Your certificates are downloaded, installed.Then trying to load your website in brower you see the connetion is secured.


4. Change Site URL:

Click Edit Site on dashboard and change the site url from http to https.

Some troubleshooting steps:

  1. Check the domain mapping if client use plugin to map we need to change the url through plugin if they use new method means we can change the url through network admin >> sites>> edit

  2. We got below three issues as of now.

If you get 404 error messages or

if the subsite redirects to the main website or

if http is not redirecting to https.

Please follow the below script.

go to your_domain.conf> Check the file. Document root path should be the same for both the main domain and subdomain. It should be like the below script.

<VirtualHost *:80>

ServerAdmin webmaster@localhost

ServerName visitscotland.tours

ServerAlias www.visitscotland.tours

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}

DocumentRoot /var/www/html

<Directory /var/www/html/>

Options FollowSymLinks

AllowOverride All

Require all granted

</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Note: If there is any issue that means something is wrong in the conf. files. Please check the files properly. Almost all issues occurred because of incorrect script in conf.files.

( Reference this links :
https://wordpress.org/support/article/wordpress-multisite-domain-mapping/

https://blog.pheonixsolutions.com/wordpress-multisite-domain-setup/

https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04#step-5-%E2%80%94-setting-up-virtual-hosts-(recommended)

https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-18-04 )