XAMPP server document root for specific website - apache

I just installed XAMPP, and I've found how to change the document root in the Apache config file, but I only want to change it for a specific site. The reason I need this is because all of my links are absolute links (i.e. /url not just url).
I tried changing it with .htaccess, but that gave me errors saying the limited recursion had been exceeded. So I went and changed that to 200, and it too a really long time, and then said that the recursion had been exceeded.
I would use aliases, but that would mean saying that any request to / goes somewhere else.
So is there anyway for me to specify that files inside of directory dir should have their document root as dir?
Thanks.

I found the solution, but it's a bit involved. You have to change the Apace config file, and the hosts file.
In the Apache config file, I added this:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/absolute path/from/C/drive"
ServerName site.local
</VirtualHost>
Then I had to add this in the hosts file:
127.0.0.1 site.local
You can read up more on the virtual host here: http://httpd.apache.org/docs/2.2/vhosts/examples.html

Related

Using Apache VirtualHosts to serve multiple subdomains from same global ip address

I have a domain myexample.com which I would like to have multiple subdomains for, using the same IP address. I want to use Apache VirtualHosts without showing the client that redirection is happening. Here are the rules I want:
www.myexample.com gets content from the /var/www folder
www1.myexample.com gets content from the /var/www1 folder
www2.myexample.com gets content from the /var/www2 folder
The problem here is that all three must run on the same computer all on port 80 and I don't want to use 301 redirection because then the client can see what is happening. How do I configure VirtualHosts to do this? I can't figure out how to use mod_rewrite. Im running Ubuntu 14.04 with Apache2.
Thanks!
To add virtual hosts it is recommendable to write each virtual host in a separate file or write all of the virtual hosts for a specific user in one file. This improves the manageability of your server and makes it easy for you to find which file to edit when you want to change a specific setting for 1 domain.
When editing your apache2.conf file in /etc/apache2 there should be a line that says include sites-enabled/ at the bottom of your file. If it isn't there add it.
then create a new file for either your domain or your user in the sites-enabled folder. For easy editing I would do nano <filename>.conf which will open the editor and set the filename and extension.
Insert the following code into the file.
<VirtualHost 0.0.0.0:80>
ServerName www1.example.com
ServerAdmin admin#www1.example.com
DocumentRoot /var/www1
</VirtualHost>
To get everything on the same IP you could either enter *:80 in place of 0.0.0.0 to listen on all IP's on the system or enter the specific public IP address the server has for enhanced security.
Also, other directives may be required if you want to set specific PHP values or if you want to move your log files to a different file use:
CustomLog custompath/domainname.log
ErrorLog custompath/domainname.error.log
Hopes that solves your problem

Apache named-based VirtualHost configuration for multiple sites in one host

My problem is simple and i think the solution also.
I search the forums about 2-3 hours and didnt my answer... -_-' .
I got "space" in a host provider. So they gave me a "www" directory.
I have multiple folders in this directory so it's like:
www--
|
/Folder1
/Folder2
/Folder3 etc.etc.....
Each folder represents a website.
So i want to redirect each website to each folder e.g. :
www.example1.com -> Folder1
www.example2.com -> Folder2
www.example3.com -> Folder3 etc....
-BUT- without showing the subfolder of each ...
So this is NOT a solution: www.example1.com/Folder1
This IS a solution: www.example1.com .
How can i modify my .htaccess file in root WWW ?
Thanks in advance !
This has to be done through your http server configuration (like apache).
VirtualHosts is how you split multiple domains across one computer, and their respective .htaccess configuration will give you protection for your site (username/password).
If you just want to split the computer into multiple hosts, you don't need to use .htaccess.
See the following links
Here are some VirtualHost Configuration Examples
Apache HTTP Server Tutorial
Server Config Files
Excerpt from the "example's" link on "Name-Based Virtual Hosts":
<VirtualHost 172.20.30.50>
DocumentRoot /www/example1
ServerName www.example.com
# Other directives here ...
</VirtualHost>
<VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName www.example.org
# Other directives here ...
</VirtualHost>
The configuration file is usually located in /etc/apache2/apache2.conf which then reads from /etc/apache2/sites-enabled/*.conf which are essentially symbolic links to /etc/apache2/sites-available/*.conf - those files are used with the above code to accomplish the results you describe.
You may also be interested looking into nginx, an alternative to apache2.
.htaccess is not what you're looking for. Instead, read up on Name-based Virtual Host Support. You will need to add some entries to your httpd.conf file to point each domain to the correct folder in the www directory. It should be pretty straight forward.
http://httpd.apache.org/docs/2.2/vhosts/name-based.html

WAMP Server takes another DocumentRoot than I prescribed

I have WAMP Server installed, which works fine—normally.
I have changed some settings in httpd.conf, including the DocumentRoot directive. But when I start the server, and open localhost through a web browser, it gives a 403 Forbidden error. When I open the error log, I see the cause:
Warning: DocumentRoot [C:/Apache2/docs/dummy-host.example.com] does not exist
But wait... In the httpd.conf file, the DocumentRoot directive is properly set to A:/website/www/.
How is that possible?
Sounds like your editing the wrong DocumentRoot.
I use another WAMP (Wamp-Developer) but I'm guessing that your httpd.conf's DocumentRoot is the server's (non-VirtualHost) DocumentRoot.
You're looking to edit the website's (localhost's) VirtualHost block, which is either at the end of httpd.conf or in another file (that's included by httpd.conf).
Run Apache via the command line like this:
httpd -S
It will show you where the VirtualHost is.
You'll also need to make sure that your custom DocumentRoot has all the permissions set for access.
<Directory /xxxx>
order allow,deny
allow from all
...
Probably you've uncommented this line in httpd.conf:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
httpd-vhosts.conf is the file where you can put your VirtualHost directives for having them separate from the rest, but it contains a sample VirtualHost (exactly your dummy-host.example) that is causing the error.
So you have to replace the sample host with your one(s).
But you can also comment the include line and write the VirtualHost directly in your httpd.conf.
It's important to read the error log properly:
Warning: DocumentRoot [C:/Apache2/docs/dummy-host.example.com] does not exist
So we have to find a directive in some file that is trying to define a virtual host. In my case (W7pro, WAMP) I found it in the following location:
C:\wamp\bin\apache\Apache2.2.21\conf\extra\httpd-vhosts.conf
Just edit the file and delete the corresponding virtual host directives.
try 127.0.0.1, if it works. go to C:\Windows\System32\drivers\etc and add (or uncomment) the following line:
127.0.0.1 localhost
For me it was MSSQL reporting service:
SQL Server Reporting Services (MSSQLSERVER)
disabled it and it works.

How to create Virtual Host from Apache .htaccess?

I am using Apache Friends XAMPP in Windows (Local Server). I setup the virtual host in httpd-vhosts.conf in an Apache configuration directory like this
NameVirtualHost *:80
<VirtualHost *:80>
ServerName test.example.com
DocumentRoot "E:\xampp\htdocs\example"
</VirtualHost>
This works fine when I browse the URL
http://test.example.com
Is it possible to create virtual host from Apache .htaccess dynamically?
The context for VirtualHost has to be server config. See the Apache docs.
This means that the directive may be
used in the server configuration files
(e.g., httpd.conf), but not within any
or
containers. It is not allowed in
.htaccess files at all.
(Directive Dictionary)
It seems to be impossible. Because your .htaccess is used only after your host is resolved by root configuration files of a server like httpd.conf, apache2.conf.
To put simply, .htaccess in the www directory or in its subdirectories will only be processed after root configuration files are processed.
I mean you type http://host.name and apache finds the destination and uses .htaccess file on the host to perform some operations if needed.

Apache and Cakephp application

I am running into issues with cakephp application running with CentOs. I did not change any setting in the default config other than added a file under conf.d which content as :
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/portal/
ServerName abc.mydomain.com
</VirtualHost>
When accessed, home page works i.e. app.mydomain.com shows up but none of the CSS,JS and img files are loaded which are under default structure
i.e. /var/www/portal/app/webroot/img
/var/www/portal/app/webroot/css
/var/www/portal/app/webroot/js
So I tried moving them right under /var/www/portal/ and that worked for homepage but clicking on any link on homepage just does 404. e.g. If link is abc.mydomain.com/test
In apache log I see the errors as 'File Does not exist : /var/www/portal/test' . It seems that apache is not sending the request to cakephp to process the url.
What could be wrong here? Most likely with the apache security settings but am not sure where to lool.
Is your AllowOverride set to all? Only then the CakePHP rewrite directives which are in .htaccess files start working. Alternatively, you can move them to the virtual host configuration and get them to work.
Ok, this is a common mistake. you should enable "rewrite" --> module rewrite. (this is of course a php module). in ubuntu you usually type sudo a2enmod rewrite. Check for CentOS command.