dtzh131555 2019-05-11 15:24
浏览 190

如何从主文件夹中使用Apache运行PHP项目

Old codeignitor project just won't run due to apache problem. Tried all the solutions found in other posts and other fora, but luck so far. It's a simple problem and I think it has something to do with permissions. Yet the permission settings seem to be fine.

Firstly, the problem. This is what I see in the browser

this is what I see in the browser

This is what I see in the apache logs:

[Sat May 11 10:55:43.026415 2019] [core:crit] [pid 10672] (13)Permission denied: [client 127.0.0.1:38216] AH00529: /home/user_name/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/home/user_name/' is executable 127.0.0.1 - -

[11/May/2019:10:55:43 -0400] "GET / HTTP/1.1" 403 575 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"

[Sat May 11 10:55:43.314120 2019] [core:crit] [pid 10672] (13)Permission denied: [client 127.0.0.1:38216] AH00529: /home/user_name/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/home/user_name/' is executable, referer: http://my_php_site.local/ 127.0.0.1 - -

[11/May/2019:10:55:43 -0400] "GET /favicon.ico HTTP/1.1" 403 585 "http://my_php_site.local/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"

Note that apache is trying to execute a .htaccess file in /home/user_name/.htaccess

I do have a .htaccess file in the project folder, and think that's the Apache should look for.

Secondly, my environment. Just in case I miss something I will give here my whole configuration.

The project is located somewhere in my /home/user_name/ folder, and not in /var/www/.

File permissions for .htaccess:

-rwxr-xr-x  1 user_name www-data .htaccess

Project folder permissions:

drwxr-xr-x 11 user_name www-data my_php_site

Since the project is in the home folder I have a rule in my /etc/hosts file:

127.0.0.1       my_php_site.local

The apache config for my site:

<Directory /home/user_name/code/projects/my_php_site>
    Require all granted
</Directory>
<VirtualHost *:80>
        ServerName my_php_site.local
        ServerAlias my_php_site.local
        ServerAdmin webmaster@localhost
        DocumentRoot /home/user_name/code/projects/my_php_site

        ErrorLog /home/user_name/code/projects/my_php_site/logs/apache2-error.log
        CustomLog /home/user_name/code/projects/my_php_site/logs/apache2-access.log combined
</VirtualHost>

And finally, the .htaccess file itself:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?/$1 [L]
  • 写回答

1条回答 默认 最新

  • dongtao1262 2019-05-23 04:28
    关注

    Solution

    Apache — with user group www_data — must be able to traverse the home folder. This means it needs octal value 5, symbolic r-x.

    chmod 750 /home/user_name
    

    One Stack Overflow post mentions permissions for the project folder, but not for the home folder itself: https://askubuntu.com/questions/325498/apache-cant-access-folders-in-my-home-directory

    Following steps can also be necessary, depending on versions and system:

    Allow Apache to execute files in the home folder

    sudo a2enmod userdir
    

    sudo nano /etc/apache2/mods-available/php7.0.conf Comment this part (put # at the start of each line):

    #<IfModule mod_userdir.c>
    #    <Directory /home/*/public_html>
    #        php_admin_flag engine Off
    #    </Directory>
    #</IfModule>
    

    sudo nano /etc/apache2/apache2.conf

    Add this:

    <Directory /home/*/public_html/>
            Options Indexes FollowSymLinks
            AllowOverride None
            Require all granted
    </Directory>
    
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮