**WordPress, but serving multiple sites/subdomains?**
Read it on my blog, it has a nicer image/text layout.
Besides my technical blog (blog.rozman.info), I wanted to transfer my other writings from Blogger to my WordPress blog. But those writings are stories in slovenian language. I didn’t want to mix it in the same blog. I wanted to have my stories on a separate subdomain (zgodbe.rozman.info).
So I played with it for 2 hours, googled, failed, repeated and now it works. Here’s the summary of steps:
1. DNS
- I updated my DNS records. I added A record zgodbe.rozman.info to point to the IP of my router.
2. Reverse proxy
I updated my reverse proxy (nginx) settings:
- In /sites-available directory: I copied (reused) the existing blog vhosts file to new one (zgodbe.rozman….)
- I edited it and changed all blog.rozman.info to zgodbe.rozman.info
3. In /sites-enabled I created new symlink to the file above
ln -s /etc/nginx/sites-available/zgodbe.rozman.info.vhost /etc/nginx/sites-enabled/zgodbe.rozman.info.vhost
4. Asked for a new Letsencrypt certificate:
certbot --nginx -d zgodbe.rozman.info
3. Activate multisite setup in WP
- disable all plugins
- wp-config.php:
define('WP_ALLOW_MULTISITE', true); //first thing to add, then 'multi-site menu appear in WP'
Then, WP Multisite menu appears in WP. When activating install of multi-site, it creates some lines that I added to wp-config.php and .htaccess
4. Editing wp-config.php and .htaccess
I copied the configuration code WP showed in previous step to:
wp-config.php
define( 'MULTISITE', true );define( 'SUBDOMAIN_INSTALL', true );define( 'DOMAIN_CURRENT_SITE', 'blog.rozman.info' );define( 'PATH_CURRENT_SITE', '/' );define( 'SITE_ID_CURRENT_SITE', 1 );define( 'BLOG_ID_CURRENT_SITE', 1 );
… and .htaccess:
RewriteEngine OnRewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]RewriteBase /RewriteRule ^index\.php$ - [L]# add a trailing slash to /wp-adminRewriteRule ^wp-admin$ wp-admin/ [R=301,L]RewriteCond %{REQUEST_FILENAME} -f [OR]RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^ - [L]RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
Welp, the old blog site is broken!
After these changes, my blog didn’t work anymore. Layout was off, css obviously didn’t load, images were missing and I couldn’t login because of broken redirects.
So I did some dark magic to the database (I didn’t make this up, I found hints in wp-config.php file that pointed to https://www.turnkeylinux.org/docs/wordpress/multisite
So I did:
mysql --defaults-extra-file=/etc/mysql/debian.cnf <<EOFUSE wordpress;UPDATE wp_options SET option_value='https://blog.rozman.info' WHERE option_name='home';UPDATE wp_options SET option_value='https://blog.rozman.info' WHERE option_name='siteurl';EOF
This fixed paths to my media (images) and the site wasn’t broken anymore.
Creating new site
Finally, I can create new site (Network admin/sites/add new site). It allowed me to add site as zgodbe.blog.rozman.info. I thought this is a fixed sub-sub domain and I didn’t want to create it at first. Then I created it and edited the name of the new subdomain to zgodbe.rozman.info
Can’t login to new site!
Yeah, the new site worked, but when I wanted to log-in, I couldn’t (error: please allow cookies something…)
wp-config.php
define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST']);
Great, login to the new WP site works!
I can’t upload bigger images!
I also noticed I can not upload bigger images to my blog posts so I increased upload sizes (in wp-config.php):
//filesizesdefine('WP_MEMORY_LIMIT', '256M');define('UPLOAD_MAX_FILESIZE', '100M');define('POST_MAX_SIZE', '100M');
I also increased post size in my reverse proxy (nginx.conf):
http {...client_max_body_size 200M;...
End result
Now my WP can handle multiple sites. Users are shared among them, but plugins are not. I have to reinstall plugins to the new site. I found out I don’t need to reinstall plugin, just click ‘network activate’ for every installed plugin.
I’m quite satisfied it works because I avoided reconfiguration of WP for several months.
Tags: #homelab #selfhosting #wordpress #multisite
https://blog.rozman.info/wordpress-but-serving-multiple-sites-subdomains/
#homelab #multisite #selfhosting #WordPress