Fedora 20 配置php 預設路徑問題

來源:互聯網
上載者:User
大家好。我在fedora 20上安裝了預設的php+apache+mysql. 我在更改apache的預設文件路徑時遇到了如下問題:1. SELinux安全許可權;2. 更改相關檔案夾許可權問題。我在根據錯誤記錄檔的提示設定了相關的SELinux許可權,並使用chmod, chron更改了相關的許可權後,現在的提示是403 forbidden.。請問接下來我該怎麼做?

具體說來,我已做完的步驟:
1. 設定SELinux許可權:
setsebool -P httpd_read_user_content 1
setsebool -P httpd_enable_homedirs 1
2. 使用chmod, chron更改目錄許可權(我的目錄為~/www/, 頁面指令碼和分頁檔放在~/www/html目錄中,已取得root許可權):
# chmod 755 ~/www
# chmod 755 ~/www/html
# chron -R -t httpd_sys_content_t ~/www
# chron -R -t httpd_sys_content -t ~/www/html
# cd ~/www/html
# touch index.html
3. 修改httpd.conf檔案:
DocumentRoot ".../www/html"

Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all



Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all



Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all


儲存後並重啟apache服務,仍然得到403 forbidden錯誤。請問接下來我該怎麼辦?網上的辦法都試過了,都沒用。我是新手,請賜教,小弟不勝感激。


回複討論(解決方案)

確定你php環境沒問題? $ php -v

確定你php環境沒問題? $ php -v
沒問題啊。如果我在預設的/var/www/html下建立php檔案,是可以啟動並執行。

你現在在www/html/ 下建立 index.php
echo phpinfo();
?>
運行有報錯?

至於你說的403,

$ ll .../www/
貼出結果看看

或者

在設定檔中找到下面兩句

user deamon
group deamon

因為這兩句的存在,使得apache並沒有許可權去讀寫目前使用者的目錄,所以會出現許可權問題

把它們改為
user currentUser (其中 currentUser 是目前使用者的使用者名稱)
group currentGroup (其中 currentGroup 是目前使用者所在的組名 如不知道 可用命令 groups "目前使用者名" 來查詢)

你現在在www/html/ 下建立 index.php
echo phpinfo();
?>
運行有報錯?

至於你說的403,

$ ll .../www/
貼出結果看看

或者

在設定檔中找到下面兩句

user deamon
group deamon

因為這兩句的存在,使得apache並沒有許可權去讀寫目前使用者的目錄,所以會出現許可權問題

把它們改為
user currentUser (其中 currentUser 是目前使用者的使用者名稱)
group currentGroup (其中 currentGroup 是目前使用者所在的組名 如不知道 可用命令 groups "目前使用者名" 來查詢)
還是不行。按你的步驟走了一遍,現在的情況是地址欄輸入localhost可以顯示apache預設測試頁面(原來不顯示),但輸入localhost/index.html或index.php仍然報403 forbidden錯誤。

現在的檔案結構如下:
[root@localhost lanhyde]# ll www
總用量 4
drwxr-xr-x. 2 lanhyde lanhyde 4096 1月 13 14:09 html
[root@localhost lanhyde]# cd www
[root@localhost html]$ ls -Z
-rw-rw-r--. lanhyde lanhyde unconfined_u:object_r:httpd_sys_content_t:s0 index.php
-rw-rw-r--. lanhyde lanhyde unconfined_u:object_r:httpd_sys_content_t:s0 index.php~
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 log.txt
-rwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 mypol.pp
-rwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 mypol.te
[lanhyde@localhost html]$ ll
總用量 16
-rw-rw-r--. 1 lanhyde lanhyde 20 1月 13 14:18 index.php
-rw-rw-r--. 1 lanhyde lanhyde 0 1月 13 14:18 index.php~
-rw-r--r--. 1 root root 1278 1月 13 13:58 log.txt
-rwxr-xr-x. 1 root root 939 1月 13 14:02 mypol.pp
-rwxr-xr-x. 1 root root 219 1月 13 14:02 mypol.te

-rw-rw-r--. 1 lanhyde lanhyde 20 1月 13 14:18 index.php
更改
chmod 755 file or chmod 777 file試試
-rwxr-xr-x 1 root root
-rwxrwxrwx 1 root root

-rw-rw-r--. 1 lanhyde lanhyde 20 1月 13 14:18 index.php
更改
chmod 755 file or chmod 777 file試試
-rwxr-xr-x 1 root root
-rwxrwxrwx 1 root root
試過了,不管用。。。


-rw-rw-r--. 1 lanhyde lanhyde 20 1月 13 14:18 index.php
更改
chmod 755 file or chmod 777 file試試
-rwxr-xr-x 1 root root
-rwxrwxrwx 1 root root
試過了,不管用。。。
貼出你操作之後的效果。



-rw-rw-r--. 1 lanhyde lanhyde 20 1月 13 14:18 index.php
更改
chmod 755 file or chmod 777 file試試
-rwxr-xr-x 1 root root
-rwxrwxrwx 1 root root
試過了,不管用。。。
貼出你操作之後的效果。
抱歉這麼久才回複。使用其它網站提供的資料,我已經解決問題了。還是非常謝謝你哈。

貼出我的參考地址為有相同問題的童鞋提供點協助:http://www.if-not-true-then-false.com/2010/enable-apache-userdir-with-selinux-on-fedora-centos-red-hat-rhel/

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.