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:


utf8 DEFAULT COLLATE utf8_general_ci; [/sql]


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


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]  somesite.dev


Virtual Host

Since the domain is already redirecting to localhost (, 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:


<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


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:


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]


WP-CLI test

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


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


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.


Leave a Reply

Your email address will not be published. Required fields are marked *