Linuxサーバ奮戦記 ---インストール・設定編--- (Mod.11Feb2009) >>TOP
- Perlのインストール
- Apache2.2のインストール
- PHP5のインストール
知らなかった便利なこと…
Linuxでは設定をコマンド入力していくことが多いのですが特にパス,ファイル名やフォルダ名の長い文字数のものがよくあります。これら長い文字を入力していくのにうんざりきますが,Tabキーを使用すれば手間が省けることがわかりました。
例: 下記のファイルの展開で tar zxvf A まで入力した後 Tabキー を押せば存在するものが表示されます。もし表示されなけばtar
zxvf Ac まで入力した後 Tabキーを押していきます。少しは楽になります。
Perlのインストール
http://www.activestate.com/ のサイトから ActivePerl-5.6.1.638-i686-linux.tar.gz をダウンロード。
保存先は /usr/local/src とします。あえてActivePerl-5.6.Xを使ってるのはGDやGDGraphなどのモジュールを考えてのことである。ActivePerl-5.8.1では使えなったです。
まずはスーパーユーザになって設定します。
$su
<パスワードを入力>
# cd /usr/local/src
# tar zxvf ActivePerl-5.6.1.638-i686-linux.tar.gz
# cd ActivePerl-5.6.1.638
# ./install.sh
---
Enter top level directory for install [/usr/local/ActivePerl-5.6]
/usr/local
---
Enable PPM3 to send profile into ASPN? [n]
n
---
Proceed?[y] y
---
このインストールよりCGI・SSIでのPerlのパスは
/usr/local/bin/perl と設定すればよいことになります。
確認方法: which perl と入力して /usr/local/bin/perl と表示されればOK。
Apache2.2のインストール (28Jan2009)
http://www.apache.jp/ のサイトから httpd-2.2.11.tar.gz をダウンロード。
保存先は /usr/local/src とします。
まずはスーパーユーザになって設定します。
$ su
<パスワードを入力>
OpenSSLもインストールすることにする。
下記の様にWebサイト(http://www.openssl.org/source/)からダウンロード(保存先は /usr/local/src)とします。
# cd /usr/local/src
# tar zxvf openssl-0.9.8j.tar.gz
# cd openssl-0.9.8j
# ./config
# make
# make install
# cd /usr/local/src
# tar zxvf httpd-2.2.11.tar.gz
# cd httpd-2.2.11
# ./configure --enable-so --enable-ssl --with-ssl=/usr/local/ssl --enable-deflate=shared
--enable-dav_fs=shared --enable-dav=shared --enable-setenvif=shared --enable-alias=shared
--enable-auth_digest=shared --enable-authn_file=shared --enable-proxy=shared
--enable-proxy_connect=shared --enable-proxy_ftp=shared --enable-proxy_http=shared
--enable-proxy_ajp=shared --enable-proxy_balancer=shared --enable-cache=shared
--enable-disk-cache=shared --enable-mem-cache=shared
# make
# make install
インストール完了。
標準では /usr/local/apache2 以下にインストールされます。
設定は httpd.conf (/usr/local/apache2/conf)を
vi エディタかテキストエディタで編集します。
vi エディタだと PuTTy (PuTTYjp日本語版)などのSSH通信ソフトを使うことで Windows PC から変更が可能になります。
上記でmod_sslがインストールされているのでセキュアサーバを立ち上げてみます。
# openssl genrsa -out server_key.pem 1024
Generating RSA private key, 1024 bit long modulus
.............++++++
.....++++++
e is 65537 (0x10001) |
# openssl req -new -key server_key.pem -out server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:JP
State or Province Name (full name) [Berkshire]:kyoto
Locality Name (eg, city) [Newbury]:kyoto
Organization Name (eg, company) [My Company Ltd]:yuyuyu
Organizational Unit Name (eg, section) []:ayu
Common Name (eg, your name or your server's hostname) []:www.yuyuyu.jp
Email Address []:admin@yuyuyu.jp
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []: |
# openssl x509 -req -in server.csr -signkey server_key.pem -out server.crt
-days 365
# mv server_key.pem server.key
# cp server.crt /usr/local/apache2/conf/
# cp server.key /usr/local/apache2/conf/
Apache2 の httpd.conf を編集する。
#vi /usr/local/apache2/conf/httpd.conf
・・・・・・・・・・・・・・・・・ # Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf
・・・・・・・・・・・・・・・・・
|
以上でSSLの設定は終わり。
Apache2.2の起動
# /usr/local/apache2/bin/apachectl start
WEBブラウザを開き http://localhost/ としてApacheの画面が表示されればOK。
終了は以下のように入力。(SSLはhttps://localhost/)
# /usr/local/apache2/bin/apachectl stop
httpd.confを変更後再読み込みは以下の様に入力。
# /usr/local/apache2/bin/apachectl restart
Apache2の自動起動の設定
Linuxを再起動するとWEBサーバは起動されません。マニュアルで上記のように入力しなければなりません。
PCを起動したら自動でスタートさせるようにすれば手間が省けます。以下の様に設定すればよいようです(他にはシンボリックリンクで行うやり方があるようです)。
$ su
<パスワードを入力>
---- 方法1 ----
# vi /etc/rc.local
以下の1行を追加して書き込み終了します。
/usr/local/apache2/bin/apachectl start
---- 方法2 ----
# cd /usr/local/src/httpd-2.2.11/build/rpm/
# cp -rp httpd.init /etc/rc.d/init.d/httpd
# vi /etc/rc.d/init.d/httpd (赤色に変更?)
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /etc/httpd/conf/httpd.conf
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache2/bin/apachectl
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
prog=httpd
RETVAL=0
# check for 1.3 configuration
check13 () {
CONFFILE=/usr/local/apache2/conf/httpd.conf
GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"
GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"
GONE="${GONE}AccessConfig|ResourceConfig)"
if grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then
echo
echo 1>&2 " Apache 1.3 configuration directives found"
echo 1>&2 " please read @docdir@/migration.html"
failure "Apache 1.3 config directives test"
echo
exit 1
fi
}
# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start() {
echo -n $"Starting $prog: "
check13 || exit 1
daemon $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd /usr/local/apache2/logs/httpd.pid
}
reload() {
echo -n $"Reloading $prog: "
check13 || exit 1
killproc $httpd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f /usr/local/apache2/logs/httpd.pid ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL |
# chkconfig --add httpd [サービスに追加]
# chkconfig httpd on [自動起動設定]
方法2で設定した場合は,通常の起動・停止等は以下の様にしてもOK。
# /etc/rc.d/init.d/httpd start [起動]
# /etc/rc.d/init.d/httpd stop [停止]
# /etc/rc.d/init.d/httpd restart [再起動]
vi エディタでは
カーソルは←↑↓→で移動できます。
i (キーを押す)で入力モードになります。
入力モードから抜けるときは Esc キーを押します。
削除したいときは x キーを押します(1文字ずつ消す)。
設定を保存して終了するには Shift を押したまま zz
と押します。あるいは
:wq と入力します。
設定を保存せずに終了するには :q! と入力します。
PHPのインストール (02Aug2009)
将来WebMail(SquirrelMail)をインストールすることも考えてビルドしています。
http://www.php.net/ のサイトから php-5.2.10.tar.gz または php-5.3.0.tar.gz をダウンロード。
保存先は /usr/local/src とします。
まずはスーパーユーザになって設定します。
$ su
<パスワードを入力>
# cd /usr/local/src
# tar zxvf php-5.2.10.tar.gz
# cd php-5.2.10
# ./configure --with-apxs2=/usr/local/apache2/bin/apxs
--enable-zend-multibyte --enable-mbstring
--enable-mbregex (上の行から改行せずにここまで入力することに注意)
# make
# make install
# cp php.ini-dist /usr/local/lib/php.ini (php-5.2.x) # cp php.ini-production /usr/local/lib/php.ini (php-5.3.x)
上記Apache2のhttpd.confで以下の行を追加します。
LoadModule php5_module modules/libphp5.so (←この行だけhttpd.confに自動的に追加されるようだ)
AddType application/x-httpd-php .php
Apacheサーバを起動しなおす。
# /usr/local/apache2/bin/apachectl restart
または
# /ete/rc.d/init.d/apache restart
その他
PHP 5.3.x では Apache2 での error ログに多くのエラーが出力されかなり容量となっていたので設定ファイルを変更してみた。
Apache2 のエラーログ例:
PHP Warning: date(): It is not safe to rely on the system's timezone settings.
You are *required* to use the date.timezone setting or the date_default_timezone_set()
function. In case you used any of those methods and you are still getting
this warning, you most likely misspelled the timezone identifier. We selected
'Asia/Tokyo' for 'JST/9.0/no DST' instead in ...... |
対策例として php.ini を下記の様に変更
・・・・・・・・・・・・・・・・・
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = 'Asia/Tokyo'
・・・・・・・・・・・・・・・・・ |
|
|