LNMP(Linux + Nginx + MySQL + PHP)因高併發效能優勢廣受青睞。本文記錄完整編譯安裝流程。

前置:關閉 RPM 預裝 Apache/MySQL
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel \
freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel \
glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel \
e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel \
openldap openldap-devel nss_ldap openldap-clients openldap-servers
wget https://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gz
wget https://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
wget https://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.14-fpm-0.5.14.diff.gz
wget https://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gz
wget https://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
wget https://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget https://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget https://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget https://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget https://blog.s135.com/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
wget https://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
wget https://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget https://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget https://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.3.0.tgz
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr/local
make && make install
cd ..
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure && make && make install
cd libltdl
./configure --enable-ltdl-install && make && make install
cd ../..
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure && make && make install
cd ..
# 建立符號連結至 /usr/lib
ln -s /usr/local/lib/libmcrypt.* /usr/lib/
ln -s /usr/local/lib/libmhash.* /usr/lib/
ln -s /usr/local/bin/libmcrypt-config /usr/bin/
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure && make && make install
cd ..
groupadd mysql
useradd -g mysql mysql
tar zxvf mysql-5.5.3-m3.tar.gz
cd mysql-5.5.3-m3
./configure --prefix=/usr/local/mysql --without-debug --enable-thread-safe-client \
--with-pthread --enable-assembler --enable-profiling --with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static --with-extra-charsets=all --with-plugins=all \
--with-mysqld-user=mysql --without-embedded-server --with-server-suffix=-community \
--with-unix-socket-path=/tmp/mysql.sock
make && make install
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
# 編輯 /etc/my.cnf 設定 utf8
# [client] default-character-set=utf8
# [mysqld] character-set-server=utf8; collation-server=utf8_general_ci
setfacl -m u:mysql:rwx -R /usr/local/mysql
setfacl -m d:u:mysql:rwx -R /usr/local/mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql
/usr/local/mysql/bin/mysqld_safe --user=mysql &
/usr/local/mysql/bin/mysqladmin -uroot password 123
/usr/local/mysql/bin/mysql -uroot -p123
tar zxvf php-5.2.14.tar.gz
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
cd php-5.2.14
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir \
--with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path \
--enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization \
--with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm \
--enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf \
--with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl \
--with-xmlrpc --enable-zip --enable-soap
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist /usr/local/php/etc/php.ini
cd ..
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ..
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ..
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make && make install
cd ..
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2
./configure && make && make install
cd ..
tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ..
tar zxvf nginx-0.8.46.tar.gz
cd nginx-0.8.46
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module
make && make install
# 配置 nginx.conf 支援 PHP-FPM
# 啟動
/usr/local/nginx/sbin/nginx
/usr/local/php/sbin/php-fpm start