Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache VirtualHost and localhost

I'm working with XAMPP on Mac OS X.

I'm trying to run a Symfony website properly for a client, and I really don't know Symfony (yet). I just want to install and launch it.

I've changed my /etc/hosts file this way:

127.0.0.1 www.mysite.local 

And the httpd.conf file this way:

<VirtualHost *:80>   ServerName www.mysite.local   DocumentRoot /Applications/MAMP/htdocs/mysite/web   DirectoryIndex index.php   <Directory /Applications/MAMP/htdocs/mysite/web>     AllowOverride All     Allow from All   </Directory>   Alias /sf /Applications/MAMP/htdocs/mysite/lib/vendor/symfony/data/web/sf   <Directory "/Applications/MAMP/htdocs/mysite/lib/vendor/symfony/data/web/sf">     AllowOverride All     Allow from All   </Directory> </VirtualHost> 

Now, the site is working (yay!), but I can't access any more any of my other local sites because localhost is rendered as www.mysite.local.

Where am I wrong?

like image 461
Angelica Rosa Avatar asked Jun 11 '12 13:06

Angelica Rosa


People also ask

What is Virtualhost in Apache server?

The Apache HTTP server supports virtual hosts, meaning that it can respond to requests that are directed to multiple IP addresses or host names that correspond to the same host machine. You can configure each virtual host to provide different content and to behave differently.

Where is virtual host file Apache?

Create a Virtual Hosts By default on Ubuntu systems, Apache Virtual Hosts configuration files are stored in /etc/apache2/sites-available directory and can be enabled by creating symbolic links to the /etc/apache2/sites-enabled directory.

What is the difference between name-based virtual hosting and IP based virtual hosting?

IP-based virtual hosts use the IP address of the connection to determine the correct virtual host to serve. Therefore you need to have a separate IP address for each host. With name-based virtual hosting, the server relies on the client to report the hostname as part of the HTTP headers.


1 Answers

This worked for me!

To run projects like http://localhost/projectName:

<VirtualHost localhost:80>    ServerAdmin localhost     DocumentRoot path/to/htdocs/     ServerName localhost </VirtualHost> 

To run projects like http://somewebsite.com locally:

<VirtualHost somewebsite.com:80>      ServerAdmin [email protected]      DocumentRoot /path/to/htdocs/somewebsiteFolder      ServerName www.somewebsite.com      ServerAlias somewebsite.com </VirtualHost> 

The same for other websites:

<VirtualHost anothersite.local:80>      ServerAdmin [email protected]      DocumentRoot /path/to/htdocs/anotherSiteFolder      ServerName www.anothersite.local      ServerAlias anothersite.com </VirtualHost> 
like image 63
Ganatra Avatar answered Oct 14 '22 11:10

Ganatra