Create Apache Virtual Host: Step-by-Step Guide

In summary: You can find the line that should say something like this:ServerName phpweb20 127.0.0.1If you don't have this line in place, you can get it by typing this:cat /etc/hosts
  • #1
sean1234
40
0
I am attempting to create a virtual host here on my machine. I assume the place to do this is in the /etc/apache2/sites-enabled/000-default file. The file currently reads this:

NameVirtualHost *
<VirtualHost *>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/$ /apache2-default/
</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
ServerSignature On

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>

</VirtualHost>



This is the information I am want to put in the host:

<VirtualHost 192.168.0.80>
ServerName phpweb20
DocumentRoot /var/www/phpweb20/htdocs

<Directory /var/www/phpweb20/htdocs>
AllowOverride All
Options All
</Directory>

php_value include_path .:/var/www/phpweb20/include:/usr/local/lib/pear
php_value magic quotes_gpc off
php_value register_globals off
</virtualHost>





So I changed the file to this:

NameVirtualHost *
<VirtualHost 192.168.0.80>
ServerAdmin webmaster@localhost
ServerName phpweb20

DocumentRoot /var/www/phpweb20/htdocs
<Directory />
Options All
AllowOverride All
</Directory>
<Directory /var/www/phpweb20/htdocs>
Options All
AllowOverride All
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/$ /apache2-default/
</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
ServerSignature On

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>
php_value include_path .:/var/www/phpweb20/include:/usr/local/lib/pear
php_value magic_quotes_gpc off
php_value register_globals off

</VirtualHost>


When I restart apache in the terminal I get this message:

* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Sun Apr 13 12:26:55 2008] [warn] NameVirtualHost *:0 has no VirtualHosts
httpd (no pid file) not running
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Sun Apr 13 12:27:05 2008] [warn] NameVirtualHost *:0 has no VirtualHosts
 
Computer science news on Phys.org
  • #2
It seems you haven't registered the servername in your DNS.
 
  • #3
Nor in the /etc/hosts.
 

FAQ: Create Apache Virtual Host: Step-by-Step Guide

What is a virtual host in Apache?

A virtual host in Apache is a method of hosting multiple websites on a single server. It allows for the use of a single IP address to serve different websites, each with its own domain name. Virtual hosts are commonly used in shared hosting environments where multiple websites are hosted on a single server.

How do I create a virtual host in Apache?

To create a virtual host in Apache, you will need to follow these steps:

  1. Open the Apache configuration file (usually located at /etc/apache2/apache2.conf).
  2. Add a new virtual host block with the desired domain name and directory path.
  3. Save the changes and restart the Apache server.

What is the purpose of a virtual host file?

A virtual host file contains the configuration settings for a specific virtual host in Apache. It allows for the customization of settings such as domain name, directory path, and access permissions for a specific website hosted on the server. Virtual host files make it easier to manage multiple websites on a single server.

Can I have multiple virtual hosts on one IP address?

Yes, you can have multiple virtual hosts on one IP address using the same Apache server. Virtual hosts allow for the use of multiple domain names on a single server, so multiple virtual hosts can be configured to use the same IP address.

How do I troubleshoot issues with virtual hosts in Apache?

If you are experiencing issues with virtual hosts in Apache, here are a few troubleshooting steps you can follow:

  1. Check the syntax of your virtual host file to ensure it is correct.
  2. Make sure the domain name is correctly pointed to the server's IP address.
  3. Check the file and directory permissions for the virtual host's directory.
  4. Restart the Apache server to apply any changes made to the virtual host configuration.

Similar threads

Replies
6
Views
1K
Back
Top