之前的Web服务器都是通过yum搭建的,想要添加新模块或者更新某些软件都很不方便(牵一发而动全身啊!)。所以,现在准备将环境改为源码编译安装,这样便于调整,性能上也会比yum方式好很多。以下是我的安装步骤,我的系统是CentOS 6.3 64位。
注意:本文所以配置都是基于第二步所下载的软件版本,安装其他版本不保证会成功
推荐阅读:
CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6)
Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建)
一:安装依赖包
yum install cmake make gcc gcc-c++ 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-devel libidn libidn-devel openssl expat expat-devel \
openssl-devel nss_ldap openldap openldap-devel openldap-clients openldap-servers unixODBC-devel \
libxslt-devel libevent-devel libtool-ltdl bison libtool pcre-devel zip unzip gmp-devel gd gd-devel
二:下载LNMP所需软件
wget
wget
wget
wget
wget
wget
wget %200.9.6.1/eaccelerator-0.9.6.1.tar.bz2
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget https://github.com/nicolasff/phpRedis/archive/master.zip
三、安装mysql
tar zxf mysql-5.5.19.tar.gz
cd mysql-5.5.19
groupadd mysql
useradd -g mysql -s /sbin/nologin -M mysql
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
make && make install
chown -R mysql.mysql /usr/local/mysql
cd ..
因为有专门的mysql服务器,所以mysql安装到此结束。如果想要在本地运行mysql的话还要做其他配置。比如my.cnf配置文件,mysql启动脚本等等。
四:安装PHP
安装PHP(FastCGI)
### 安装PHP支持库 ###
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local
make
make install
cd ..
tar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure && make && make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make && make install
cd ../../
tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
tar zxf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
./configure
make
make install
cd ../
tar zxf re2c-0.13.5.tar.gz
cd re2c-0.13.5
./configure
make && make install
cd ..
在安装PHP主程序前,还需要做一些调整,不然会各种报错。
echo "/usr/local/lib" > /etc/ld.so.conf.d/local.conf
echo "/usr/lib64" >> /etc/ld.so.conf.d/local.conf
ln -sv /usr/lib64/libldap* /usr/lib/
ln -sv /usr/include/sqlext.h /usr/local/include/sqlext.h
ln -sv /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config
ln -sv /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
ln -sv /lib64/libexpat.* /lib/
ln -sv /usr/lib64/libexpat.* /usr/lib/
ldconfig
现在安装PHP
tar jxf php-5.3.18.tar.bz2
cd php-5.3.18
groupadd nginx
useradd -M -s /sbin/nologin -g nginx nginx
./configure \
--prefix=/usr/local/php --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d \
--with-pic --with-bz2 --with-gettext --with-gmp --with-iconv --with-openssl \
--with-zlib --with-layout=GNU --with-kerberos --with-mhash --with-pcre-regex --enable-exif \
--enable-magic-quotes --enable-sockets --enable-ucd-snmp-hack --enable-shmop --enable-calendar \
--enable-mbstring \
--enable-xml --enable-fpm --enable-gd-native-ttf --enable-exif --enable-soap --with-gd --with-curl \
--with-mcrypt \
--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql \
--with-unixODBC \
--enable-wddx --with-libexpat-dir --with-xmlrpc --with-xsl --with-ldap --enable-bcmath \
--enable-dom --without-gdbm --disable-debug --disable-rpath --disable-fileinfo --without-pspell \
--disable-posix --disable-sysvmsg --disable-sysvshm --disable-sysvsem
make ZEND_EXTRA_LIBS='-liconv'
make install
拷贝配置文件及启动脚本
cp php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cd ../