| home > Apache2 PHP5 ImageMagick インストール |
Apache2 PHP5 ImageMagick インストール
■Apache2インストール
[root@ns1 ~]# cd /usr/ports/www/apache22
[root@ns1 apache22]# make WITH_SUEXEC=yes SUEXEC_DOCROOT=/home install clean
[root@ns1 apache22]# cd
■http.conf編集
[root@ns1 ~]# cp /usr/local/etc/apache22/httpd.conf /usr/local/etc/apache22/httpd.conf.org
[root@ns1 ~]# vi /usr/local/etc/apache22/httpd.conf
ServerAdmin you@example.com
↓
ServerAdmin hostmaster@freebsd.orz ←変更
#ServerName www.example.com:80
↓
ServerName www.freebsd.orz:80 ←コメント解除&変更
DocumentRoot "/usr/local/www/apache22/data"
↓
DocumentRoot "/home/hoge/public_html" ←変更
<Directory "/usr/local/www/apache22/data">
↓
<Directory "/home/hoge/public_html"> ←変更
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
#Options Indexes FollowSymLinks
↓
Options Includes ExecCGI FollowSymLinks ←変更
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
#AllowOverride None
↓
AllowOverride All ←変更
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php index.cgi ←変更(index.php index.cgiを追加)
</IfModule>
ErrorLog "/var/log/httpd-error.log"
↓
ErrorLog /var/log/httpd/hoge-error.log ←変更(エラーログ)
<IfModule log_config_module>
CustomLog "/var/log/httpd-access.log" combined
↓
SetEnvIf Request_URI "default\.ida" nolog
SetEnvIf Request_URI "cmd\.exe" nolog
SetEnvIf Request_URI "root\.exe" nolog
SetEnvIf Request_URI "Admin\.dll" nolog
SetEnvIf Request_URI "NULL\.IDA" nolog
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" nolog
CustomLog /var/log/httpd/hoge-access.log combined env=!nolog ←変更
</IfModule>
<IfModule mime_module>
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php ←追加(.phpを使えるようにする)
#AddHandler cgi-script .cgi
↓
AddHandler cgi-script .cgi .pl ←コメント解除&変更(.cgi .plを使えるようにする)
</IfModule>
#Include etc/apache22/extra/httpd-vhosts.conf
↓
Include etc/apache22/extra/httpd-vhosts.conf ←コメント解除
※黄色い部分は環境に合わせて変更してください。
■VirtualHost設定
[root@ns1 ~]# rm /usr/local/etc/apache22/extra/httpd-vhosts.conf
[root@ns1 ~]# vi /usr/local/etc/apache22/extra/httpd-vhosts.conf
↓下記を記入
NameVirtualHost *:80
<VirtualHost *:80>
ServerName any
DocumentRoot /tmp
</VirtualHost>
<VirtualHost *:80>
ServerName www.freebsd.orz
ServerAlias freebsd.orz
ServerAdmin hostmaster@freebsd.orz
DocumentRoot /home/hoge/public_html
SuexecUserGroup hoge hoge
ErrorLog /var/log/httpd/hoge-error.log
CustomLog /var/log/httpd/hoge-access.log combined env=!nolog
</VirtualHost>
※黄色い部分は環境に合わせて変更してください。
■mod_deflate設定
[root@ns1 ~]# vi /usr/local/etc/apache22/Includes/deflate.conf
↓下記を記入
<Location />
# Insert filter
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png|ico|z|taz|t?gz|t?bz2?|zip|lzh|sit|rar|pdf|mp3|ogg|wma|rm|wmv|mov|mpe?g)$ \
no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>
■php5インストール
[root@ns1 ~]# cd /usr/ports/lang/php5
[root@ns1 php5]# make WITH_APACHE=yes install clean
■php5-extensionsインストール
[root@ns1 php5]# cd /usr/ports/lang/php5-extensions
[root@ns1 php5-extensions]# make WITH_GD=yes WITH_MBSTRING=yes WITH_MYSQL=yes install clean
■php.ini設定
[root@ns1 ~]# cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini
[root@ns1 ~]# chmod 644 /usr/local/etc/php.ini
[root@ns1 ~]# vi /usr/local/etc/php.ini
expose_php = On
↓
expose_php = Off ←変更
;default_charset = "iso-8859-1"
↓
default_charset = "UTF-8" ←コメント解除&変更
;mbstring.language = Japanese
↓
mbstring.language = Japanese ←コメント解除
;mbstring.internal_encoding = EUC-JP
↓
mbstring.internal_encoding = UTF-8 ←コメント解除&変更
;mbstring.http_input = auto
↓
mbstring.http_input = auto ←コメント解除
;mbstring.http_output = SJIS
↓
mbstring.http_output = pass ←コメント解除&変更
;mbstring.encoding_translation = Off
↓
mbstring.encoding_translation = Off ←コメント解除
;mbstring.detect_order = auto
↓
mbstring.detect_order = auto ←コメント解除
;mbstring.substitute_character = none;
↓
mbstring.substitute_character = none; ←コメント解除
■ImageMagickインストール
[root@ns1 ~]# cd /usr/ports/graphics/ImageMagick
[root@ns1 ImageMagick]# make install clean
[root@ns1 ImageMagick]# cd
■logディレクトリ作成
[root@ns1 ~]# mkdir /var/log/httpd
[root@ns1 ~]# chown www: /var/log/httpd
■Apache2起動
[root@ns1 ~]# vi /etc/rc.conf
apache22_enable="YES" ←追加(apache22起動)
[root@ns1 ~]# /usr/local/etc/rc.d/apache22 start
■ログローテーション
[root@ns1 ~]# vi /usr/local/etc/logrotate.d/apache22
↓下記を記入
/var/log/httpd/*log {
daily
rotate 4
create
nocompress
missingok
sharedscripts
postrotate
/usr/local/sbin/apachectl -k graceful
endscript
}
ヒント
ログローテーションをインストールしてない場合はこちらを参照。
外部に公開する場合
プロトコル(TCP)ポート80番(HTTP)を開放。

