APACHEとPHPのアップグレード
Apache HTTP Server 2.4.3が出ていたので,Apacheのアップグレード対応しようと思いましたが、
2.2.xxの方が安定してそうだったので2.2.22でアップグレード。
——————–
[root@aws bin]# /usr/local/apache2/bin/httpd -v Server version: Apache/2.2.22 (Unix) Server built: Sep 8 2012 22:42:21 [root@aws bin]# /usr/local/bin/php -v PHP 5.4.6 (cli) (built: Sep 9 2012 00:34:45) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies [root@aws bin]#
—————————————————————
apacheインストール
Apache HTTP Server 2.2.22 (httpd)
http://httpd.apache.org/download.cgi#apache24
—————————————————————
apacheのダウンロード
[root@aws src]# <code>wget http://ftp.kddilabs.jp/infosystems/apache//httpd/httpd-2.2.22.tar.gz --2012-09-08 22:33:01-- http://ftp.kddilabs.jp/infosystems/apache//httpd/httpd-2.2.22.tar.gz Resolving ftp.kddilabs.jp... 192.26.91.193, 2001:200:601:10:206:5bff:fef0:466c Connecting to ftp.kddilabs.jp|192.26.91.193|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 7200529 (6.9M) [application/x-gzip] Saving to: “httpd-2.2.22.tar.gz” 100%[=========================================================>] 7,200,529 3.59M/s in 1.9s 2012-09-08 22:33:03 (3.59 MB/s) - “httpd-2.2.22.tar.gz” saved [7200529/7200529] </code> [root@aws src]# [root@aws src]# ls -l total 377160 -rw-r--r-- 1 root root 7200529 Jan 30 2012 httpd-2.2.22.tar.gz -rw-r--r-- 1 root root 6137268 Aug 20 13:22 httpd-2.4.3.tar.gz -rw-rw-r-- 1 ec2-user ec2-user 186355822 Jul 6 23:07 mysql-5.5.25a-linux2.6-x86_64.tar.gz -rw-rw-r-- 1 ec2-user ec2-user 186504948 Aug 26 11:37 mysql-5.5.27-linux2.6-x86_64.tar.gz [root@aws src]# <strong>apache tarの展開</strong> [root@aws src]# tar xzvf httpd-2.2.22.tar.gz httpd-2.2.22/ httpd-2.2.22/emacs-style httpd-2.2.22/httpd.dsp httpd-2.2.22/libhttpd.dsp httpd-2.2.22/.deps httpd-2.2.22/Makefile.in httpd-2.2.22/include/ httpd-2.2.22/include/scoreboard.h httpd-2.2.22/include/ap_regkey.h httpd-2.2.22/include/ap_compat.h httpd-2.2.22/include/http_config.h httpd-2.2.22/include/util_time.h httpd-2.2.22/include/ap_mmn.h [省略] httpd-2.2.22/libhttpd.dep httpd-2.2.22/configure.in httpd-2.2.22/VERSIONING httpd-2.2.22/README httpd-2.2.22/LAYOUT httpd-2.2.22/buildconf httpd-2.2.22/.gdbinit [root@aws src]# [root@aws src]# ls -l total 377164 drwxr-xr-x 11 500 ec2-user 4096 Jan 25 2012 httpd-2.2.22 -rw-r--r-- 1 root root 7200529 Jan 30 2012 httpd-2.2.22.tar.gz -rw-r--r-- 1 root root 6137268 Aug 20 13:22 httpd-2.4.3.tar.gz -rw-rw-r-- 1 ec2-user ec2-user 186355822 Jul 6 23:07 mysql-5.5.25a-linux2.6-x86_64.tar.gz -rw-rw-r-- 1 ec2-user ec2-user 186504948 Aug 26 11:37 mysql-5.5.27-linux2.6-x86_64.tar.gz [root@aws src]#
展開したApacheのconfigureとmake
[root@aws src]# cd httpd-2.2.22 [root@aws httpd-2.2.22]# pwd /usr/local/src/httpd-2.2.22 [root@aws httpd-2.2.22]#
—————————————————————
■基本コンフィグでconfigureを実行
—————————————————————
<code> ./configure \ --enable-rewrite --enable-expires --enable-so \ --prefix=/usr/local/httpd-2_2_22 </code>
—————————————————————
[root@aws httpd-2.2.22]# ./configure \ > --enable-rewrite --enable-expires --enable-so \ > --prefix=/usr/local/httpd-2_2_22 checking for chosen layout... Apache checking for working mkdir -p... yes checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu Configuring Apache Portable Runtime library ... checking for APR... yes setting CC to "gcc" setting CPP to "gcc -E" setting CFLAGS to " -pthread" setting CPPFLAGS to " -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE" setting LDFLAGS to " " Configuring Apache Portable Runtime Utility library... checking for APR-util... yes checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no [省略] config.status: creating docs/conf/extra/httpd-vhosts.conf config.status: creating include/ap_config_layout.h config.status: creating support/apxs config.status: creating support/apachectl config.status: creating support/dbmmanage config.status: creating support/envvars-std config.status: creating support/log_server_status config.status: creating support/logresolve.pl config.status: creating support/phf_abuse_log.cgi config.status: creating support/split-logfile config.status: creating build/rules.mk config.status: creating build/pkg/pkginfo config.status: creating build/config_vars.sh config.status: creating include/ap_config_auto.h config.status: executing default commands [root@aws httpd-2.2.22]# [root@aws httpd-2.2.22]# make Making all in srclib make[1]: Entering directory `/usr/local/src/httpd-2.2.22/srclib' Making all in pcre make[2]: Entering directory `/usr/local/src/httpd-2.2.22/srclib/pcre' make[3]: Entering directory `/usr/local/src/httpd-2.2.22/srclib/pcre' [省略] make[1]: Leaving directory `/usr/local/src/httpd-2.2.22' [root@aws httpd-2.2.22]# [root@aws httpd-2.2.22]# ls -l /usr/local/ total 48 drwxr-xr-x 2 root root 4096 May 27 09:00 bin drwxr-xr-x 2 root root 4096 Jan 6 2012 etc drwxr-xr-x 2 root root 4096 Jan 6 2012 games drwxr-xr-x 3 root root 4096 May 27 09:00 include drwxr-xr-x 2 root root 4096 May 26 23:12 lib drwxr-xr-x 3 root root 4096 Mar 24 17:06 lib64 drwxr-xr-x 2 root root 4096 Jan 6 2012 libexec lrwxrwxrwx 1 root root 39 Aug 26 12:09 mysql -> /usr/local/mysql-5.5.27-linux2.6-x86_64 drwxrwxr-x 13 mysql mysql 4096 Jul 7 04:44 mysql-5.5.25a-linux2.6-x86_64 drwxr-xr-x 14 mysql mysql 4096 Aug 26 12:09 mysql-5.5.27-linux2.6-x86_64 drwxr-xr-x 2 root root 4096 Jan 6 2012 sbin drwxr-xr-x 6 root root 4096 Mar 24 17:06 share drwxr-xr-x 3 root root 4096 Sep 8 22:35 src [root@aws httpd-2.2.22]# [root@aws httpd-2.2.22]# make install Making install in srclib make[1]: Entering directory `/usr/local/src/httpd-2.2.22/srclib' Making install in pcre make[2]: Entering directory `/usr/local/src/httpd-2.2.22/srclib/pcre' make[3]: Entering directory `/usr/local/src/httpd-2.2.22/srclib/pcre' make[3]: Leaving directory `/usr/local/src/httpd-2.2.22/srclib/pcre' make[2]: Leaving directory `/usr/local/src/httpd-2.2.22/srclib/pcre' make[2]: Entering directory `/usr/local/src/httpd-2.2.22/srclib' make[2]: Leaving directory `/usr/local/src/httpd-2.2.22/srclib' make[1]: Leaving directory `/usr/local/src/httpd-2.2.22/srclib' [省略] mkdir /usr/local/httpd-2_2_22/build Installing man pages and online manual mkdir /usr/local/httpd-2_2_22/man mkdir /usr/local/httpd-2_2_22/man/man1 mkdir /usr/local/httpd-2_2_22/man/man8 mkdir /usr/local/httpd-2_2_22/manual make[1]: Leaving directory `/usr/local/src/httpd-2.2.22' [root@aws httpd-2.2.22]# [root@aws httpd-2.2.22]# ls -l /usr/local/ total 52 drwxr-xr-x 2 root root 4096 May 27 09:00 bin drwxr-xr-x 2 root root 4096 Jan 6 2012 etc drwxr-xr-x 2 root root 4096 Jan 6 2012 games drwxr-xr-x 14 root root 4096 Sep 8 22:44 httpd-2_2_22 drwxr-xr-x 3 root root 4096 May 27 09:00 include drwxr-xr-x 2 root root 4096 May 26 23:12 lib drwxr-xr-x 3 root root 4096 Mar 24 17:06 lib64 drwxr-xr-x 2 root root 4096 Jan 6 2012 libexec lrwxrwxrwx 1 root root 39 Aug 26 12:09 mysql -> /usr/local/mysql-5.5.27-linux2.6-x86_64 drwxrwxr-x 13 mysql mysql 4096 Jul 7 04:44 mysql-5.5.25a-linux2.6-x86_64 drwxr-xr-x 14 mysql mysql 4096 Aug 26 12:09 mysql-5.5.27-linux2.6-x86_64 drwxr-xr-x 2 root root 4096 Jan 6 2012 sbin drwxr-xr-x 6 root root 4096 Mar 24 17:06 share drwxr-xr-x 3 root root 4096 Sep 8 22:35 src [root@aws httpd-2.2.22]#
インストール後にシンボリックリンク作成
後でバージョンアップや切戻しを楽にするた為。
[root@aws local]# ln -s /usr/local/httpd-2_2_22 /usr/local/apache2 [root@aws local]# ls -l total 52 lrwxrwxrwx 1 root root 23 Sep 8 22:47 apache2 -> /usr/local/httpd-2_2_22 drwxr-xr-x 2 root root 4096 May 27 09:00 bin drwxr-xr-x 2 root root 4096 Jan 6 2012 etc drwxr-xr-x 2 root root 4096 Jan 6 2012 games drwxr-xr-x 14 root root 4096 Sep 8 22:44 httpd-2_2_22 drwxr-xr-x 3 root root 4096 May 27 09:00 include drwxr-xr-x 2 root root 4096 May 26 23:12 lib drwxr-xr-x 3 root root 4096 Mar 24 17:06 lib64 drwxr-xr-x 2 root root 4096 Jan 6 2012 libexec lrwxrwxrwx 1 root root 39 Aug 26 12:09 mysql -> /usr/local/mysql-5.5.27-linux2.6-x86_64 drwxrwxr-x 13 mysql mysql 4096 Jul 7 04:44 mysql-5.5.25a-linux2.6-x86_64 drwxr-xr-x 14 mysql mysql 4096 Aug 26 12:09 mysql-5.5.27-linux2.6-x86_64 drwxr-xr-x 2 root root 4096 Jan 6 2012 sbin drwxr-xr-x 6 root root 4096 Mar 24 17:06 share drwxr-xr-x 3 root root 4096 Sep 8 22:35 src [root@aws local]#
アカウントは既に作成済み
[root@aws local]# cat /etc/passwd | grep apache2 apache:x:558:558:Apache:/usr/local/apache2:/sbin/nologin [root@aws local]#
※フォルダー権限等も既に設定済み。
init.dの変更・作成
---------------------------------------------------------------------------------------- [root@aws local]# vi /etc/init.d/httpd2 [root@aws local]# chmod 755 /etc/init.d/httpd2 ---------------------------------------------------------------------------------------- [BASH] #!/bin/bash # # Startup script for Apache Web Server # # chkconfig: 345 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: /usr/local/apache2/conf/httpd.conf PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/usr/bin:/bin CMDPATH=/usr/local/apache2/bin/ CMD=apachectl test -f $CMDPATH$CMD || exit 0 start() { echo -n "Starting httpd ... " $CMDPATH$CMD start echo "done." } stop() { echo -n "Stopping httpd ... " $CMDPATH$CMD stop echo "done." } case "$1" in start) start ;; stop) stop ;; restart|force-reload) stop sleep 2 start ;; *) echo "Usage: /etc/rc.d/init.d/rc.httpd2 {start|stop|restart}" exit 1 ;; esac exit 0 [/BASH] ---------------------------------------------------------------------------------------- [root@aws local]# ls -l /etc/init.d/httpd2 -rwxr-xr-x 1 root root 870 Sep 8 23:00 /etc/init.d/httpd2 [root@aws local]# <strong>OS起動時の自動起動設定</strong> [root@aws local]# /sbin/chkconfig httpd2 on [root@aws local]# /sbin/chkconfig --list httpd2 httpd2 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@aws local]#
PHPインストール・バージョンアップ
—————————————————————————————-
■PHPインストール php-5.4.6.tar.gz 13,964,954 bytes
http://jp.php.net/get/php-5.4.6.tar.gz/from/a/mirror
—————————————————————————————-
<code>./configure \ --prefix=/usr/local/php-5.4.6 --with-config-file-path=/etc \ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql \ --enable-sockets</code>
—————————————————————————————-
[root@aws php-5.4.6]# ./configure \ > --prefix=/usr/local/php-5.4.6 --with-config-file-path=/etc \ > --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql \ > --enable-sockets checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for a sed that does not truncate output... /bin/sed checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu checking for cc... cc [省略] Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating main/php_config.h config.status: executing default commands [root@aws php-5.4.6]#
メモ:PHPインストール時にエラーが出たので依存関係解決
—————————————————————————————-
[root@aws php-5.4.6]# yum install libxml2
[root@aws php-5.4.6]# yum install libxml2-devel
—————————————————————————————-
[root@aws php-5.4.6]# make install Installing PHP SAPI module: apache2handler /usr/local/httpd-2_2_22/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp5.la /usr/local/httpd-2_2_22/modules /usr/lib64/apr-1/build/libtool --mode=install cp libphp5.la /usr/local/httpd-2_2_22/modules/ libtool: install: cp .libs/libphp5.so /usr/local/httpd-2_2_22/modules/libphp5.so libtool: install: cp .libs/libphp5.lai /usr/local/httpd-2_2_22/modules/libphp5.la libtool: install: warning: remember to run `libtool --finish /usr/local/src/php-5.4.6/libs' chmod 755 /usr/local/httpd-2_2_22/modules/libphp5.so [activating module `php5' in /usr/local/httpd-2_2_22/conf/httpd.conf] Installing PHP CLI binary: /usr/local/php-5.4.6/bin/ Installing PHP CLI man page: /usr/local/php-5.4.6/php/man/man1/ Installing PHP CGI binary: /usr/local/php-5.4.6/bin/ Installing build environment: /usr/local/php-5.4.6/lib/php/build/ Installing header files: /usr/local/php-5.4.6/include/php/ Installing helper programs: /usr/local/php-5.4.6/bin/ program: phpize program: php-config Installing man pages: /usr/local/php-5.4.6/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/php-5.4.6/lib/php/ [PEAR] Archive_Tar - installed: 1.3.7 [PEAR] Console_Getopt - installed: 1.3.0 [PEAR] Structures_Graph- installed: 1.0.4 [PEAR] XML_Util - installed: 1.2.1 [PEAR] PEAR - installed: 1.9.4 /usr/local/src/php-5.4.6/build/shtool install -c ext/phar/phar.phar /usr/local/php-5.4.6/bin ln -s -f /usr/local/php-5.4.6/bin/phar.phar /usr/local/php-5.4.6/bin/phar Installing PDO headers: /usr/local/php-5.4.6/include/php/ext/pdo/ [root@aws php-5.4.6]# [root@aws local]# <code>ln -sfn /usr/local/php-5.4.6/bin/php /usr/local/bin/php</code> [root@aws local]# <code>ln -sfn /usr/local/php-5.4.6/bin/php-config /usr/local/bin/php-config</code> [root@aws local]# <code>ln -sfn /usr/local/php-5.4.6/bin/phpize /usr/local/bin/phpize</code> [root@aws local]# <code>ln -sfn /usr/local/php-5.4.6/lib/php /usr/local/lib/php</code> <a href="http://variable.jp/wp-content/uploads/2012/09/php-symbolic.jpg"><img src="http://variable.jp/wp-content/uploads/2012/09/php-symbolic.jpg" alt="PHP" title="php-symbolic" width="633" height="256" /></a> <strong>php.iniの設定変更(セキュリティ・MYSQL Socket調整)</strong> [root@aws local]# cp -rp /usr/local/src/php-5.4.6/php.ini-production /etc/php.ini [root@aws local]# vi /etc/php.ini [root@aws local]# cat /etc/php.ini | egrep -i "expose_php|mysql.default_socket" ; expose_php = On expose_php = Off pdo_mysql.default_socket= ;mysql.default_socket = mysql.default_socket = /usr/local/mysql/data/mysql.sock [root@aws local]#
—————————————————————————————-
PHP設定メモ:
—————————————————————————————-
register_globals
http://php.net/manual/ja/ini.core.php
この機能は PHP 5.3.0 で 非推奨となり、 PHP 5.4.0 で削除されました。
register_globals は、 variables_order ディレクティブの影響を受けます。
—————————————————————————————-
—————————————————————————————-
LoadModules,Rewriteを利用する為にFollowSymLinksとAllowOverrideを設定
—————————————————————————————-
[root@aws conf]# cat httpd.conf | egrep -i "php|Options" LoadModule php5_module modules/libphp5.so # Options Indexes FollowSymLinks Options FollowSymLinks DirectoryIndex index.php AddType application/x-httpd-php .php [root@aws conf]# [root@aws local]# /etc/init.d/httpd2 restart Stopping httpd ... done. Starting httpd ... done. [root@aws local]#