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

前端 未结 7 875
予麋鹿
予麋鹿 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:

    <VirtualHost *:80>
    ServerName localhost
    DocumentRoot /Library/WebServer/Documents/
    </VirtualHost>
    

    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

    <IfModule unixd_module>
    

    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/

    0 讨论(0)
  • 2020-11-28 01:23

    Following these instructions from start to finish worked for me: https://www.computersnyou.com/3376/setup-apache-php-mysql-macosx-10-10-yosemite/

    Basic instructions added in response to suggestion from rozkosz:

    These instructions are for setting up apache from scratch after upgrading the Yosemite. It seems like you've done most of this but you need to make edits to your /etc/apache2/users/YOURUSERNAME.conf. In any case, here's a summary of the whole thing:

    uncomment the following in /etc/apache2/httpd.conf

    LoadModule authn_core_module libexec/apache2/mod_authn_core.so
    LoadModule authz_host_module libexec/apache2/mod_authz_host.so 
    LoadModule userdir_module libexec/apache2/mod_userdir.so 
    Include /private/etc/apache2/extra/httpd-userdir.conf
    

    Then,go to /etc/apache2/extra/httpd-userdir.confand uncomment:

    Include /private/etc/apache2/users/*.conf 
    

    Your /etc/apache2/users/YOURUSERNAME.conf file should contain the following:

    <Directory /Users/*/Sites>
      DirectoryIndex index.html index.php index index.html default.html default.htm
      AllowOverride FileInfo AuthConfig Limit Indexes
      Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
      <Limit GET POST OPTIONS>
       Require all granted
      </Limit>
      <LimitExcept GET POST OPTIONS>
       Require all denied
      </LimitExcept>
    </Directory>
    

    Now create the Sites folder in your home directory, restart apache, and all should be working properly.

    0 讨论(0)
  • 2020-11-28 01:27

    Looks like you need to uncomment the following:

    #LoadModule userdir_module libexec/apache2/mod_userdir.so
    

    and

    #Include /private/etc/apache2/extra/httpd-userdir.conf
    

    Then in httpd-userdir.conf you may need to uncomment:

    #Include /private/etc/apache2/users/*.conf
    

    Lastly you would need to create /private/etc/apache2/users/kevin.conf if it doesn't exist. I think it should look something like this:

    <Directory "/Users/kevin/Sites/">
      Options Indexes MultiViews
      AllowOverride None
      Require all granted
    </Directory>
    

    Make sure to restart the Apache server afterwards with:

    sudo apachectl restart
    
    0 讨论(0)
  • 2020-11-28 01:28

    For the rare person who spent as much time as I did wondering why none of the other resources or posts worked... this is for you. I spent 6 hours (at work) devoted entirely towards getting this damn permission issue solved and here was my solution. PLEASE NOTE: When I initially set out to solve this issue, I could access localhost (in Chrome), getting the desired output of It Works!. So make sure you can at least get that far before moving on.


    I'm using PHP v5.5.14 on a Retina Macbook Pro (mid-2014) that is running OS X Yosemite (I tested this again using Apple's recent El Capitan update and confirmed to be a solution!). My problem was that I recieived a 403 ERROR stating that permission was denied whenever attempting to access localhost/~userDirName/. My solution involves 3 simple steps:

    STEP #1:

    Load the userdir module by finding the following two lines in /etc/apache2/httpd.conf and uncommenting them by removing the leading hash (#):

    LoadModule userdir_module libexec/apache2/mod_userdir.so
    Include /private/etc/apache2/extra/httpd-userdir.conf
    

    STEP #2:

    Navigate to /etc/apache2/extra/httpd-userdir.conf and uncomment the following line (in the same manner as step 1):

    Include /private/etc/apache2/users/*.conf
    

    STEP #3:

    Edit /etc/apache2/users/fileYouMade.conf. You must add Require local and a + character before each argument that is option-specific. The result will look like this:

    <Directory "/Users/user/Sites/">
        Options +Indexes +MultiViews +FollowSymLinks +SymLinksIfOwnerMatch +ExecCGI
        AllowOverride All
        Require local
        Order allow,deny
        Allow from all
    </Directory>
    
    0 讨论(0)
  • 2020-11-28 01:32

    Resuming for El Captain, with users support:

    • sudo nano /private/etc/apache2/users/username.conf

      <Directory "/Users/noone/Sites/">
          Options Indexes MultiViews FollowSymLinks Includes ExecCGI
          AllowOverride All
          Order allow,deny
          Allow from localhost
          Require all granted
      </Directory>
      
    • sudo nano /etc/apache2/httpd.conf, uncomment:

      LoadModule userdir_module libexec/apache2/mod_userdir.so
      LoadModule include_module libexec/apache2/mod_include.so
      LoadModule rewrite_module libexec/apache2/mod_rewrite.so
      LoadModule cgi_module libexec/apache2/mod_cgi.so
      LoadModule php5_module libexec/apache2/libphp5.so
      
      Include /private/etc/apache2/extra/httpd-userdir.conf
      
    • sudo nano /etc/apache2/extra/httpd-userdir.conf, uncomment:

      Include /private/etc/apache2/users/*.conf
      
    • apachectl configtest

    • sudo apachectl restart

    Taken from here.

    0 讨论(0)
  • 2020-11-28 01:40

    In Apache 2, you've to enable mod_userdir extension, e.g.

    a2enmod userdir
    

    Prefix with sudo if required.

    Then reload/restart Apache.

    0 讨论(0)
提交回复
热议问题