Local Setup of Multisite on LAMP

I had some issues this month setting up locally several multisites on LAMP so I’ve decided to draft my complete flow for further use (and get other opinions on it as well).

The sites were different in nature, some were running on Apache, others – on nginx, running on subdomain or subfolder-related structure.

Placing the data and the database

I place the WordPress folder in my server’s DocumentRoot folder, such as /var/www or /opt/lampp/htdocs.  I’m also creating a database and importing the dump over there:

[sql] CREATE DATABASE somedb DEFAULT CHARACTER SET

utf8 DEFAULT COLLATE utf8_general_ci; [/sql]

[bash]

mysql -umydbuser -p –database=somedb < /path/to/my-db-dump.sql

[/bash]

Then I configure the wp-config.php (or whatever) config file accordingly with the correct credentials.

Mapping the host

My first step is mapping a dedicated domain such as somesite.dev or the real domain (only when needed to test temporarily) to work. Adding a line in /etc/hosts:

[shell]

127.0.0.1  somesite.dev

[/shell]

Virtual Host

Since the domain is already redirecting to localhost (127.0.0.1), the server needs a virtual host to resolve it properly and load the proper folder from Apache when the domain is hit, so in my httpd-vhosts.conf (or just httpd.conf or similar file, depending on the setup) adding a new virtual host:

[bash]

<VirtualHost *:80>
DocumentRoot /var/www/somesite
ServerName somesite.dev
ServerAlias somesite.dev

<Directory /var/www/somesite/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

[/bash]

Restarting the server should set the server so when you hit somesite.dev in the address bar, the /var/www/somesite folder is loaded (where the WordPress project resides).

Permalinks structure

I’ve used different .htaccess rules to map my site properly, but this one seems to be most friendly to my environment:

[shell]

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ – [L]

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]

[/shell]

WP-CLI test

I have WP-CLI set globally, so I navigate to the /var/www/somesite folder and run a quick `wp` call.

wp

>Normally, a quick manual of the tool would be listed with “how to use”, however if the index.php run fails then a log would be displayed with some technical issues to be solved (warnings, missing classes, incorrect execution, fatal errors…). Solving them would facilitate the process later, naturally.

Error log

After the first setup I monitor the error_log server file for a couple of days, the first run might be a complete failure too until all error_log entries are resolved. This could be an infinite loop (due to a wrong redirect), missing classes or libraries, some PHP-specific dependency/function missing etc. I would normally address the code-related issues to the project, try to sync the version as much as possible with the server (or use Vagrant for a mirror setup accordingly) and mock classes/install libraries whenever needed to resolve the conflict and unify the environment.

Permalinks

After all there could be a setup or cache-related issue with the permalinks, I check my mod_rewrite rules (whether it’s running at the moment and is properly set for that virtual host/folder) and re-save the permalinks from the admin settings to flush the cache.

 


My name is Mario Peshev, a global SME Business Advisor running digital businesses for 20 the past years.

Born in Bulgaria, Europe, I gained diverse management experience through my training work across Europe, North America, and the Arab world. With 10,000+ hours in consulting and training for organizations like SAP, VMware, CERN, I’ve dedicated a huge amount of my time to helping hundreds of SMEs growing in different stages of the business lifecycle.

My martech agency DevriX grew past 50 people and ranks as a top 10 WordPress global agency and Growth Blueprint, my advisory firm, has served 400+ SME founders and executives with monthly ongoing strategy sessions.


Follow me at:

Latest Editions:

Browse by Category

Latest Answers: