banner

[Rule] Rules  [Home] Main Forum  [Portal] Portal  
[Members] Member Listing  [Statistics] Statistics  [Search] Search  [Reading Room] Reading Room 
[Register] Register  
[Login] Loginhttp  | https  ]
 
Forum Index Thảo luận hệ điều hành *nix Phân quyền cho thư mục www trong thư mục home  XML
  [Question]   Phân quyền cho thư mục www trong thư mục home 18/07/2013 18:42:09 (+0700) | #1 | 277569
minhquang.qhamy
Member

[Minus]    0    [Plus]
Joined: 27/10/2012 18:23:08
Messages: 43
Offline
[Profile] [PM]
Em đã chuyển thư mục www ở vị trí mặc định sang thư mục người dùng home.

Và đã phân quyền với các lệnh sau :

Code:
sudo find /home/minhquang/www/ -type f -exec chmod 644 {} \;
sudo find /home/minhquang/www/ -type d -exec chmod 755 {} \;
sudo chown minhquang:minhquang -R /home/minhquang/www/


Nhưng cứ mỗi khi em tạo một file .php trong đó rồi chạy thì bị lỗi 500 (permission). Nếu muốn chạy được thì phải chạy lại các lệnh trên.

Giờ em muốn mỗi khi tạo file .php sau đó chạy không bị lỗi mà không cần phân qyuền lại thì phải làm sao ạ ?

Em xin cảm ơn !
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 19/07/2013 14:01:23 (+0700) | #2 | 277593
[Avatar]
quanta
Moderator

Joined: 28/07/2006 14:44:21
Messages: 7265
Location: $ locate `whoami`
Offline
[Profile] [PM]

minhquang.qhamy wrote:

Nhưng cứ mỗi khi em tạo một file .php trong đó rồi chạy thì bị lỗi 500 (permission). Nếu muốn chạy được thì phải chạy lại các lệnh trên.
 

Web server chạy dưới quyền của user nào? Sao lại 500 nhỉ, có chăng chỉ là 403 thôi chứ. Nguyên văn lỗi trên web browser và trong log file như nào?

minhquang.qhamy wrote:

Giờ em muốn mỗi khi tạo file .php sau đó chạy không bị lỗi mà không cần phân qyuền lại thì phải làm sao ạ ?
 

Bạn thử tìm hiểu SGID (Set Group ID) xem.
Let's build on a great foundation!
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 21/07/2013 12:43:01 (+0700) | #3 | 277622
minhquang.qhamy
Member

[Minus]    0    [Plus]
Joined: 27/10/2012 18:23:08
Messages: 43
Offline
[Profile] [PM]
Webserver chạy dưới quyền user nguyenminhquang (user khai báo khi cài đặt Ubuntu)
Em chạy ls -l thì kết quả là :

Mới tạo chưa chmod, chown
file : -rw-rw-r--
folder : drwxrwxr-x

Đã chmod, chown
file : -rw-r--r--
folder : drwxr-xr-x

Nguyên văn lỗi trên web browser :

Code:
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80


và trong log file:

Code:
[Sun Jul 21 13:15:21 2013] [error] [client 127.0.0.1] SoftException in Application.cpp:249: File "/home/nguyenminhquang/www/php.php" is writeable by group, referer: http://localhost/
[Sun Jul 21 13:15:21 2013] [error] [client 127.0.0.1] Premature end of script headers: php.php, referer: http://localhost/
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 21/07/2013 20:07:46 (+0700) | #4 | 277628
xwm
Member

[Minus]    0    [Plus]
Joined: 29/08/2011 21:49:17
Messages: 36
Offline
[Profile] [PM]
- Xem lại phân quyền /home/user coi đúng chưa
- Bạn chạy PHP handler nào, nếu sử dụng suphp thì bạn nên chú ý lại phân quyền : 0755 cho folder và 0644 cho file:
find /home/username/public_html -type d -exec chmod 755 '{}' \;
find /home/username/public_html -type f -exec chmod 644 '{}' \;

find /home/username/www -type d -exec chown username:username '{}' \;
find /home/username/www -type f -exec chown username:username '{}' \;
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 22/07/2013 05:51:51 (+0700) | #5 | 277635
minhquang.qhamy
Member

[Minus]    0    [Plus]
Joined: 27/10/2012 18:23:08
Messages: 43
Offline
[Profile] [PM]
... nếu sử dụng suphp thì bạn nên chú ý lại phân quyền : 0755 cho folder và 0644 cho file 


Vẫn không được
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 22/07/2013 09:00:25 (+0700) | #6 | 277636
[Avatar]
quanta
Moderator

Joined: 28/07/2006 14:44:21
Messages: 7265
Location: $ locate `whoami`
Offline
[Profile] [PM]
Bạn đang dùng `suPHP` à? Bạn thử tìm hiểu xem lỗi "Premature end of script headers" nghĩa là gì chưa?
Let's build on a great foundation!
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 24/07/2013 09:20:53 (+0700) | #7 | 277688
minhquang.qhamy
Member

[Minus]    0    [Plus]
Joined: 27/10/2012 18:23:08
Messages: 43
Offline
[Profile] [PM]
Code:
Bạn đang dùng `suPHP` à?

Vâng, em dùng suPHP

Bạn thử tìm hiểu xem lỗi "Premature end of script headers" nghĩa là gì chưa? 


Tiếng Anh của em còn rất hạn chế nên em hiểu một ít như sau :

1. Upgrading or downgrading to a different version of PHP can leave residual options in the httpd.conf.
Check the current version of PHP using php -v on the command line and search for any lines mentioning another version in the httpd.conf.
If you find them, comment them out, distill the httpd.conf and restart apache. 

Phiên bản hiện tại của em là 5.3 và em không nâng cấp nó, trong httpd.conf của em thì trống không có gì, trong apache2.conf thì em tìm không thấy dòng nào đề cập đến phiển bản khác mà chưa comment (có dấu ; đầu dòng) (Em có đọc và theo ý hiểu của em thì các phiên bản sau httpd.conf được chuyền vào apache2.conf)


2. The RLimitCPU and RLimitMEM directives in the httpd.conf may also be responsible for the error if a script was killed due to a resource limit.[/code]
Em tìm trong apache2.conf thì không thấy cả 2 : RLimitCPU and RLimitMEM 


3. A configuration problem in suEXEC, mod_perl, or another third party module can often interfere with the execution of scripts and cause the error. If these are the cause, additional information relating to specifics will be found in the apache error_log.  

Em cũng không rõ là lỗi báo trong file log có liên quan đến suEXEC, mod_perl or module không nữa.

4. If suphp’s log reaches 2GB in size or larger you may see the premature end of scripts headers error.
See what the log contains and either gzip it or null it. Restart apache and then deal with any issues that the suphp log brought to light.
The suphp log is located at: /usr/local/apache/logs/suphp_log 

Em đã tìm trong file log và file gzip thì không thấy dòng nào thuộc tính lớn hơn hay bằng 2GB

5. The script’s permissions may also cause this error. CGI scripts can only access resources allowed for the User and Group specified in the httpd.conf.
In this case, the error may simply be pointing out that an unauthorized user is attempting to access a script. 

Khi cài Apache có 1 bước em đã bỏ qua là bước khai báo "APACHE_RUN_USER" and "APACHE_RUN_GROUP".
Và khi đọc được thông tin trong phần 5 và em có tìm hiểu thêm thì em sửa như sau :

/etc/apache2/envvars : export APACHE_RUN_USER=nguyenminhquang và export APACHE_RUN_GROUP=nguyenminhquang
/etc/apache2/apache2.conf : User nguyenminhquang và Group nguyenminhquang

Sau đó em chạy lênh : chown nguyenminhquang:nguyenminhquang /var/lock/apache2
rồi restart lại apache.


Nhưng kết quả vẫn không được, ngược lại thì tất cả các file em đã tạo trước đều bị lỗi 500 dù có chạy lại các lệnh phân quyền như trước cũng không thể chạy được.

Em có chỉnh lại như cũ nhưng vẫn bị lỗi 500 đối với tất cả các file (Không biết là em sửa lại như cũ có lỗi ở bước nào không nữa)

Trong file log có báo lỗi sau :
[code][Wed Jul 24 09:23:31 2013] [error] [client 127.0.0.1] SecurityException in Application.cpp:175: Calling user is not webserver user!, referer: http://localhost/
[Wed Jul 24 09:23:31 2013] [error] [client 127.0.0.1] Premature end of script headers: test2.php, referer: http://localhost/[/code]
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 24/07/2013 09:49:29 (+0700) | #8 | 277690
[Avatar]
quanta
Moderator

Joined: 28/07/2006 14:44:21
Messages: 7265
Location: $ locate `whoami`
Offline
[Profile] [PM]

minhquang.qhamy wrote:

Em đã tìm trong file log và file gzip thì không thấy dòng nào thuộc tính lớn hơn hay bằng 2GB
 

Không phải là "dòng nào" mà là kích cỡ của bản thân file log đó có cái nào lớn hơn 2GB không?

minhquang.qhamy wrote:

Trong file log có báo lỗi sau :
[Wed Jul 24 09:23:31 2013] [error] [client 127.0.0.1] SecurityException in Application.cpp:175: Calling user is not webserver user!, referer: http://localhost/
[Wed Jul 24 09:23:31 2013] [error] [client 127.0.0.1] Premature end of script headers: test2.php, referer: http://localhost/ 
 

`grep webserver_user /path/to/suphp.conf`?
Let's build on a great foundation!
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 24/07/2013 12:35:35 (+0700) | #9 | 277696
minhquang.qhamy
Member

[Minus]    0    [Plus]
Joined: 27/10/2012 18:23:08
Messages: 43
Offline
[Profile] [PM]
`grep webserver_user /path/to/suphp.conf`? 

Em đã sửa thành nguyenminhquang, lúc trước là www-data

Em dùng lệnh sau để xem :
Code:
ps aux | grep apache

Trước khi sửa thì có root và www-data
Nhưng sau khi sửa thì chỉ có root, nguyenminhquang hay www-data đều không có.

Và vẫn bị lỗi 500 khi tạo file mới.
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 24/07/2013 14:13:07 (+0700) | #10 | 277704
[Avatar]
quanta
Moderator

Joined: 28/07/2006 14:44:21
Messages: 7265
Location: $ locate `whoami`
Offline
[Profile] [PM]

minhquang.qhamy wrote:
`grep webserver_user /path/to/suphp.conf`? 

Em đã sửa thành nguyenminhquang, lúc trước là www-data
 

Bạn sửa file nào vậy?

minhquang.qhamy wrote:

Em dùng lệnh sau để xem :
Code:
ps aux | grep apache

Trước khi sửa thì có root và www-data
Nhưng sau khi sửa thì chỉ có root, nguyenminhquang hay www-data đều không có.
 

Cho mình xem kết quả của `ps aux | grep [a]pache` nhé.
Let's build on a great foundation!
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 24/07/2013 14:37:49 (+0700) | #11 | 277705
minhquang.qhamy
Member

[Minus]    0    [Plus]
Joined: 27/10/2012 18:23:08
Messages: 43
Offline
[Profile] [PM]
Bạn sửa file nào vậy?  


/etc/apache2/envvars
export APACHE_RUN_USER=nguyenminhquang
export APACHE_RUN_GROUP=nguyenminhquang
/etc/apache2/apache2.conf
User nguyenminhquang
Group nguyenminhquang
/etc/suphp/suphp.conf
webserver_user=nguyenminhquang

Trên là các thông tin mà em đã sửa

kết quả của `ps aux | grep [a]pache` 

Code:
root      1161  0.0  0.4 230428  9552 ?        Ss   15:15   0:00 /usr/sbin/apache2 -k start
1000      1167  0.0  0.2 230460  5624 ?        S    15:15   0:00 /usr/sbin/apache2 -k start
1000      1168  0.0  0.2 230460  5624 ?        S    15:15   0:00 /usr/sbin/apache2 -k start
1000      1170  0.0  0.2 230460  5624 ?        S    15:15   0:00 /usr/sbin/apache2 -k start
1000      1172  0.0  0.2 230460  5624 ?        S    15:15   0:00 /usr/sbin/apache2 -k start
1000      1174  0.0  0.2 230460  5624 ?        S    15:15   0:00 /usr/sbin/apache2 -k start
1000      2610  0.0  0.0  15060   924 pts/0    S+   15:31   0:00 grep --color=auto apache


Lúc em chưa sửa file : /etc/suphp/suphp.conf thì có thêm user khác là : www-data còn sau khi sửa thì kết quả là như trên
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 24/07/2013 14:52:03 (+0700) | #12 | 277706
[Avatar]
quanta
Moderator

Joined: 28/07/2006 14:44:21
Messages: 7265
Location: $ locate `whoami`
Offline
[Profile] [PM]
1000 có phải là UID của nguyenminhquang không: `awk -F: '$3 == 1000 { print $1 }' /etc/passwd`?
Let's build on a great foundation!
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 24/07/2013 15:09:35 (+0700) | #13 | 277707
minhquang.qhamy
Member

[Minus]    0    [Plus]
Joined: 27/10/2012 18:23:08
Messages: 43
Offline
[Profile] [PM]

quanta wrote:
1000 có phải là UID của nguyenminhquang không: `awk -F: '$3 == 1000 { print $1 }' /etc/passwd`? 


Dạ đúng rồi ạ :

Code:
nguyenminhquang:x:1000:1000:NguyenMinhQuang,,,:/home/nguyenminhquang:/bin/bash
www-data:x:33:33:www-data:/var/www:/bin/sh
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 24/07/2013 15:31:02 (+0700) | #14 | 277710
[Avatar]
quanta
Moderator

Joined: 28/07/2006 14:44:21
Messages: 7265
Location: $ locate `whoami`
Offline
[Profile] [PM]
Vậy giờ bạn còn bị lỗi "Calling user is not webserver user" không? Nếu không, trong error log có gì?
Let's build on a great foundation!
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 24/07/2013 15:57:36 (+0700) | #15 | 277713
minhquang.qhamy
Member

[Minus]    0    [Plus]
Joined: 27/10/2012 18:23:08
Messages: 43
Offline
[Profile] [PM]

quanta wrote:
Vậy giờ bạn còn bị lỗi "Calling user is not webserver user" không? Nếu không, trong error log có gì? 


Vẫn bị lỗi như lúc đầu :
Code:
[Wed Jul 24 16:36:25 2013] [error] [client 127.0.0.1] SoftException in Application.cpp:249: File "/home/nguyenminhquang/www/php4.php" is writeable by group, referer: http://localhost/
[Wed Jul 24 16:36:25 2013] [error] [client 127.0.0.1] Premature end of script headers: php4.php, referer: http://localhost/


Nhưng trong file suphp.conf có 4 Security options mặc định là false và em đã sửa lại tất cả thành true (Em có đọc được thông tin này khi tìm hiểu ) thì không bị lỗi gì nữa khi tạo file mới.

Code:
; Security options
allow_file_group_writeable=true
allow_file_others_writeable=true
allow_directory_group_writeable=true
allow_directory_others_writeable=true


Cảm ơn anh quantaxwm đã giúp !
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 24/07/2013 16:02:52 (+0700) | #16 | 277714
[Avatar]
quanta
Moderator

Joined: 28/07/2006 14:44:21
Messages: 7265
Location: $ locate `whoami`
Offline
[Profile] [PM]
Bạn có hiểu mấy cái options trên nói gì không?
Let's build on a great foundation!
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 24/07/2013 16:51:03 (+0700) | #17 | 277715
minhquang.qhamy
Member

[Minus]    0    [Plus]
Joined: 27/10/2012 18:23:08
Messages: 43
Offline
[Profile] [PM]

quanta wrote:
Bạn có hiểu mấy cái options trên nói gì không? 


Em có tìm được trang này :

http://www.suphp.org/DocumentationView.html?file=CONFIG 


Em chỉ hiểu đơn giản như sau :

Nhóm group : Chỉ có user nằm trong group mới được phép
Nhóm others : Bất kỳ ai (cả thế giới) đã truy cập đến tập tin hay thư mục thì đều có quyền ghi

allow_file_ : Cho phép ghi các tập tin (tạo tập tin mới)
allow_directoy_ : Cho phép tạo các thư mục

Em không hiểu đoạn Allow directories scripts are residing in nghĩa cụ thể là gì ?



[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 24/07/2013 22:06:30 (+0700) | #18 | 277731
[Avatar]
quanta
Moderator

Joined: 28/07/2006 14:44:21
Messages: 7265
Location: $ locate `whoami`
Offline
[Profile] [PM]
`/home/nguyenminhquang/www/php4.php` đang có permission là bao nhiêu: `stat -c %a /home/nguyenminhquang/www/php4.php`?
Let's build on a great foundation!
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 25/07/2013 08:03:55 (+0700) | #19 | 277734
minhquang.qhamy
Member

[Minus]    0    [Plus]
Joined: 27/10/2012 18:23:08
Messages: 43
Offline
[Profile] [PM]

quanta wrote:
`/home/nguyenminhquang/www/php4.php` đang có permission là bao nhiêu: `stat -c %a /home/nguyenminhquang/www/php4.php`? 


Các file và folder được tạo ra sau khi em sửa file suphp.conf thì permission lần lượt là 664 và 775
Các file và folder được tạo ra trước khi em sửa file suphp.conf thì permission lần lượt là 644 và 755

Em đã thử sửa lại file suphp.conf các Security options thành false hết rồi restart apache bằng lệnh 'sudo /etc/init.d/apache2 restart' , sau đó em xem lại permission của các file, folder được tạo sau khi em sửa Security options lần đầu tiên thì vẫn giữ nguyên là 664 và 775 (Lần đầu tiên em sửa Security options thành true hết) còn các file, folder trước vẫn là 644 và 755, nhưng các file có permission là 664 em chạy trên trình duyệt lại bị lỗi 500
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 25/07/2013 13:56:04 (+0700) | #20 | 277747
[Avatar]
quanta
Moderator

Joined: 28/07/2006 14:44:21
Messages: 7265
Location: $ locate `whoami`
Offline
[Profile] [PM]
Tóm lại, bạn hiểu vì sao lại bị lỗi 500 rồi đúng không? Nếu `allow_file_group_writeable=false` mà permission của `/home/nguyenminhquang/www/php4.php` lại là 664 thì nó la lên:
File "/home/nguyenminhquang/www/php4.php" is writeable by group 

là đúng rồi còn gì nữa. Do bạn đã `chown` rồi nên mình nghĩ `chmod` về 644 sẽ hay hơn là chỉnh `allow_file_group_writeable` thành true.

Giờ bạn thử tìm hiểu xem: cái gì sẽ quyết định permission của một file khi nó được tạo ra?

Let's build on a great foundation!
[Up] [Print Copy]
  [Question]   Phân quyền cho thư mục www trong thư mục home 25/07/2013 18:27:13 (+0700) | #21 | 277757
minhquang.qhamy
Member

[Minus]    0    [Plus]
Joined: 27/10/2012 18:23:08
Messages: 43
Offline
[Profile] [PM]

... vì sao lại bị lỗi 500 ... 

Là do mod_group với thiết lập security options trong suphp.conf không đồng nhất

cái gì sẽ quyết định permission của một file khi nó được tạo ra? 

Lúc trước em nghĩ là do thiết lập security options quyết định đến tất cả những thứ bên trong folder www, nhưng giờ nghĩ lại thì không phải, mod_user và mod_group sẽ quyết định đến permission của files, folders được tạo ra.

`chmod` về 644 sẽ hay hơn là chỉnh `allow_file_group_writeable` thành true. 

Cảm ơn anh, em chạy trên localhost nên không lo về vấn đề bảo mật, chỉ là làm sao cho thuận tiện thôi ạ.
[Up] [Print Copy]
[digg] [delicious] [google] [yahoo] [technorati] [reddit] [stumbleupon]
Go to: 
 Users currently in here 
1 Anonymous

Powered by JForum - Extended by HVAOnline
 hvaonline.net  |  hvaforum.net  |  hvazone.net  |  hvanews.net  |  vnhacker.org
1999 - 2013 © v2012|0504|218|