httpd.conf - Setting up a second "localhost" to a different localpath - apache

I'm using XAMPP on my Windows 7 computer when doing web projects. In my httpd.conf file, DocumentRoot is set up simple, like this:
DocumentRoot "D:/Users/Thinkpad/DropBox/MAMP"
<Directory "D:/Users/Thinkpad/DropBox/MAMP">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
This location is used for work projects, and now I want a separate location just like this one, for private projects. Just have it to point to a different localpath, D:/Users/Thinkpad/DropBox/Web, and preferrably name it something other than localhost. Something like private or something. So my URL will end up looking like this http://private/mywebproject
I've tried looking at documentation for this, but I can't get it to work. Do I need to edit my hosts file for it to work? And what else needs to be set in httpd.conf file?
Edit: So here's the final solution from the httpd-vhosts file
<VirtualHost private:80>
DocumentRoot "D:/Users/Thinkpad/Dropbox/Web"
ServerName private
ErrorLog "logs/dropbox.local-error.log"
CustomLog "logs/dropbox.local-access.log" combined
<Directory "D:/Users/Thinkpad/Dropbox/Web">
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost localhost:80>
DocumentRoot "D:/Users/Thinkpad/Dropbox/MAMP"
ServerName private
ErrorLog "logs/dropbox.local-error.log"
CustomLog "logs/dropbox.local-access.log" combined
<Directory "D:/Users/Thinkpad/Dropbox/MAMP">
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
I had to add the regular localhost as well, even though it was already defined in httpd.conf file.
Also, hosts-file needed to have these two lines:
127.0.0.1 localhost
127.0.0.1 private

You have to add new virtual host
by default in C:\xampp\apache\conf\extra\httpd-vhosts.conf add something like
<VirtualHost *:80>
ServerName private.localhost
DocumentRoot D:/Users/Thinkpad/DropBox/private
</VirtualHost>
and after that you have to edit windows hosts file
append this
127.0.0.1 private.localhost
then restart the xammp
You may take a look to one project that makes this easy https://github.com/vkdimitrov/VhostsEditor

Related

XAMPP virtualhost site with all configs not working

I am trying to run site my.com locally on XAMPP's apache server. Here my configurations in httpd-vhosts.conf file in the path ...\XAMPP\apache\conf\extra:
<VirtualHost *:80>
DocumentRoot "D:/IDEs/XAMPP/htdocs"
ServerName localhost
<Directory "D:/IDEs/XAMPP/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/IDEs/Websites/my.com"
ServerName my.com
<Directory "D:/IDEs/Websites/my.com">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Also, I remembered to add two lines in the hosts file, with is located in C:\Windows\System32\drivers\etc:
127.0.0.1 localhost
127.0.0.1 my.com
However, when I enter via link 'my.com' with enabled apache server, I've got only page with folder directories, which are in htdocs XAMPP's folder.
I have checked a lot of videos and stackoverflow questions, but nothing helped.
I would be pleased if you could help me with solving this issue.
first you should arrange directories on httpd.conf
example:
<Directory "C:/SERVER~1/web/site1">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "C:/SERVER~1/web/site2">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
and then arrange vhosts.conf like this
example :
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.site1.com
DocumentRoot "C:/SERVER~1/web/site1"
</VirtualHost>
<VirtualHost *:80>
ServerName site1.com
DocumentRoot "C:/SERVER~1/web/site1"
</VirtualHost>
<VirtualHost *:80>
ServerName www.site2.com
DocumentRoot "C:/SERVER~1/web/site2"
</VirtualHost>
<VirtualHost *:80>
ServerName site2.com
DocumentRoot "C:/SERVER~1/web/site2"
</VirtualHost>
After five days-night of reading, searching, trying, I finnally fould the solution and done it in some steps:
First of all, forget about every file, and concentrate on the httpd-ssl.conf which is located in D:\IDEs\XAMPP\apache\conf\extra.
Second:
find the line "SSL Virtual Host Context" which has been commented. And below, find the line <VirtualHost _default_:443>.or simmilar. Then change it to <VirtualHost *:443>.
Third, change document root to the path of xampp's htdocs, for example, "D:/XAMPP/htdocs". Also, change ServerName from www.example.com:443 or similar, to localhost.
Here we done.
And Finally, after line </VirtualHost>, insert code
<VirtualHost *:443>
DocumentRoot "D:/IDEs/Websites/my.com"
ServerName my.com
<Directory "D:/IDEs/Websites/my.com">
Require all granted
</Directory>
</VirtualHost>
Change Document Root and Directory paths to your website location. And Servername to your server name.
RESTART APACHE
it works for me.
I also understood than some website uses SSL on localhost while the others not.
SO if you have exception like Apache/2.4.37 (Win32) OpenSSL/1.0.2p PHP/7.0.33 Server at my.com Port 443 you shold add your virtualhost configs into httpd-ssl.conf file.
If you got like ... Port 80 add yourl virtualhost configs into httpd-vhosts.conf

Two sites with Apache virtual hosts

I'm working on 2 different sites. I have local copies of them checked out from SVN at my home folder, and symbolic links in /var/www pointing to them.
I've set up virtual hosts in httpd.conf like this:
<VirtualHost *:80>
DocumentRoot /var/www/siteA
ServerName 192.168.0.10/siteA
<Directory "/var/www/siteA">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/siteB
ServerName 192.168.0.10/siteB
<Directory "/var/www/siteB">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I would like to be able to access the sites with 192.168.0.10/siteA and /siteB, but when typing the address in browser, it throws a 404 and apache error log says: "File does not exist: /var/www/siteA/siteA".
What am I doing wrong and where does the second "/siteA" come from?
You've got too much configuration in there. /SiteA and /SiteB should be paths relative to your site root, you can't have different sites on the same host header, which in this case is "192.168.0.10". If you want to bind that address to the configuration, something along the lines of the following should work.
<VirtualHost 192.168.0.10:80>
DocumentRoot /var/www
ServerName 192.168.0.10
<Directory "/var/www">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
If you now browse to /SiteA, /SiteB you should see the contents of your directory as long as your symlinks are correct. You also need to ensure you have the "NameVirtualHost" directive set correctly in your httpd.conf.

Install magento twice on the same server

I am making some test in one magento installation, but now i want to start again because all of the garbage i added to the first installation, but I need to keep it installed to see things on the admin panel and on the code...
How can I make this second installation? I tried once but the server, apache, redirects me to the second installation and I wasn't able to see the first again.
Thanks!
You can have as many installations as you want doing :
1) Creating the folders
/www/docs/magento01
/www/docs/magento02
2) Creating the virtual hosts (as vjtemplates said):
<VirtualHost *:80>
DocumentRoot /www/docs/magento01
ServerName local.magento01
<Directory "/www/docs/magento01">
SetEnv APPLICATION_ENV "development"
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/docs/magento02
ServerName local.magento02
<Directory "/www/docs/magento02">
SetEnv APPLICATION_ENV "development"
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
3) Change your HOSTS (if you working in your local machine)
ubuntu: /etc/hosts
windows: C:Windows\system32\drivers\etc\hosts.txt
And add the lines
127.0.0.1 local.magento01
127.0.0.1 local.magento02
4) Restart your server and type in your browser either local.magento01 or local.magento02 and you should be able to see your websites.
Cheers
On your Apache httpd-vhost.conf, you can add as many Document Root as you want.
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog #rel_logfiledir#/dummy-host.example.com-error_log
CustomLog #rel_logfiledir#/dummy-host.example.com-access_log common
</VirtualHost>

apache virtual host not opening when given subfolders

I have set up a virtual host in apache this morning and it works well for the root folder.
Settings for virtual hosts -
<VirtualHost *:80>
ServerName dev.abcworld.com
ServerAlias dev.abcworld.com
DocumentRoot C:\nem\wamp\www\dev\html
<Directory C:\nem\wamp\www\dev\html>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName prod.abcworld.com
ServerAlias prod.abcworld.com
DocumentRoot C:\nem\wamp\www\prod\html
<Directory C:\nem\wamp\www\prod\html>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Example :
dev.abcworld.com - works well
prod.abcworld.com - works well
but when ever I click a link in dev.abcworld.com which is supposed to redirect to another page in the project like dev.abcworld.com/payments or dev.abcworld.com/somthing or dev.abcworld.com/anything it always says "The requested URL /apartments was not found on this server."
why does is works only on the root folder? how can i make this work for the whole project both in dev and prod?
open your browser console and check to which path it is sending request.

Multiple versions of a website each with its own root directory using Apache

I have multiple versions of my website. Each resides in its own folder, for example:
site_v1/
index.html
page1.html
site_v2/
index.html
page1.html
How can I configure apache so that each version of the site has its own definition of the root directory?
In other words, I want site_v1/index.html to think the root directory is site_v1, and site_v2/index.html to think the root directory is site_v2
You are looking for the VirtualHost directive.
Apache manual on virtual hosts
As #Pekka wrote, you are indeed looking for the VirtualHost directive, but I though I might add an example configuration for your virtual host configuration. This should be placed in your httpd.conf file, edited to your preference, and remember to fill in the full path:
NameVirtualHost v1.yoursite.com:80
<VirtualHost v1.yoursite.com:80>
ServerName v1.yoursite.com
ServerAlias v1.yoursite.com
DocumentRoot /path/to/site_v1
ErrorLog /path/to/prefered/error.log
CustomLog /path/to/prefered/access.log combined
<Directory /path/to/site_v1>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
NameVirtualHost v2.yoursite.com:80
<VirtualHost v2.yoursite.com:80>
ServerName v2.yoursite.com
ServerAlias v2.yoursite.com
DocumentRoot /path/to/site_v2
ErrorLog /path/to/prefered/error.log
CustomLog /path/to/prefered/access.log combined
<Directory /path/to/site_v2>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
If you want, you may chose to use a different access/error log for each version of your site. Just change the name/path to the log file, and you're done. /path/to are the path to the site folder, and v1.yoursite.com & v2.yoursite.com should be changed to the relative domains you want to use for each version. If you don't want to change the log files, remove the ErrorLog and CustomLog directives and I'll default to the main log files set in httpd.conf