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.
LVL 1
rafaelrglAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
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

0
skullnobrainsCommented:
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.
0
Julian HansenCommented:
and you'd need to set the base directory in your wordpress config
We do that in the .htaccess
RewriteBase /site1
Or
RewriteBase /site2
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

skullnobrainsCommented:
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
0
Julian HansenCommented:
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

0
skullnobrainsCommented:
@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
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Installation

From novice to tech pro — start learning today.