Apache+suExec構築メモ
Apache+suExecでのWebサーバの構築
CentOS4.4でのインストール記録です。
suExec機能を持ったサーバ構築を行う。参考:suEXEC サポート - Apache HTTP サーバ
PHPについてはCGI版はこの機能で動作するが、モジュール版はUserディレクティブで指定したユーザで動作する。
このサーバはソフト開発の実験用として使いたいので、PHPやCGIの実行はユーザ毎にアクセス権を持たせて実行させたいが、提供されているApacheのRPMパッケージでは設定できないようだ。コンパイルしないと無理。
suEXEC のルートディレクトリが /var/www になる。
サーバー管理者のホームページスペースは初期設定で /var/www/ がドキュメントルートなので問題ないのですが、
ユーザのホームディレクトリは /home になり、suEXEC のルートディレクトリと異なるため CGI が正常に動作しません。
この問題を解消するために RPM パッケージをカスタマイズします。
また PHP、Ruby をインストールする。
ソースファイルの編集
ソースファイルの入手
centosplusにソースがありましたので、これを使います。
$ sudo wget ftp://ftp.riken.jp/Linux/caos/centos/4.4/centosplus/SRPMS/httpd-2.0.59-1.el4s1.5.el4.centos.src.rpm
--20:45:05-- ftp://ftp.riken.jp/Linux/caos/centos/4.4/centosplus/SRPMS/httpd-2.0.59-1.el4s1.5.el4.centos.src.rpm
=> `httpd-2.0.59-1.el4s1.5.el4.centos.src.rpm'
ftp.riken.jp をDNSに問いあわせています... 134.160.38.1
ftp.riken.jp|134.160.38.1|:21 に接続しています... 接続しました。
anonymous としてログインしています... ログインしました!
==> SYST ... 完了しました。 ==> PWD ... 完了しました。
==> TYPE I ... 完了しました。 ==> CWD /Linux/caos/centos/4.4/centosplus/SRPMS ... 完了しました。
==> PASV ... 完了しました。 ==> RETR httpd-2.0.59-1.el4s1.5.el4.centos.src.rpm ... 完了しました。
長さ: 6,237,534 (5.9M) (確証はありません)
100%[============================================>] 6,237,534 175.77K/s ETA 00:00
20:45:44 (215.87 KB/s) - `httpd-2.0.59-1.el4s1.5.el4.centos.src.rpm' を保存しました [6237534]
$ sudo mkdir -p /usr/src/redhat/SOURCES $ sudo rpm -ihv httpd-2.0.59-1.el4s1.5.el4.centos.src.rpm 1:httpd 警告: user buildcentos does not exist - using root
とエラーがでますので、buildcentosというユーザとグループを作成します。
$ sudo useradd -s /sbin/nologin buildcentos
再度実行する。
$ sudo rpm -ihv httpd-2.0.59-1.el4s1.5.el4.centos.src.rpm 1:httpd ########################################### [100%]
今度は大丈夫でした。
$ sudo vi /usr/src/redhat/SPECS/httpd.spec
%define contentdir /var/www → %define contentdir /home へ変更する。 %define suexec_caller apache %define mmn 20020903 %define vstring CentOS %define distro CentOS Application Stack
リビルドの準備
$ sudo yum -y install rpm-build autoconf automake libtool
Loading "fastestmirror" plugin Setting up Install Process Setting up repositories dag 100% |=========================| 1.1 kB 00:00 update 100% |=========================| 951 B 00:00 base 100% |=========================| 1.1 kB 00:00 centosplus 100% |=========================| 951 B 00:00 addons 100% |=========================| 951 B 00:00 extras 100% |=========================| 1.1 kB 00:00 Loading mirror speeds from cached hostfile Reading repository metadata in from local files Reducing Dag RPM Repository for Red Hat Enterprise Linux to included packages only Finished Parsing package install arguments Nothing to do
リビルド
$ sudo rpmbuild --bb /usr/src/redhat/SPECS/httpd.spec
エラー: Failed build dependencies:
xmlto >= 0.0.11 is needed by httpd-2.0.59-1.el4s1.5.i386
apr-devel >= 0.9.4-20 is needed by httpd-2.0.59-1.el4s1.5.i386
apr-util-devel is needed by httpd-2.0.59-1.el4s1.5.i386
pcre-devel is needed by httpd-2.0.59-1.el4s1.5.i386
distcache-devel is needed by httpd-2.0.59-1.el4s1.5.i386
実行するのに不足しているパッケージがあると怒られる。
表示されているパッケージをインストールする。
$ sudo yum -y install xmlto apr-devel apr-util-devel pcre-devel distcache-devel
再度実行する
$ sudo rpmbuild --bb /usr/src/redhat/SPECS/httpd.spec
インストール
$ sudo rpm -ihv --force /usr/src/redhat/RPMS/i386/httpd-2.0.59-1.el4s1.5.i386.rpm \ /usr/src/redhat/RPMS/i386/httpd-debuginfo-2.0.59-1.el4s1.5.i386.rpm \ /usr/src/redhat/RPMS/i386/httpd-devel-2.0.59-1.el4s1.5.i386.rpm \ /usr/src/redhat/RPMS/i386/httpd-manual-2.0.59-1.el4s1.5.i386.rpm \ /usr/src/redhat/RPMS/i386/mod_ssl-2.0.59-1.el4s1.5.i386.rpm Preparing... ########################################### [100%] 1:httpd ########################################### [ 20%] 2:httpd-debuginfo ########################################### [ 40%] 3:httpd-devel ########################################### [ 60%] 4:httpd-manual ########################################### [ 80%] 5:mod_ssl ########################################### [100%]
今度は大丈夫でした。
PHP Rubyのインストール
PHPは初期設定で4.3.9がインストールされる。PHP5で運用したいので、/etc/yum.repos.d/CentOS-Base.repo
の設定を変更する。
$ sudo vi /etc/yum.repos.d/CentOS-Base.repo
[centosplus]セクションを有効にする。
[centosplus] enabled=1
$ sudo yum -y install php ruby
Loading "fastestmirror" plugin Setting up Install Process Setting up repositories Loading mirror speeds from cached hostfile Reading repository metadata in from local files Reducing Dag RPM Repository for Red Hat Enterprise Linux to included packages only Finished Parsing package install arguments Resolving Dependencies --> Populating transaction set with selected packages. Please wait. ---> Downloading header for ruby to pack into transaction set. ruby-1.8.1-7.EL4.8.i386.r 100% |=========================| 29 kB 00:00 ---> Package ruby.i386 0:1.8.1-7.EL4.8 set to be updated ---> Downloading header for php to pack into transaction set. php-5.1.6-3.el4s1.5.i386. 100% |=========================| 17 kB 00:00 ---> Package php.i386 0:5.1.6-3.el4s1.5 set to be updated --> Running transaction check --> Processing Dependency: php-cli = 5.1.6-3.el4s1.5 for package: php --> Processing Dependency: libruby.so.1.8 for package: ruby --> Processing Dependency: ruby-libs = 1.8.1-7.EL4.8 for package: ruby --> Processing Dependency: php-common = 5.1.6-3.el4s1.5 for package: php --> Restarting Dependency Resolution with new changes. --> Populating transaction set with selected packages. Please wait. ---> Downloading header for ruby-libs to pack into transaction set. ruby-libs-1.8.1-7.EL4.8.i 100% |=========================| 76 kB 00:00 ---> Package ruby-libs.i386 0:1.8.1-7.EL4.8 set to be updated ---> Downloading header for php-cli to pack into transaction set. php-cli-5.1.6-3.el4s1.5.i 100% |=========================| 16 kB 00:00 ---> Package php-cli.i386 0:5.1.6-3.el4s1.5 set to be updated ---> Downloading header for php-common to pack into transaction set. php-common-5.1.6-3.el4s1. 100% |=========================| 19 kB 00:00 ---> Package php-common.i386 0:5.1.6-3.el4s1.5 set to be updated --> Running transaction check Dependencies Resolved ============================================================================= Package Arch Version Repository Size ============================================================================= Installing: php i386 5.1.6-3.el4s1.5 centosplus 1.1 M ruby i386 1.8.1-7.EL4.8 update 156 k Installing for dependencies: php-cli i386 5.1.6-3.el4s1.5 centosplus 2.0 M php-common i386 5.1.6-3.el4s1.5 centosplus 135 k ruby-libs i386 1.8.1-7.EL4.8 update 1.5 M Transaction Summary ============================================================================= Install 5 Package(s) Update 0 Package(s) Remove 0 Package(s) Total download size: 4.9 M Downloading Packages: (1/5): ruby-1.8.1-7.EL4.8 100% |=========================| 156 kB 00:00 (2/5): ruby-libs-1.8.1-7. 100% |=========================| 1.5 MB 00:06 (3/5): php-5.1.6-3.el4s1. 100% |=========================| 1.1 MB 00:06 (4/5): php-cli-5.1.6-3.el 100% |=========================| 2.0 MB 00:10 (5/5): php-common-5.1.6-3 100% |=========================| 135 kB 00:00 Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing: php-common ######################### [1/5] Installing: php-cli ######################### [2/5] Installing: ruby-libs ######################### [3/5] Installing: ruby ######################### [4/5] Installing: php ######################### [5/5] Installed: php.i386 0:5.1.6-3.el4s1.5 ruby.i386 0:1.8.1-7.EL4.8 uby-libs.i386 0:1.8.1-7.EL4.8 Complete!
httpd.confの設定
主な設定内容
- バージョン情報を表示しない
- 不必要なモジュールは省く
- CGI 暴走対策に CPU を 7 秒以上使わせない
- ドキュメントルートを /home/system/webmaster/root に変更
- CGI、SSI、PHP、Ruby、Python を使用可能
- 文字化け対策に AddDefaultCharset? UTF-8 をコメントアウト
$ sudo vi /etc/httpd/conf/httpd.conf
ServerTokens Prod
ServerRoot "/etc/httpd"
PidFile run/httpd.pid
Timeout 120
RLimitCPU 5 10
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
<IfModule worker.c>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
Listen 80
#-------------------------------------------------------------------------------
LoadModule access_module modules/mod_access.so
LoadModule auth_module modules/mod_auth.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
#-------------------------------------------------------------------------------
# Server status, server info
#-------------------------------------------------------------------------------
LoadModule status_module modules/mod_status.so
LoadModule info_module modules/mod_info.so
#-------------------------------------------------------------------------------
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule mime_module modules/mod_mime.so
LoadModule rewrite_module modules/mod_rewrite.so
#-------------------------------------------------------------------------------
LoadModule dir_module modules/mod_dir.so
LoadModule userdir_module modules/mod_userdir.so
#-------------------------------------------------------------------------------
LoadModule alias_module modules/mod_alias.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
#-------------------------------------------------------------------------------
LoadModule suexec_module modules/mod_suexec.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule env_module modules/mod_env.so
LoadModule include_module modules/mod_include.so
Include conf.d/*.conf
User apache
Group apache
ServerAdmin webmaster@hoge.com
ServerName xxx.hoge.com:80
UseCanonicalName Off
DocumentRoot "/home/system/webmaster/root/"
<Directory "/home">
Options ExecCGI IncludesNoExec FollowSymLinks
AllowOverride FileInfo AuthConfig Limit
</Directory>
<IfModule mod_userdir.c>
#UserDir disable
UserDir /home/normal/*/public_html
</IfModule>
DirectoryIndex index.htm index.html index.shtml index.php index.cgi index.rb
AccessFileName .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
TypesConfig /etc/mime.types
DefaultType text/plain
HostnameLookups Off
<Files ~ "\.(php|cgi)$">
HostnameLookups on
</Files>
ErrorLog logs/error_log
LogLevel error
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
SetEnvIf Request_URI "default\.ida" no_log
SetEnvIf Request_URI "cmd\.exe" no_log
SetEnvIf Request_URI "root\.exe" no_log
SetEnvIf Request_URI "Admin\.dll" no_log
SetEnvIf Request_URI "NULL\.IDA" no_log
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" no_log
SetEnvIf Remote_Addr 192.168. no_log
CustomLog logs/access_log combined env=!no_log
ServerSignature Off
#ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
#<Directory "/var/www/cgi-bin">
# AllowOverride None
# Options None
# Order allow,deny
# Allow from all
#</Directory>
IndexOptions FancyIndexing VersionSort NameWidth=*
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*
AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core
AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^
DefaultIcon /icons/unknown.gif
ReadmeName README.html
HeaderName HEADER.html
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
AddLanguage ca .ca
AddLanguage cs .cz .cs
AddLanguage da .dk
AddLanguage de .de
AddLanguage el .el
AddLanguage en .en
AddLanguage eo .eo
AddLanguage es .es
AddLanguage et .et
AddLanguage fr .fr
AddLanguage he .he
AddLanguage hr .hr
AddLanguage it .it
AddLanguage ja .ja
AddLanguage ko .ko
AddLanguage ltz .ltz
AddLanguage nl .nl
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pl .po
AddLanguage pt .pt
AddLanguage pt-BR .pt-br
AddLanguage ru .ru
AddLanguage sv .sv
AddLanguage zh-CN .zh-cn
AddLanguage zh-TW .zh-tw
LanguagePriority en ca cs da de el eo es et fr he hr it ja ko
ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
ForceLanguagePriority Prefer Fallback
#AddDefaultCharset UTF-8
AddType application/x-tar .tgz
AddType application/x-httpd-php .php
AddEncoding x-compress .Z
AddEncoding x-gzip .gz .tgz
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddHandler cgi-script .cgi .pl
AddHandler type-map var
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml .htm .html .cgi .php .rb
Alias /error/ "/home/system/webmaster/error/"
<IfModule mod_negotiation.c>
<IfModule mod_include.c>
<Directory "/home/system/webmaster/error">
AllowOverride None
Options IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
Order allow,deny
Allow from all
LanguagePriority en es de fr
ForceLanguagePriority Prefer Fallback
</Directory>
ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
# ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
ErrorDocument 404 /error/404.html
ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
ErrorDocument 410 /error/HTTP_GONE.html.var
ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
</IfModule>
</IfModule>
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully
#-------------------------------------------------------------------------------
# Server Status,info
#-------------------------------------------------------------------------------
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 192.168.3.0/24
</Location>
<Location /server-info>
SetHandler server-info
Order deny,allow
Deny from all
Allow from 192.168.3.0/24
</Location>
テストして内容の確認を行います。
$ sudo apachectl configtest Syntax error on line 311 of /etc/httpd/conf/httpd.conf: DocumentRoot must be a directory
ドキュメントルートがないと怒られるので作成します。
$ sudo mkdir /home/system
アクセス権は701で作成する。でないと、ユーザのログインが出来なくなる。
$ sudo chmod 701 /home/system
ユーザwebmasterを追加
$ sudo useradd -c"This Site Administrator" -d"/home/system/webmaster" -s /bin/bash webmaster $ sudo passwd webmaster $ su webmaster $ cd ~ $ mkdir root $ chmod 701 root $ su # cd /home # mv error /home/system/webmaster # chown -R webmaster:webmaster /home/system/webmaster/error # chmod 701 /home/system/webmaster/error # chmod 604 /home/system/webmaster/error/*.var # chmod 604 /home/system/webmaster/error/*.html # mv icons /home/system/webmaster # chown -R webmaster:webmaster /home/system/webmaster/icons # chmod 701 /home/system/webmaster/icons # chmod 604 /home/system/webmaster/icons/*.* # chmod 604 /home/system/webmaster/icons/small/*.* # mv manual /home/system/webmaster
$ sudo apachectl configtest Syntax error on line 797 of /etc/httpd/conf/httpd.conf: Invalid command 'LanguagePriority', perhaps mis-spelled or defined by a module not included in the server configuration
LanguagePriority?がロードされていないのに設定があるのでエラーとなっている。
$ sudo vi /etc/httpd/conf/httpd.conf
以下の場所をコメントにする。
#LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
$ sudo apachectl configtest Syntax error on line 804 of /etc/httpd/conf/httpd.conf: Invalid command 'ForceLanguagePriority', perhaps mis-spelled or defined by a module not included in the server configuration
ForceLanguagePriority?がロードされていないのに設定があるのでエラーとなっている。
$ sudo vi /etc/httpd/conf/httpd.conf
804行目のForceLanguagePriority?をコメントにする。
$ sudo apachectl configtest Syntax OK
やっとOKだった。
サービスの起動
$ sudo service httpd start httpd を起動中: [ OK ]
クライアントで確認すると、403エラー!
$ sudo vi /var/log/httpd/error_log
[notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [notice] Digest: generating secret for digest authentication ... [notice] Digest: done [notice] Apache configured -- resuming normal operations [crit] [client 192.168.X.X] (13)Permission denied: /home/system/webmaster/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
アクセス権限でおこられているので、rootディレクトリの権限を変更する。
$ sudo chmod 755 /home/system/ $ sudo chmod 701 /home/system/webmaster/ $ sudo chmod 701 /home/system/webmaster/root/
再度表示したらOK。
サービスの自動起動設定
# chkconfig httpd on
バーチャルホストの設定
バーチャルドメイン環境で suEXEC を有効にするには SuexecUserGroup? を指定する必要があります。
/~ID でアクセスさせたくないドメインは UserDir? disable を設定します。
アクセスログ、エラーログは専用フォルダーを作成し保存しています。
サーバー全体のアクセス統計を取りたいため、アクセスログを /var/log/httpd/access_log にも保存します。
バーチャルドメインは、/etc/httpd/conf.virtual/domain-name/sundomain-name.conf ファイルにて設定し、/etc/httpd/conf/httpd.conf に include します。
# vi /etc/httpd/conf.d/virtual.conf
#--------------#
# Virtual Host #
#--------------#
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
ServerName www.hoge.com
SuexecUserGroup webmaster webmaster
</VirtualHost>
#---------#
# include #
#---------#
Include conf.virtual/*.conf
Include conf.virtual/xxx1.hoge.com/*.conf
Include conf.virtual/xxx2.hoge.com/*.conf
PHPでもユーザ権限で動作させる-suPHP
[[suPHP>http://www.suphp.org/Home.html]]が公式サイト。
所有者権限でphpを動作させることが出来るapacheモジュール。
内部で CGI/CLI 版の php を exec しているだけのようですが。。。
暇があったら入れてみる。
suPHP/Apacheへの設定
# wget http://www.suphp.org/download/suphp-0.6.2.tar.gz # tar zvxf suphp-0.6.2.tar.gz # cd suphp-0.6.2.tar # ./configure --with-min-uid=500 --with-min-gid=500 \ --with-apache-user=apache --with-php=/usr/bin/php-cgi \ --with-logfile=/var/log/httpd/suphp.log --with-apxs=/usr/sbin/apxs \ --sysconfdir=/usr/local/etc --disable-checkpath \ --with-apr=/usr/bin/apr-config --with-setid-mode=owner
# vi /usr/local/etc/suphp.conf
[global] ;Path to logfile logfile=/var/log/httpd/suphp.log ;Loglevel loglevel=info ;User Apache is running as webserver_user=apache ;Path all scripts have to be in docroot=/ ;Path to chroot() to before executing script ;chroot=/mychroot ; Security options allow_file_group_writeable=false allow_file_others_writeable=false allow_directory_group_writeable=false allow_directory_others_writeable=false ;Check wheter script is within DOCUMENT_ROOT check_vhost_docroot=false ;Send minor error messages to browser errors_to_browser=true ;PATH environment variable env_path=/bin:/usr/bin:/usr/local/bin:/usr/local/sbin ;Umask to set, specify in octal notation umask=0022 ; Minimum UID min_uid=100 ; Minimum GID min_gid=100 [handlers] ;Handler for php-scripts x-httpd-php=php:/usr/bin/php-cgi ;Handler for CGI-scripts x-suphp-cgi=execute:!self
suPHP_AddHandler?を使えるようにmod_suphp.cを修正
下記のように修正すると、httpd.confでsuPHP_AddHandler?が使用可能になる。
# vi ./src/apache2/mod_suphp.c
324 AP_INIT_ITERATE("suPHP_AddHandler", suphp_handle_cmd_add_handler, NULL, ACCESS_C ONF, "Tells mod_suphp to handle these MIME-types"),
↓↓
324 AP_INIT_ITERATE("suPHP_AddHandler", suphp_handle_cmd_add_handler, NULL, RSRC_CONF | ACCESS_C ONF, "Tells mod_suphp to handle these MIME-types"),
make,make instlal
make ;make install
# vi /etc/httpd/conf.d/suphp.conf
LoadModule suphp_module modules/mod_suphp.so suPHP_Engine on AddHandler x-httpd-php .php suPHP_AddHandler x-httpd-php
module版PHPによる実行をストップする為に名前変更をする。
# mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.org
Apache再起動
# service httpd restart
# tail -f /var/log/httpd/suphp.log
これにより、CGI/PHPともに自UID/GIDで実行できる。
また、suPHPにより、ディレクトリやファイルのパーミッションが777である場合、実行が強制ストップされる。
(/etc/suphp.confにより変更可能)
また、mod_vhost_aliasを適用することによりバーチャルホスト毎に別UID/GIDで動作することができた。
suExec配下のアクセス権の設定
よく忘れるのでメモ。
1.suExecでないWebサーバの場合
| ファイルの種類 | アクセス権 | 転送モード |
|---|---|---|
| 拡張子が .php .css .js | [644] | アスキーモード |
| 拡張子が .dat | [644] or [666] | アスキーモード |
| 拡張子が .gif .jpeg .jpg | [644] | バイナリモード |
| フォルダ | [755] or [777] |
2.suExecが動作しているサーバーの場合上記の設定では動きません。
| ファイルの種類 | アクセス権 | 転送モード |
|---|---|---|
| 拡張子が .php .css .js | [644]->[604] | アスキーモード |
| 拡張子が .dat | [644]->[604] | アスキーモード |
| [666]->[600] | ||
| 拡張子が .gif .jpeg .jpg | [644]->[604] | バイナリモード |
| フォルダ | [755]->[701] | |
| [777]->[705] or [700] or [701] |
参考URL
OS:CentOS4.4
[カテゴリ:Linux]
[カテゴリ:Apache]
[カテゴリ:PHP]
- http://search.yahoo.co.jp/search?p=class作成&search.x=1&fr=top_ga1_sa&tid=top_ga1_sa&ei=UTF-8&aq=&oq=(1)
- http://www.google.co.jp/search?q=centos ftp アップロード&hl=ja&lr=lang_ja&client=firefox-a&rls=org.mozilla:ja:official&tbs=lr:lang_1ja&prmd=df&ei=JPiBTM3bDIWasAOysv32Bw&start=20&sa=N(1)
- http://www.google.co.jp/search?hl=ja&q=eclipse php 環境設定&aq=0r&aqi=g-r1&aql=&oq=eclipse PHP かんきょう&gs_rfai=(1)
- http://www.google.co.jp/search?aq=f&sourceid=chrome&ie=UTF-8&q=vsftp(1)
- http://www.google.co.jp/search?hl=ja&q=eclipse php apache 設定&aq=0&aqi=g1&aql=&oq=eclipse php apache &gs_rfai=(1)
- http://www.google.co.jp/search?hl=ja&lr=lang_ja&tbs=lr:lang_1ja&q=create database mysql&aq=f&aqi=g-e1g2&aql=&oq=&gs_rfai=(1)
- http://www.google.co.jp/search?client=opera&rls=ja&q=eclipse php 設定&sourceid=opera&ie=utf-8&oe=utf-8(1)
- http://www.google.co.jp/search?q=Invalid command 'AddIconByEncoding', perhaps misspelled&hl=ja&safe=off&client=firefox-a&hs=CaF&rls=org.mozilla:ja-JP-mac:official&source=lnt&tbs=lr:lang_1ja&lr=lang_ja&sa=X&ei=cSiBTKX9OY3WvQOKm6CqBA&ved=0CAcQpwU(1)
- http://www.google.co.jp/search?hl=ja&client=firefox-a&channel=s&rls=org.mozilla:ja:official&q=linux lan HDD 認識 &aq=f&aqi=&aql=&oq=&gs_rfai=(1)
- http://www.google.co.jp/search?hl=ja&lr=&client=firefox-a&rls=org.mozilla:ja:official&channel=s&q=linux LANハードディスク 接続&aq=f&aqi=&aql=&oq=&gs_rfai=(1)
最終更新時間:2007年05月16日 02時07分24秒
TOP