Link to home
Start Free TrialLog in
Avatar of rafaelrgl
rafaelrgl

asked on

How to configure virtual host in apache2 to have its own root folder

Here is my question, I want to have 2 wordpress installation inside my VM.

folder structure:
/var/www/site1
/var/www/site2

url structure:
site1:    ipaddress/
site2:    ipaddress/site2

the problem I am facing is that I want site2 independent without access to site1, so when I put in on link inside site2 like this   /page1.html it should not go to ipaddress/page1.html, but it should go  to ipaddress/site2/page1.html So all resources would be block to current root of site2.

So how should be the config inside apache2. I am using alias, but it let all requests from site2 got to root of site 1. that can not happen.
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

If you are going to be using the IP address to access the sites then your only option is to use aliases i.e.

root
   /site1
     files
   /site2
     files

Open in new window

<IfModule alias_module>
  Alias /site1 "/home/site1"
  Alias /site2 "/home/site2"
  <Directory "/home">
    Options Indexes FollowSymLinks MultiViews ExecCGI
    AllowOverride All
	Require all granted
  </Directory>  
</IfModule>

Open in new window


Alias one (site1) would be accessed by http://ipaddress/site1
Alias two (site2) would be accessed by http://ipaddress/site2

To have them on different urls you would need to setup different domain names for each - for instance you can do the following. Create the following DNS / Hosts entries
site1.local => ipaddress
site2.local => ipaddress 

Open in new window


Then setup your virtual hosts as

<VirtualHost *:80>
    DocumentRoot "/home/site1"
    ServerName site1.local
    ErrorLog "logs/site1.local-error.log"
    CustomLog "logs/site1.local-access.log" common
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "/home/site2"
    ServerName site2.local
    ErrorLog "logs/site2.local-error.log"
    CustomLog "logs/site2.local-access.log" common
</VirtualHost>

Open in new window


Now you would access them as
http://site1.local
http://site2.local

Open in new window

Avatar of skullnobrains
skullnobrains

and you'd need to set the base directory in your wordpress config to the proper one so you don't get redirected to the webserver's root. by default wordpress assumes it is installed at the webserver's root.

using named-based virtual hosting or different server ports for each site is much simpler.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Should work as well providing wp uses the base html tag and relative links. Given that s you speaking i assume you checked or know
No base tag - links are absolute.
RewriteEngine On
RewriteBase /site1/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site1/index.php [L]

Open in new window

@jh
my bad. did not notice it acted at the rewrite level... interesting ( and slightly double-edged ) feature. thanks for pointing this out
best regards