`Apache` `localhost/~username/` not working

前端 未结 7 928
予麋鹿
予麋鹿 2020-11-28 00:40

UPDATE: The following answer will also work for El Capitan.

For people who just start, the file mentioned below is under /etc/apache2

For th

7条回答
  •  情话喂你
    2020-11-28 01:23

    Answer from user3814420 is correct if you use path to you project.

    But if you still have issue like I had, when using virtual host:

    One caveat to note about virtual hosts is that once set up you lose your older document root previously at /LIbrary/WebServer/Documents or accessed in the browser at localhost what happens is that you get a 403 Forbidden Error. But the ~/username document root is still compatible.

    To get around this, you need to add in a vhost for localhost and declare this vhost before any of the others, in the same file:

    sudo nano /etc/apache2/extra/httpd-vhosts.conf
    

    Add in:

    
    ServerName localhost
    DocumentRoot /Library/WebServer/Documents/
    
    

    Restart apache

    sudo apachectl restart
    

    Changing the WebServer Default User

    One of the frustrations of using the Users/username/Sites folder for vhosts is the permissions issues with things like updates and authentication.

    This is because the default webserver user which runs httpd is known as _www, which will not be the user in your local account. If your machine is only in use by you and the webserver will run only under your account then you can change the user.

    To Find Your User and Group In the Terminal use the id command to see your username and group

    id
    

    You will get a bunch of user groups, you need your primary user uid and group gid names

    uid=502(your_user_name) gid=20(staff)
    

    After edit /etc/apache2/httpd.conf

    sudo nano /etc/apache2/httpd.conf
    

    find block

    
    

    and comment

    #User _www
    #Group _www
    

    after add new 2 line user uid and in my case group gid defined with id command above:

    User your_user_name
    Group staff
    

    Source: http://coolestguidesontheplanet.com/set-virtual-hosts-apache-mac-osx-10-10-yosemite/

提交回复
热议问题