CentOS 6.2 に Apache 2.2.22 と MySQL 5.2.22 と PHP 5.4.0 をインストール
新しくお名前.comにサーバー借りて構築したのでメモ。
新しく書きなおしたので、こっちのほうを参照のこと。
CentOS 6.2 サーバー構築手順 - 俺の成長日記
まずは必要なライブラリのインストール
# cd /usr/local/src # yum install -y \ gettext gettext-devel ncurses-devel libpng-devel libjpeg-devel \ freetype-devel libxml2-devel curl-devel gd gd-devel cmake \ openssl libevent-devel libxml2-devel libmcrypt-devel openssl-devel \ bzip2-devel t1lib-devel gmp-devel libicu-devel aspell-devel \ readline-devel libtidy-devel libxslt-devel gcc gcc-c++ wget bison\ # wget http://zlib.net/zlib-1.2.6.tar.gz # tar xfz zlib-1.2.6.tar.gz # cd zlib-1.2.6 # ./configure --shared && make all install # cd ../ # wget http://elders.princeton.edu/data/puias/unsupported/6/x86_64/libmcrypt-2.5.8-9.puias6.x86_64.rpm # wget http://elders.princeton.edu/data/puias/unsupported/6/x86_64/libmcrypt-devel-2.5.8-9.puias6.x86_64.rpm # rpm -ivh libmcrypt-2.5.8-9.puias6.x86_64.rpm # rpm -ivh libmcrypt-devel-2.5.8-9.puias6.x86_64.rpm
ユーザーを作成する
# groupadd mysql # useradd -d /home/mysql -g mysql -r -s /sbin/nologin mysql # groupadd apache # useradd -d /home/mysql -g apache -r -s /sbin/nologin apache
MySQL をインストールする
# curl -o mysql-5.5.22.tar.gz http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.5/mysql-5.5.22.tar.gz # tar xfz mysql-5.5.22.tar.gz # cd mysql-5.5.22 # cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci # make # make install # mkdir /usr/local/mysql/etc # chown -R mysql:mysql /usr/local/mysql # cd /usr/local/mysql # ./scripts/mysql_install_db --user=mysql --skip-name-resolve # cp /usr/local/src/mysql-5.5.22/support-files/my-medium.cnf /usr/local/mysql/etc/my.cnf # chown -R root . # chown -R mysql:mysql /usr/local/mysql/data # cd /usr/local/src
# vim ~/.bashrc 以下2行を一番下に追記 --------------------------------------- PATH=$PATH:/usr/local/mysql/bin export PATH --------------------------------------- # source ~/.bashrc
MySQL の root ユーザーのパスワードを変更する
# /usr/local/mysql/support-files/mysql.server start # mysql -u root root> SET PASSWORD FOR root@localhost=PASSWORD('hoge'); root> exit; # mysql -u root # これで弾かれることを確認 # /usr/local/mysql/support-files/mysql.server stop # 一応停止しておく # cd /usr/local/src
Apache のインストール
# wget http://ftp.riken.jp/net/apache//httpd/httpd-2.2.22.tar.gz # tar xfz httpd-2.2.22.tar.gz # cd httpd-2.2.22 # ./configure \ --with-libdir=lib64 --prefix=/usr/local/apache2 --with-layout=PHP --with-pear \ --with-apxs2=/usr/local/apache2/bin/apxs --enable-calendar \ --enable-bcmath --with-gmp --enable-exif --with-mcrypt \ --with-mhash --with-zlib --with-bz2 --enable-zip --enable-ftp \ --enable-mbstring --with-iconv --enable-intl --with-icu-dir=/usr \ --with-gettext --with-pspell --enable-sockets --with-openssl \ --with-curl --with-curlwrappers --with-gd --enable-gd-native-ttf \ --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr \ --with-xpm-dir=/usr --with-freetype-dir=/usr --with-t1lib=/usr \ --with-libxml-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd --enable-soap --with-xmlrpc --with-xsl \ --with-tidy=/usr --with-readline --enable-pcntl --enable-sysvshm \ --enable-sysvmsg --enable-shmop --enable-ssl=shared --enable-rewrite \ --enable-deflate --enable-headers # make # make install # chown -R apache:apache /usr/local/apache2
Apache の設定ファイル編集
# vim /usr/local/apache2/conf/httpd.conf # 実行ユーザーを変更 ------------------------------------------------- User daemon Group daemon ↓ User apache Group apache ------------------------------------------------- # index を html から php に変更 ------------------------------------------------- <IfModule dir_module> DirectoryIndex index.html </IfModule> ↓ <IfModule dir_module> DirectoryIndex index.php </IfModule> -------------------------------------------------
PHP のインストール
# wget http://www.php.net/get/php-5.4.0.tar.bz2/from/this/mirror # tar jxf php-5.4.0.tar.bz2 # cd php-5.4.0 # ./configure --with-libdir=lib64 --prefix=/usr/local/php540 --with-layout=PHP \ --with-pear --with-apxs2=/usr/local/apache2/bin/apxs --enable-calendar \ --enable-bcmath --with-gmp --enable-exif --with-mcrypt --with-mhash \ --with-zlib --with-bz2 --enable-zip --enable-ftp --enable-mbstring --with-iconv \ --enable-intl --with-icu-dir=/usr --with-gettext --with-pspell --enable-sockets \ --with-openssl --with-curl --with-curlwrappers --with-gd --enable-gd-native-ttf \ --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-xpm-dir=/usr \ --with-freetype-dir=/usr --with-t1lib=/usr --with-libxml-dir=/usr \ --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \ --enable-soap --with-xmlrpc --with-xsl --with-tidy=/usr --with-readline \ --enable-pcntl --enable-sysvshm --enable-sysvmsg --enable-shmop # make # make test # make install
※2012/05/05追記 CLI 版も必要なので追加 --enable-cli
あと、php 5.4.2 も出ていたので、s/php5.4.0/php5.4.2/g s/540/542/g
Apache にモジュールを読み込ませる
# vim /usr/local/apache2/conf/httpd.conf 下記を追記 ---------------------------------------- LoadModule php5_module modules/libphp5.so AddType application/x-httpd-php .php ----------------------------------------
80番ポートの解放
# vim /etc/sysconfig/iptables # 下記を追記 ------------------------------- -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT ------------------------------- # /etc/rc.d/init.d/iptables restart