FreeBSD/2つの環境共存
Apache1+PHP4+MySQL4、Apache2+PHP5+MySQL5共存 †
「Apache1+PHP4+MySQL4」と「Apache2+PHP5+MySQL5」の2つの環境を共存させて 特定URLであれば、8080ポートに飛ばす。
イメージ図 †
「Apache2+PHP5+MySQL5」環境構築 †
Apache2.2インストール †
mod_proxyを使えるようにオプションを加える。
$ tar zxvf httpd-2.2.11.tar.gz $ cd httpd-2.2.11 $ ./configure \ --prefix=/usr/local/apache2 \ --enable-so \ --enable-rewrite=shared \ --enable-ssl \ --enable-speling=shared \ --enable-proxy=shared \ --enable-proxy-http=shared $ make # make install
MySQL5インストール †
$ tar zxvf mysql-5.0.83.tar.gz $ cd mysql-5.0.83 $ ./configure \ --prefix=/usr/local/mysql5 \ --with-charset=utf8 \ --with-extra-charsets=all \ --with-mysqld-user=mysql \ --localstatedir=/home/mysql5/data \ --with-unix-socket-path=/tmp/mysql5.sock \ --with-tcp-port=3306 $ make # make install
MySQL5ユーザ作成 †
pw groupadd mysql5 pw useradd mysql5 -g mysql5 -d /usr/local/ -s /usr/sbin/nologin
設定ファイルのコピー †
# cp support-files/my-medium.cnf /etc/my5.cnf # cp support-files/mysql.server /usr/local/etc/rc.d/mysql5.sh # chmod 755 /usr/local/etc/rc.d/mysql5.sh
起動スクリプト修正 †
起動部分に「--defaults-file=/etc/my5.cnf」を追加
# vi /usr/local/etc/rc.d/mysql5.sh 327 $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 & ↓ 327 $bindir/mysqld_safe --defaults-file=/etc/my5.cnf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
MySQL5起動 †
# /usr/local/etc/rc.d/mysql5.sh start
PHP5インストール †
$ tar zxvf php-5.2.10.tar.gz $ cd php-5.2.10 $ ./configure \ --with-apxs2=/usr/local/apache2/bin/apxs \ --prefix=/usr/local/php5 \ --with-mysql=/usr/local/ \ --enable-cli \ --enable-pear \ --with-tsrm-pth \ --with-gd --with-zlib \ --with-freetype-dir=/usr/local \ --with-jpeg-dir=/usr/local \ --with-png-dir=/usr/local \ --enable-force-cgi-redirect \ --enable-mbstring \ --enable-mbstr-enc-trans \ --enable-trans-sid \ --enable-versioning \ --enable-gd-native-ttf \ --enable-gd-jis-conv $ make # make install
php.iniのコピー †
# cp php.ini-dist /usr/local/php5/lib/php.ini
httpd.confに追加 †
AddType application/x-httpd-php .php
「Apache1+PHP4+」の環境構築 †
Apache1.3インストール †
$ tar zxvf apache_1.3.41.tar.gz $ tar zxvf mod_ssl-2.8.31-1.3.41.tar.gz $ ./configure \ --prefix=/usr/local/apache \ --with-apache=../apache_1.3.41 \ --enable-shared=ssl \ --enable-module=ssl \ --with-ssl=/usr \ --enable-module=so \ --enable-module=rewrite \ --enable-shared=rewrite \ $ cd ../apache_1.3.41 $ make $ make certificate # make install
ポートの変更 †
# /usr/local/apache/conf/httpd.conf Listen 80 → Listen 8080
MySQL4インストール †
※MySQL5の方とは、ポートとsocketを変えておく。
$ tar zxvf mysql-4.1.22.tar.gz $ cd mysql-4.1.22 $ ./configure \ --prefix=/usr/local/mysql4 \ --with-charset=ujis \ --with-extra-charsets=all \ --with-mysqld-user=mysql4 \ --without-bench \ --localstatedir=/home/mysql4/data \ --with-unix-socket-path=/tmp/mysql4.sock \ --with-tcp-port=3307 $ make # make install
MySQL4ユーザ作成 †
pw groupadd mysql5 pw useradd mysql4 -g mysql4 -d /usr/local/ -s /usr/sbin/nologin
設定ファイルのコピー †
# cp support-files/my-medium.cnf /etc/my4.cnf # cp support-files/mysql.server /usr/local/etc/rc.d/mysql4.sh # chmod 755 /usr/local/etc/rc.d/mysql4.sh
起動スクリプト修正 †
起動部分に「--defaults-file=/etc/my4.cnf」を追加
# vi /usr/local/etc/rc.d/mysql4.sh 327 $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 & ↓ 327 $bindir/mysqld_safe --defaults-file=/etc/my4.cnf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
PHP4インストール †
$ tar zxvf php-4.4.9.tar.tar $ cd php-4.4.9 $ ./configure \ --prefix=/usr/local/php4 \ --with-apxs=/usr/local/apache/bin/apxs \ --enable-mbstring \ --enable-mbstr-euc-trans \ --with-pgsql=/usr/local/pgsql7 \ --with-mysql=/usr/local/mysql4 \ --with-jpeg-dir=/usr/local \ --with-tiff-dir=/usr/local \ --with-png-dir=/usr/local \ --with-zlib=/usr \ --with-t1lib=/usr/local \ --with-curl=/usr/local \ --with-freetype-dir=/usr/local \ --enable-gd-jis-conv \ --with-gd --with-dom $ make # make install
php.iniのコピー †
# cp php.ini-dist /usr/local/php4/lib/php.ini
httpd.confに追加 †
AddType application/x-httpd-php .php
リバースプロキシの設定(Apache2側) †
「内部から外部へのアクセスを中継する」動作と反対であることが「リバース」の由来であると言われている。
この設定で、「php4.matsui.net」にアクセスすると、「http://127.0.0.1:8080」にアクセスできる。
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so <IfModule mod_proxy.c> ProxyRequests Off <Proxy *> Order deny,allow #Deny from all #Allow from .your_domain.com </Proxy> </IfModule> <VirtualHost *:80> ServerName php4.matsui.net ProxyPass / http://php4.matsui.net:8080/ ProxyPassReverse / http://php4.matsui.net:8080/ </VirtualHost> <VirtualHost *:80> ServerName php44.matsui.net ProxyPass / http://php44.matsui.net:8080/ ProxyPassReverse / http://php44.matsui.net:8080/ </VirtualHost>
Apache再起動 †
# /usr/local/apache2/bin/apachectl restart