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

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">

Related

How to change xampp htdocs directory in Mac OS Big Sur

I have installed Xampp 7.2.34 from https://www.apachefriends.org in Big Sur.
XAMPP htdocs folder is placed in /Applications/XAMPP/xamppfiles directory. Is there anyway that I can change the location of htdocs folder and place all my projects in the new location.
Current Location: /Applications/XAMPP/xamppfiles/htdocs
Desired Location: /Users/user/Desktop/Work/PHP/htdocs
I am following this question in Stackoverflow but it seems quite old and I was not able to accomplish what I required.
Already done:
Created new empty htdocs folder on desired location
Changed User daemon to User user in xamppfiles/etc/httpd.conf
Didn't change Group daemon
Changed DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs" to DocumentRoot "/Users/user/Desktop/Work/PHP/htdocs" in xamppfiles/etc/httpd.conf
Changed <Directory "/Applications/XAMPP/xamppfiles/htdocs"> to <Directory "/Users/user/Desktop/Work/PHP/htdocs"> in xamppfiles/etc/httpd.conf
I also uncommented this line of code Include etc/extra/httpd-vhosts.conf in xamppfiles/etc/httpd.conf
Result:
Access forbidden! error.
What did I miss? Has something changed in these years? TIA.
I have the same issue, but worked with this this solution. You could using Xampp in another version, Xampp 7.4.15 with this configuration
This worked for me using XAMPP 8.2.0 and macOS 12.6.2 Monterrey:
Make a copy of htdocs and put it where you want it. In my case, I made my copy in /Users/me/Dropbox/XAMPP/htdocs
Edit /Applications/XAMPP/xamppfiles/etc/httpd.conf
Change
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs”
to
DocumentRoot "/Users/me/Dropbox/XAMPP/htdocs"
Change
<Directory "/Applications/XAMPP/xamppfiles/htdocs”>
to
<Directory "/Users/me/Dropbox/Programming/XAMPP/htdocs">
Change
User daemon
to
User me (your user name)
Edit /Applications/XAMPP/xamppfiles/phpmyadmin/config.inc.php
After
$cfg['SaveDir'] = '';
add
$cfg['TempDir'] = '/tmp';
Edit /Applications/XAMPP/xamppfiles/properties.ini
Change
apache_htdocs_directory=/Applications/XAMPP/xamppfiles/htdocs
to
apache_htdocs_directory=/Users/me/Dropbox/Programming/XAMPP/htdocs
Save the files and restart the servers.
That was it. Hope helps someone. I looked for this answer for a long time.

How to change LAMPP webserver root document?

How to change LAMPP webserver root document? The default is localhost/xampp/ in /opt/lampp/htdocs But I have a different folder in the /opt/lampp directory and there I have my main website document which I want to load by default. How can I do this? I tried to edit the httpd.conf file in the /opt/lampp/etc and so far I did this but it doesnt seem to work : I commented out 229 line (DocumentRoot "/opt/lampp/htdocs") and added DocumentRoot "/opt/lampp/folder" and also commented by prepending # 231 line (<Directory "/opt/lampp/htdocs">) and added <Directory "/opt/lampp/folder>". What I did wrong or what else needs to be done?
You have to restart your server after editing the config file.

Apache virtual host configuration: How to make my Zend projects and phpMyAdmin play together?

In order for me to be able to run a Zend Framework project on my local development machine, I made changes to Apache's \etc\apache2\httpd.conf and the openSUSE system's \etc\hosts files. I set up a test3.local alias for an individual Zend project, and things seem to "work".
Before I started fiddling with things, I could access phpMyAdmin simply by entering http://localhost/phpMyAdmin/ in my browser. And if I take away my changes, that once again works.
Using this answer as a basis, I tried to set up an additional virtual host specifically for phpMyAdmin, hoping to "solve" this problem. But right now if key in the virtual host name, admin.local, that I intend to take me to phpMyAdmin, I get a 403 error like this:
(source: willmatheson.com)
Here is my present httpd.conf:
### Virtual server configuration ############################################
IncludeOptional /etc/apache2/vhosts.d/*.conf
<VirtualHost *:80>
ServerName test3.local
DocumentRoot /home/william/public_html/ZendTest3/public
SetEnv APPLICATION_ENV "development"
<Directory /home/william/public_html/ZendTest3/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName admin.local
DocumentRoot /var/lib/mysql/phpMyAdmin
# This gives permission to serve the directory
<Directory /var/lib/mysql/phpMyAdmin>
DirectoryIndex index.php
Options None
AllowOverride All
# This allows eveyone to access phpmyadmin, which you may not want
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
and hosts:
127.0.0.1 localhost
127.0.0.1 local
127.0.0.1 test3.local
127.0.0.1 admin.local
Ideally I'd like to not have to specify a virtual host for phpMyAdmin at all, because I'm sure to muck it up, and just somehow have the settings to make the Zend project work but to also have phpMyAdmin work like it did before.
I know this question was already answered, but I thought I'd share what I did to overcome a similar problem, in case it helps anyone else.
My problem was:
I started to get localhost/phpmyadmin 404 error after changing the DocumentRoot folder in httpd.conf. The change I made was to change the DocumentRoot
from:
DocumentRoot "C:\Program Files (x86)\Zend\Apache2/htdocs"
to:
DocumentRoot "C:\Program Files (x86)\Zend\Apache2/htdocs/a/deeper/folder"
I fixed it by changing a line in zend.conf
from:
Alias /phpMyAdmin "C:\Program Files (x86)\Zend\phpMyAdmin"
to:
Alias /phpMyAdmin "C:\Program Files (x86)\Zend\ZendServer\data\apps\http\__default__\0\phpMyAdmin\4.0.5.4_41"
Hope this helps somebody else!
Well, there's a good reason I was getting a 403 - I was digging in the wrong place. My installation of phpMyAdmin was actually in /srv/www/htdocs/phpMyAdmin. Changed that, restarted Apache (sudo systemctl restart apache2.service) and things seem to work.
If you're interested in how the heck to find files and folders on openSUSE, the following steps worked for me:
sudo zypper install findutils-locate
su
updatedb (go check your e-mail)
locate phpMyAdmin (like that, not 'phpmyadmin')

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

changing documentroot for apache on windows isn't working

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

Categories