Tài liệu Cài đặt Apache2 với module mod_fcgid và PHP5 trên OpenSUSE 11.2 docx

15 453 0
Tài liệu Cài đặt Apache2 với module mod_fcgid và PHP5 trên OpenSUSE 11.2 docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Cài đặt Apache2 với module mod_fcgid PHP5 trên OpenSUSE 11.2 Trong bài viết sau, Quản Trị Mạng sẽ giới thiệu với các bạn cách cài đặt Apache2 với module mod_fcgid PHP5 trên OpenSUSE 11.2. Về bản chất, module mod_fcgid là 1 sự thay thế hoàn hảo của mod_fastcgi, module này cho phép người dùng thực thi các đoạn mã PHP với sự cho phép của người dùng bên trong các tài khoản Apache. Lưu ý sơ bộ Trong bài viết này chúng ta sử dụng hệ thống OpenSUSE 11.2 server cùng với hostname server1.example.com địa chỉ IP 192.168.0.100, đồng thời tạo 2 Apache vhost là www.example1.com www.example2.com, để mô phỏng phương thức sử dụng mod_fcgid. Cài đặt Apache2/mod_fcgi/PHP5 Để cài đặt những thành phần trên, chúng ta sử dụng câu lệnh sau: yast2 -i apache2 apache2-mod_fcgid php5-fastcgi Nếu Apache2 đã được cài đặt sẵn với PHP5 như 1 phần module của Apache, tắt bỏ module PHP5 như sau: a2dismod php5 Tiếp theo, kích hoạt 2 module suexec fcgid: a2enmod suexec a2enmod fcgid Tạo đường dẫn khởi động của Apache: chkconfig add apache2 /etc/init.d/apache2 start Mở file /etc/php5/fastcgi/php.ini …: vi /etc/php5/fastcgi/php.ini và chú thích các đoạn mã như sau: [ ] ; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's ; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok ; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting ; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting ; of zero causes PHP to behave as before. Default is 1. You should fix your scripts ; to use SCRIPT_FILENAME rather than PATH_TRANSLATED. ; http://php.net/cgi.fix-pathinfo cgi.fix_pathinfo=1 [ ] Sau đó khởi động lại Apache: /etc/init.d/apache2 restart Tạo vhost cho www.example1.com www.example2.com Việc tiếp theo của chúng ta là tạo 2 vhost, www.example1.com (với thư mục tài liệu root /srv/www/web1/web) www.example2.com (thư mục tài liệu root tại /srv/www/web2/web). Trong đó, www.example1.com được sở hữu bởi người dùng nhóm web1, www.example2.com thuộc về người dùng web2. Trước tiên, tạo tài khoản người dùng nhóm: groupadd web1 groupadd web2 useradd -s /bin/false -d /srv/www/web1 -m -g web1 web1 useradd -s /bin/false -d /srv/www/web2 -m -g web2 web2 chmod 755 /srv/www/web1 chmod 755 /srv/www/web2 Sau đó tạo thư mục tài liệu root tạo quyền chứng thực, sở hữu thuộc về web1 web2: mkdir -p /srv/www/web1/web chown web1:web1 /srv/www/web1/web mkdir -p /srv/www/web2/web chown web2:web2 /srv/www/web2/web Sau đó chạy PHP sử dụng suExec, thư mục tài liệu root của suExec tại /srv/www: /usr/sbin/suexec2 -V server1:~ # /usr/sbin/suexec2 -V -D AP_DOC_ROOT="/srv/www" -D AP_GID_MIN=96 -D AP_HTTPD_USER="wwwrun" -D AP_LOG_EXEC="/var/log/apache2/suexec.log" -D AP_SAFE_PATH="/usr/local/bin:/usr/bin:/bin" -D AP_UID_MIN=96 -D AP_USERDIR_SUFFIX="public_html" server1:~ # Do đó chúng ta không thể gọi được các file PHP thực thi lệnh (/usr/bin/php- cgi) trực tiếp vì nó được lưu trữ bên ngoài thư mục tài liệu root của suExec. Nhưng suExec không chấp nhận các symlink, phương pháp duy nhất để giải quyết vấn đề này tạo mã wrap tương ứng cho mỗi web site trong từng thư mục con của /srv/www; các đoạn mã wrap này sẽ có chức năng gọi file thực thi PHP /usr/bin/php-cgi. Và, những đoạn mã wrap này phải được quản lý sở hữu trực tiếp bởi tài khoản người dùng nhóm tương ứng của các web site, tại đây chúng ta sẽ tạo mã wrap trong thư mục con của /srv/www/php- fcgi-scripts, ví dụ như /srv/www/php-fcgi-scripts/web1 /srv/www/php- fcgi-scripts/web2. mkdir -p /srv/www/php-fcgi-scripts/web1 mkdir -p /srv/www/php-fcgi-scripts/web2 vi /srv/www/php-fcgi-scripts/web1/php-fcgi-starter #!/bin/sh PHPRC=/etc/php5/fastcgi/ export PHPRC export PHP_FCGI_MAX_REQUESTS=5000 export PHP_FCGI_CHILDREN=8 exec /usr/bin/php-cgi vi /srv/www/php-fcgi-scripts/web2/php-fcgi-starter #!/bin/sh PHPRC=/etc/php5/fastcgi/ export PHPRC export PHP_FCGI_MAX_REQUESTS=5000 export PHP_FCGI_CHILDREN=8 exec /usr/bin/php-cgi Dòng PHPRC chứa thông tin về thư mục nơi file php.ini được lưu trữ (ví dụ /etc/php5/fastcgi/ thành /etc/php5/fastcgi/php.ini). Trong đó PHP_FCGI_MAX_REQUESTS là số lượng yêu cầu tối đa trước khi quá trình fcgid dừng lại quá trình mới tiếp tục. PHP_FCGI_CHILDREN định nghĩa số lượng “PHP children” sẽ được kích hoạt. Các đoạn mã php-fcgi-starter phải được kích hoạt: chmod 755 /srv/www/php-fcgi-scripts/web1/php-fcgi-starter chmod 755 /srv/www/php-fcgi-scripts/web2/php-fcgi-starter chown -R web1:web1 /srv/www/php-fcgi-scripts/web1 chown -R web2:web2 /srv/www/php-fcgi-scripts/web2 Tiếp theo, tạo vhost Apache của www.example1.com www.example2.com: vi /etc/apache2/vhosts.d/www.example1.com.conf <VirtualHost *> ServerName www.example1.com ServerAlias example1.com ServerAdmin webmaster@example1.com DocumentRoot /srv/www/web1/web/ <IfModule mod_fcgid.c> SuexecUserGroup web1 web1 PHP_Fix_Pathinfo_Enable 1 <Directory /srv/www/web1/web/> Options +ExecCGI AllowOverride All AddHandler fcgid-script .php FCGIWrapper /srv/www/php-fcgi-scripts/web1/php-fcgi-starter .php Order allow,deny Allow from all </Directory> </IfModule> # ErrorLog /var/log/apache2/error.log # CustomLog /var/log/apache2/access.log combined ServerSignature Off </VirtualHost> vi /etc/apache2/vhosts.d/www.example2.com.conf <VirtualHost *> ServerName www.example2.com ServerAlias example2.com ServerAdmin webmaster@example2.com DocumentRoot /srv/www/web2/web/ <IfModule mod_fcgid.c> SuexecUserGroup web2 web2 PHP_Fix_Pathinfo_Enable 1 <Directory /srv/www/web2/web/> Options +ExecCGI AllowOverride All AddHandler fcgid-script .php FCGIWrapper /srv/www/php-fcgi-scripts/web2/php-fcgi-starter .php Order allow,deny Allow from all </Directory> </IfModule> # ErrorLog /var/log/apache2/error.log # CustomLog /var/log/apache2/access.log combined ServerSignature Off </VirtualHost> Hãy chắc chắn các bạn đã nhập đúng địa chỉ đường dẫn các tham số kỹ thuật cần thiết (với đúng tài khoản user nhóm trong dòng khai báo SuexecUserGroup) Mở file /etc/apache2/httpd.conf thêm dòng NameVirtualHost * vào trước Include /etc/apache2/vhosts.d/*.conf (nếu không thì chỉ có vhost đầu tiên hoạt động): vi /etc/apache2/httpd.conf [ ] ### Virtual server configuration ########################################## # # VirtualHost: If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn't need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at # <URL:http://httpd.apache.org/docs-2.2/vhosts/> # for further details before you try to setup virtual hosts. # # You may use the command line option '-S' to verify your virtual host # configuration. # NameVirtualHost * Include /etc/apache2/vhosts.d/*.conf […] Trước khi khởi động lại Apache, chúng ta cần thay đổi các thiết lập xác nhận quyền hạn của việc thực thi suExec (nếu không thì mỗi lần khởi động Apache thì bạn sẽ nhận được cảnh báo: Warning: SuexecUserGroup directive requires SUEXEC wrapper): chmod 4755 /usr/sbin/suexec2 Và sau đó khởi động lại Apache như bình thường: /etc/init.d/apache2 restart Kiểm tra Để kiểm tra, chúng ta sẽ tạo file test PHP nho nhỏ, như ví dụ với web site www.example1.com: vi /srv/www/web1/web/info.php <?php [...]... (/etc /php5/ fastcgi/php.ini) tới thư mục /srv/www/web2/ làm cho www.example2.com gọi file php.ini trực tiếp từ thư mục /srv/www/web2/: cp /etc /php5/ fastcgi/php.ini /srv/www/web2/ chown web2:web2 /srv/www/web2/php.ini (tại đây, các bạn có thể /srv/www/web2/php.ini theo ý thích) Tiếp theo, mở file /srv/www/php-fcgi-scripts/web2/php-fcgi-starter …: vi /srv/www/php-fcgi-scripts/web2/php-fcgi-starter và. .. chế độ thực thi PHP Ví dụ, nếu ta muốn tắt bỏ module magic_quotes_gpc của www.example2.com thì sẽ làm như sau: vi /srv/www/php-fcgi-scripts/web2/php-fcgi-starter #!/bin/sh PHPRC=/etc /php5/ fastcgi/ export PHPRC export PHP_FCGI_MAX_REQUESTS=5000 export PHP_FCGI_CHILDREN=8 exec /usr/bin/php-cgi -d magic_quotes_gpc=off khởi động lại Apache: /etc/init.d /apache2 restart Tiếp tục, gọi file info.php bằng... /srv/www/php-fcgi-scripts/web2/php-fcgi-starter chèn thêm tham số /srv/www/web2/ vào trong dòng PHPRC: #!/bin/sh PHPRC=/srv/www/web2/ export PHPRC export PHP_FCGI_MAX_REQUESTS=5000 export PHP_FCGI_CHILDREN=8 exec /usr/bin/php-cgi Sau đó khởi động lại Apache: /etc/init.d /apache2 restart Tiếp đó, tạo thêm file phpinfo(); mới dành cho www.example2.com…: vi /srv/www/web2/web/info.php tiếp tục gọi file đó ra bằng trình duyệt...phpinfo(); ?> sau đó gọi file đó qua trình duyệt (http://www.example1.com/info.php) Nếu tất cả quá trình trên hoạt động đúng chức năng, bạn sẽ nhìn thấy kết quả tương tự như sau, đồng thời sẽ thấy hàm CGI/FastCGI trong dòng Server API: Tùy chỉnh file php.ini cho mỗi web site Trên thực tế, mỗi web site đều có mã wrap php-fcgi-starter của riêng... export PHP_FCGI_CHILDREN=8 exec /usr/bin/php-cgi -d magic_quotes_gpc=off khởi động lại Apache: /etc/init.d /apache2 restart Tiếp tục, gọi file info.php bằng trình duyệt (http://www.example2.com/info.php) tìm kiếm dòng magic_quotes_gpc, trình duyệt sẽ chỉ ra tình trạng Off: Chúc các bạn thành công! . Cài đặt Apache2 với module mod_ fcgid và PHP5 trên OpenSUSE 11. 2 Trong bài viết sau, Quản Trị Mạng sẽ giới thiệu với các bạn cách cài đặt Apache2 với. được cài đặt sẵn với PHP5 như 1 phần module của Apache, tắt bỏ module PHP5 như sau: a2dismod php5 Tiếp theo, kích hoạt 2 module suexec và fcgid: a2enmod

Ngày đăng: 26/01/2014, 04:20

Từ khóa liên quan

Mục lục

  • Cài đặt Apache2 với module mod_fcgid và PHP5 trên OpenSUSE 11.2

Tài liệu cùng người dùng

Tài liệu liên quan