changing documentroot for apache on windows isn't working - php

I'm trying to change documentroot on my local windows machine to point at a sub directory below htdocs. I've changed the DocumentRoot location inside httpd.conf along with the Directory location. I've restarted Apache but prinitng out document root with PHP it still points to the default location.
Changes inside httpd.conf:
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/folder_test/website"
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/folder_test/website">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
When I navigate to http://localhost/folder_test/website I see the following from my PHP output:
C:/Program Files/Apache Software Foundation/Apache2.2/htdocs
My PHP code:
<?php
//Get the document root
$root = getenv("DOCUMENT_ROOT") ;
Echo $root;
?>
I've restarted Apache...What am I missing?

Open the "\conf\extra\httpd-vhosts.conf" file.
Change the
<VirtualHost _default_:80>
DocumentRoot "${SRVROOT}/htdocs"
#ServerName www.example.com:80
</VirtualHost>
section to reflect the desired directory, in your case:
<VirtualHost _default_:80>
DocumentRoot "${SRVROOT}/htdocs/folder_test/website"
#ServerName www.example.com:80
</VirtualHost>

Hey if this is not answered still:
Sometimes when you change document root and other info in httpd.conf it does not reflect that it because the changes you have dont is not saved at all. In notepad++ and diffmerge it does not show that it is not saved on the contrary it shows as saved. Open it in normal notepad and when you try to replace it it says access denied. May be this is because these folder dont have the modification permission for users. Hence for this purpose you need to
Save the changes in a separate file else where with the same name
httpd.conf
Rename http.conf inside your apache root document to
httpd_backup.conf or just delete it.
now copy the new file you have created i.e. httpd.conf to apache
root document.
Go to "Open apache monitor" and restart
clear all cache and cookies in your browser and try again

Related

Set static Laravel URL to domain name I purchased

I need to set my url for my site to appear as mydomain.com/ and have apache recognize that as the webroot.
Currently my url looks like:
###.###.##.##/laravel/public
and I want it to become:
mydomain.com/
This is the first site I've worked on from scratch, so I'm not completely sure what information I should include here.
Current apache httpd.conf:
NameVirtualHost *:80
NOTE: NameVirtualHost cannot be used without a port specifier
(e.g. :80) if mod_ssl is being used, due to the nature of the
SSL protocol.
VirtualHost example:
Almost any Apache directive may go into a VirtualHost container.
The first VirtualHost section is used for requests without a known
server name.
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot /var/www/html/foo_bar/public
ServerName foo.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
<Directory /var/www/html/foo/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
</VirtualHost>
First you'll need to edit your httpd.conf (usually located somewhere like /etc/apache2/conf).
Look for a line like <Directory "/var/www">. This is telling apache the root directory from which you want to work. /var/www in your case will be whatever directory laravel/public is living in on your websever currently.
If you change that line to <Directory "/var/www/laravel/public"> (assuming /var/www is where your laravel app is), save the file and restart apache, then you should be serving mydomain.com from inside laravel/public.

how to configuring a xampp web server for different root directory

The web directory is the home of all of your application's public and static files. Including images, stylesheets and JavaScript files. It is also where the front controllers live.
So the question is when i install and set up xampp my web directory is:
xampp\htdocs
and I want to set it up for:
xampp\htdocs\myproject\web
How to do it?
Now when I type in my browser the address: http://localhost/
I enter xampp\htdocs directory
and I want to type in my browser the address: http://localhost/
and enter xampp\htdocs\myproject\web directory
You can change Apaches httpd.conf by clicking (in xampp control panel) apache/conf/httpd.conf and adjust the entries for DocumentRoot and the corresponding Directory entry.
Just Ctrl+F for "htdocs" and change the entries to your new path.
See screenshot:
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Go to C:\xampp\apache\conf\httpd.conf
Open httpd.conf
Find tag : DocumentRoot "C:/xampp/htdocs"
Edit tag to : DocumentRoot "C:/xampp/htdocs/myproject/web"
Now find tag and change it to < Directory "C:/xampp/htdocs/myproject/web" >
Restart Your Apache
In case, if anyone prefers a simpler solution, especially on Linux (e.g. Ubuntu), a very easy way out is to create a symbolic link to the intended folder in the htdocs folder. For example, if I want to be able to serve files from a folder called "/home/some/projects/testserver/" and my htdocs is located in "/opt/lampp/htdocs/". Just create a symbolic link like so:
ln -s /home/some/projects/testserver /opt/lampp/htdocs/testserver
The command for symbolic link works like so:
ln -s target source
where,
target - The existing file/directory you would like to link TO.
source - The file/folder to be created, copying the contents of the target. The LINK itself.
For more help see ln --help
Source: Create Symbolic Links in Ubuntu
And that's done. just visit http://localhost/testserver/
In fact, you don't even need to restart your server.
I moved my htdocs folder from C:\xampp\htdocs to D:\htdocs without editing the Apache config file (httpd.conf).
Step 1) Move C:\xampp\htdocs folder to D:\htdocs
Step 2) Create a symbolic link in C:\xampp\htdocs linked to D:\htdocs using mklink command.
D:\>mklink /J C:\xampp\htdocs D:\htdocs
Junction created for C:\xampp\htdocs <<===>> D:\htdocs
D:\>
Step 3) Done!
ok guys you are not going to believe me how easy it is, so i putted a video on YouTube to show you that [ click here ]
now ,
steps :
run your xampp control panel
click the button saying config
select apache( httpd.conf )
find document root
replace
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
those 2 lines || C:/xampp/htdocs == current location for root || change C:/xampp/htdocs with any location you want
save it
DONE: start apache and go to the localhost
see in action [ watch video click here ]
You can also put in a new virtual Host entry in the
c:\xampp\apache\conf\httpd-vhosts.conf
like:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/xampp/htdocs/myproject/web"
ServerName localhost
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
Write above code inside following tags < Directory "c:\projects" > < / Directory >
c:(you can add any directory d: e:) is drive where you have created your project folder.
Alias /projects "c:\projects"
Now you can access the pr0jects directory on your browser :
localhost/projects/
For XAMMP versions >=7.5.9-0 also change the DocumentRoot in file "/opt/lampp/etc/extra/httpd-ssl.conf" accordingly.
If you are running xampp on linux based image, to change root directory open:
/opt/lampp/etc/httpd.conf
Change default document root:
DocumentRoot "/opt/lampp/htdocs" and <Directory "/opt/lampp/htdocs"
to your folder DocumentRoot "/opt/lampp/htdocs/myFolder" and <Directory "/opt/lampp/htdocs/myFolder">
You can change the port while you open your XAMP control panel, follow the steps:
click on config net to the start button, and
select httpd.conf, a text file will open
check the file and file listen:80,
once got listen:80 replace with listen:8080 and
save in the same folder.
Once done that, you will be able to start your local server.

XAMPP define a work directory and use it

How can I define my work path in XAMPP so I could write my code there and test it.
Example: In WAMP, I just added the folder 'courses01' in the 'wamp/www/' directory.
Can I do the same in XAMPP ? Just add my courses folder in the system files? But where? and how can I access them in the 'localhost/xampp' menu??
I need this so I could work with my PHP files from my courses :(
Put your folders/php_file.php in xampp\htdocs. then access http://localhost/folder or http://localhost/php_file.php in your browser.
Here is what you should do:
Step 1:
Create a dir in your Home folder usually located here:
C:/Users/Yourname/www/courses01
Step 2: Edit virtual hosts located in:
C:/xampp/apache/conf/extra/httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost 127.0.0.1:80>
DocumentRoot "C:\Users\Yourname\www\courses01"
ServerName courses01.dev
<Directory "C:\Users\Yourname\www\courses01">
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Step 3: Modify hosts file located in:
C:\Windows\System32\Drivers\etc\hosts
add a line:
127.0.0.1 courses09.dev
Step 4: Restart apache

Changed DocumentRoot in httpd.conf, $_SERVER['DOCUMENT_ROOT'] still the same

So I changed DocumentRoot in my httpd.conf files and $_SERVER['DOCUMENT_ROOT'] still seems to be the same on XAMPP. I've restarted the server and the problem still persists. I've change DocumentRoot before from the original xampp/htdocs folder and it worked fine. Any clues?
Note the DOCUMENT_ROOT for PHP might not be the same as of Apache.
DOCUMENT_ROOT is where the PHP file is located. This could be on Document root or through a different directory.
There's another line in the httpd.conf file that needs changing. In my file it was about 30 lines below the DocumentRoot setting. I found it thanks to the preceding comment line
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "C:/work/htdocs">
I just moved the whole htdocs directory so I also had to change a line in the httpd-xampp.conf file as well.
<Directory "C:/work/htdocs/xampp">

apache php Virtualhost

I am trying to implement virtual host in my system.
I have used the below code for that.
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/Users/shanker/Documents/content_booking/"
ServerName content.boking
Alias /booking "/Users/shanker/Documents/content_booking/public/"
</VirtualHost>
also i have updated the hosts file as
127.0.0.1 content.booking
But I am getting the following errors:
---------------------------------------------------------
Access forbidden!
You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.
If you think this is a server error, please contact the webmaster.
Error 403
---------------------------------------------------------
Can anybody please fix this issue.
First check your httpd.conf file in Apache and make sure Virtual hosts is on. (remove the '#' to turn on/uncomment).
#Virtual hosts
Include conf/extra/httpd-vhosts.conf
next update your vhosts-file with some Directory options.
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/Users/shanker/Documents/content_booking/"
ServerName content.boking
<Directory "C:/Users/shanker/Documents/content_booking/">
Options Indexes FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Alias /booking "/Users/shanker/Documents/content_booking/public/"
Hope this helps.
Your ServerName is with one "o", and your hosts file entry is with "oo" (two).
Does it work once you fix that typo?
If you do not include an index.[html|htm|php] in a directory, the default action may be to list all the files in that directory or more commonly for security, to throw this error.
http://127.0.0.1/ causes Apache to look for index.[html|htm|php] files and if there isn't one there and your security doesn't allow listing the directory (which it shouldn't), this is the error.
Create an index.html file in the proper directory and see if that helps.
OS X's permissions, etc. are set up (out of box) to serve web documents from /Users/shanker/Sites so, if it's a permissions related issue, you might just try moving your code there to the /Users/shanker/Sites/content_booking/ directory and updating the DocumentRoot directive to side-step any permissions issues.

Categories