Reputation: 508
I have 2 websites i want to host on a Linux machine using Apache server. Since at this point i am unable to acquire a domain name, i access the server through IP, since I'm not required to have one yet.
The first site is comprised of a few HTML pages and is located in /var/hostroot/lifeonearth/{all files here}
and the other is comprised of several PHP pages located in /var/hostroot/webDarts/{all files here}
.
By default when i go to my IP address, it takes me to the default "Your Apache server is working" page. So from here on, how do i make it so that i can access each site through some sort of subdomain like lifeonearth.(my IP)
or webDarts.(my IP)
or, am I supposed to access them throug different ports. If it's the latter, how do I go about it?
Upvotes: 0
Views: 830
Reputation: 928
We have 2 website names.
1. example1.test.local (/var/www/example1)
2. example2.test.local (/var/www/example2)
Now Lets create two files called example1
and example2
in /etc/apache2/sites-available
.
example1
file looks like as follows
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example1
ServerName example1.test.local
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/example1>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
as the same way create another file called example2
and modify the following lines
DocumentRoot /var/www/example2
ServerName example2.test.local
and
<Directory /var/www/example2>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
rest of the file will same as example1.
Then enable those two sites
a2ensite example1
a2ensite example2
Then do apache service restart.
Now we have to do DNS pointing
If your Linux machine is LOCAL then go to your Windows machine where you want to access these websites and open the following file C:\Windows\System32\drivers\etc\hosts
and mention your ip and website name
192.168.249.101 example1.test.local
192.168.249.101 example2.test.local
Thats it! If you found any difficulties please let me know.
I have replicated this scenario at my end and it works for me. Hope it will work for you!
Upvotes: 0