Tomi<p>**<b>WordPress, but serving multiple sites/subdomains?</b>**</p><p>Read it <a href="https://blog.rozman.info/wordpress-but-serving-multiple-sites-subdomains/" rel="nofollow noopener" target="_blank">on my blog</a>, it has a nicer image/text layout.</p><p>Besides my technical blog (blog.rozman.info), I wanted to transfer my other writings from Blogger to my 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).</p><p>So I played with it for 2 hours, googled, failed, repeated and now it works. Here’s the summary of steps:</p><p><strong>1. DNS</strong></p><ol><li>I updated my DNS records. I added A record zgodbe.rozman.info to point to the IP of my router.</li></ol><p><strong>2. Reverse proxy</strong></p><p>I updated my reverse proxy (nginx) settings:</p><ol><li>In /sites-available directory: I copied (reused) the existing blog vhosts file to new one (zgodbe.rozman….)</li><li>I edited it and changed all blog.rozman.info to zgodbe.rozman.info</li></ol><p>3. In /sites-enabled I created new symlink to the file above </p><pre><code>ln -s /etc/nginx/sites-available/zgodbe.rozman.info.vhost /etc/nginx/sites-enabled/zgodbe.rozman.info.vhost</code></pre><p>4. Asked for a new Letsencrypt certificate:</p><pre><code>certbot --nginx -d zgodbe.rozman.info </code></pre><p><strong>3. Activate multisite setup in WP</strong></p><ol><li>disable all plugins</li><li>wp-config.php:</li></ol><pre><code>define('WP_ALLOW_MULTISITE', true); //first thing to add, then 'multi-site menu appear in WP'</code></pre><p>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</p><p><strong>4. Editing wp-config.php and .htaccess</strong></p><p>wp-config.php</p><pre><code>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 );</code></pre><p><strong>Welp, the old blog site is broken!</strong></p><p>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.</p><p>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 <a href="https://www.turnkeylinux.org/docs/wordpress/multisite" rel="nofollow noopener" target="_blank">https://www.turnkeylinux.org/docs/wordpress/multisite</a></p><p>So I did:</p><pre><code>mysql --defaults-extra-file=/etc/mysql/debian.cnf <<EOFUSE wordpress;UPDATE wp_options SET option_value='<a href="https://blog.rozman.info" rel="nofollow noopener" target="_blank">https://blog.rozman.info</a>' WHERE option_name='home';UPDATE wp_options SET option_value='<a href="https://blog.rozman.info" rel="nofollow noopener" target="_blank">https://blog.rozman.info</a>' WHERE option_name='siteurl';EOF</code></pre><p>This fixed paths to my media (images) and the site wasn’t broken anymore.</p><p><strong>Creating new site</strong></p><p>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 </p><p><strong>Can’t login to new site!</strong></p><p>Yeah, the new site worked, but when I wanted to log-in, I couldn’t (error: please allow cookies something…)</p><p>wp-config.php</p><pre><code>define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST']);</code></pre><p>Great, login to the new WP site works!</p><p><strong>I can’t upload bigger images!</strong></p><p>I also noticed I can not upload bigger images to my blog posts so I increased upload sizes (in wp-config.php):</p><pre><code>//filesizesdefine('WP_MEMORY_LIMIT', '256M');define('UPLOAD_MAX_FILESIZE', '100M');define('POST_MAX_SIZE', '100M');</code></pre><p>I also increased post size in my reverse proxy (nginx.conf):</p><pre><code>http {...client_max_body_size 200M;...</code></pre><p><strong>End result</strong></p><p>Now my WP can handle multiple sites. Users are shared among them, but plugins are not. <s>I have to reinstall plugins to the new site.</s> I found out I don’t need to reinstall plugin, just click ‘network activate’ for every installed plugin.</p><p>I’m quite satisfied it works because I avoided reconfiguration of WP for several months.</p><p></p><p>Tags: #homelab #selfhosting #wordpress #multisite</p><p><a href="https://blog.rozman.info/wordpress-but-serving-multiple-sites-subdomains/" class="" rel="nofollow noopener" target="_blank">https://blog.rozman.info/wordpress-but-serving-multiple-sites-subdomains/</a></p><p><a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://blog.rozman.info/tag/homelab/" target="_blank">#homelab</a> <a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://blog.rozman.info/tag/multisite/" target="_blank">#multisite</a> <a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://blog.rozman.info/tag/selfhosting/" target="_blank">#selfhosting</a> <a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://blog.rozman.info/tag/wordpress/" target="_blank">#WordPress</a></p>