saadlulu
saadlulu

Reputation: 1395

change web root apache mac OS X

I cant change my web root in apache, for some reason it points to /Sites/folder1/folder2 instead of it pointing to /Sites. I configured and change my apache <Directory "/Users/saad/Sites"> and DocumentRoot /Users/saad/Sites restarted my apachectl and still nothing.

Upvotes: 24

Views: 96975

Answers (10)

N.Srinivasulu Rao
N.Srinivasulu Rao

Reputation: 9

Following are the steps to update your document root in the new mac os ventura in 2023. You just need to update a single file.

1). Open the httpd.conf file inside the /Application/XAMPP/xamppfiles/etc folder and search for the text DocumentRoot, you can find something like as shown below.

DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/htdocs">

2). Now update the document root path for both the lines, as shown below.

DocumentRoot "/Users/Stephen/Projects/Backend/PHP"
<Directory "/Users/Stephen/Projects/Backend/PHP">

3). Now the most important step, search for the text User daemon, you will find something like as shown below.

User daemon
Group daemon
</IfModule>

now change the name daemon to the username of your OS.

User Stephen
Group daemon
</IfModule>

4).Now restart your server using the xampp control panel, that's it.

Incase the phpmyadmin doesn't opens in the browser, then simply empty the temp folder inside /Applications/XAMPP/xamppfiles/temp. For more details, please follow the video link https://www.youtube.com/watch?v=cWPSBbwmQFE

Upvotes: 0

asela daskon
asela daskon

Reputation: 564

If someone get 403 forbidden error, try to update the DirectoryIndex inside the httpd.config file as well. In case if you forgotten you have .php file in the folder. My config file was in this path /private/etc/apache2/httpd.conf This solve the issue of my macOs Monterey

DirectoryIndex index.html index.php

Upvotes: 0

uzer123
uzer123

Reputation: 21

Although i had rights for my folder (and tried the chmod solutions also), it couldnt work for me.

What i found to work is to edit the User and group that runs the htppd conf file:

in httpd.conf file, change:

User daemon to User yourMacUsername (you can find that from folder info)
Group daemon to Group staff (this is the default)

Save and restart apache

Upvotes: 1

cabronHp
cabronHp

Reputation: 301

Apache has several files with the same name httpd.conf

The "oficial" path is in /usr/local/etc/httpd/httpd.conf

Upvotes: 8

Akexis
Akexis

Reputation: 129

In case this helps someone else, it looks like Sierra made a backup file for me at:

/etc/apache2/httpd.conf~previous

I was able to copy my old configuration file into the new one, restarted apache and it worked.

Upvotes: 1

shengfengli
shengfengli

Reputation: 126

I came across the similar question as you, the httpd.conf under /private/etc/apache2/ defines the DocumentRoot as /Library/Webserver/Documents. But that directory doesn't work!

Instead,the DocumentRoot which actually works is /usr/htdocs! Weird!

Upvotes: 2

David_Wang
David_Wang

Reputation: 670

I just meet this problem, too. I need to change the DocumentRoot and point it to my customised directory, which used for saving image files.

Berkay is right, you need edit a bit on your apache httpd.config file, but besides that, you need to do one more change, otherwise the WebSharing won't be able to turn on again.

  1. Open your httpd.config by your favorite editor (Probably need to do this if you haven't change the permission access to this file)

    • sudo chmod 666 httpd.conf
    • Open httpd.config, and start editing.
    • sudo chmod 644 httpd.conf, when it's finished, proceed to step 2 (change it back to original permisson access)
  2. Find DocumentRoot "/Library/WebServer/Documents", and change it to DocumentRoot "/Users/leiwang/Sites" or any other folders you want to.

  3. One important thing is, you need to give the Read/Write permission to the folder you specified.

    • sudo chmod -R 747 foldername

Hope it helps:)

Upvotes: 35

us_david
us_david

Reputation: 4917

I ran into this problem: Once you change the root of web server to somewhere other than the default (/Library/WebServer/Documents), you need setup virtual host, otherwise, localhost will not work, and you will get:
403 Forbidden error
You can refer to this link for details on how to set it up:
http://coolestguidesontheplanet.com/set-virtual-hosts-apache-mac-osx-10-10-yosemite/

Also make sure the following line is in the configuration file for the web directory if your Max is running OS X 10.10:
Require all granted

For your reference, I just remind you if this ever happens to you.

Upvotes: 7

Berkay
Berkay

Reputation: 1439

there is a documentroot property in the /etc/apache2/httpd.conf on osx. so we can easily change the path like this;

DocumentRoot "{YOUR_ROOT_PATH}"

Upvotes: 7

saadlulu
saadlulu

Reputation: 1395

I went to /etc/apache/users/saad.conf and added the virtual host in this form "www.x.dev" to the top of my virtual hosts list. this temporarily fixed the problem. hope this helps

Upvotes: 2

Related Questions