一、系统环境
系统平台:centos 6.4
Nginx版本:nginx/1.0.15
Mysql 版本:mysql-5.5.28
Php版本:php-5.4.13
二、安装准备
nginx-1.0.15.tar.gz
php-5.4.13.tar.gz http://mirrors.sohu.com/php/
php-5.2.10-fpm-0.5.11.diff.gz
mysql-5.1.35.tar.gz http://mirrors.sohu.com/mysql/MySQL-5.5/
libiconv-1.13.tar.gz http://ftp.gnu.org/pub/gnu/libiconv/
libmcrypt-2.5.8.tar.gz
mcrypt-2.6.8.tar.gz
memcache-2.2.5.tgz
mhash-0.9.9.9.tar.gz
pcre-7.9.tar.gz
eaccelerator-0.9.5.3.tar.bz2
PDO_MYSQL-1.0.2.tgz
ImageMagick.tar.gz
imagick-2.2.2.tgz
三、安装php所需扩展
初始环境:
为了省事把所需要的库文件全都安装上,可以使用rpm包安装,也可以用yum命令安装,
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
#nginx所需要的库文件件
yum -y install pcre-devel zlib-devel
#PHP依赖的库文件
yum -y install gd-devel libjpeg-devel libpng-devel freetype-devel libxml2-devel curl-devel
cp -frp /usr/lib64/libldap* /usr/lib/
安装库文件
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local
make && make install
tar zxvf 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
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make && make install
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make && make install
四、安装mysql
1>、安装简介
用户名:mysql
安装目录:/usr/local/mysql-5.5
数据库目录:/data/mysql/data
源码包:mysql-5.5.28.tar.gz
2>、安装准备
添加用户
useradd -s /sbin/nologin mysql
建立所需目录
mkdir -p /data/mysql/data
chown -R mysql:mysql /data/mysql
安装编译所需文件或程序
yum install gcc gcc-c++ cmake ncurses-devel bison
下载源码包
http://sourceforge.net/projects/mysql.mirror/files/MySQL 5.5.28/
wget http://ncu.dl.sourceforge.net/project/mysql.mirror/MySQL 5.5.28/mysql-5.5.28.tar.gz
3>、编译安装
cd
tar xzvf mysql-5.5.28.tar.gz
cd mysql-5.5.28
cmake -DMYSQL_USER=mysql -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.5 -DINSTALL_DATADIR=/data/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1
参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DMYSQL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DWITH_MYISAM_STORAGE_ENGINE=1 //安装myisam存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 //安装innodb存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 //安装archive存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 //安装blackhole存储引擎
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DMYSQL_TCP_PORT=3306 //MySQL监听端口
-DMYSQL_USER=mysql //MySQL用户名
其他参数:
-DWITH-EMBEDDED_SERVER=1 //编译成embedded MySQL library (libmysqld.a)
-DSYSCONFDIR=/etc //MySQL配辑文件
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock //Unix socket 文件路径
-DWITH_READLINE=1 //快捷键功能
-DWITH_SSL=yes //SSL
-DWITH_MEMORY_STORAGE_ENGINE=1 //安装memory存储引擎
-DWITH_FEDERATED_STORAGE_ENGINE=1 //安装frderated存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 //安装数据库分区
-DINSTALL_PLUGINDIR=/usr/local/mysql/plugin //插件文件及配置路径
make && make install
chown -R mysql:mysql /usr/local/mysql5.5/
mv /root/mysql-5.5.28/support-files/my-large.cnf /etc/my.cnf
mv /root/mysql-5.5.28/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
开启启动
chkconfig --level 345 mysqld on
设置环境变量
echo "export PATH=/usr/local/mysql5.5/bin/:$PATH" >> /etc/profile
source /etc/profile
/usr/local/mysql5.5/scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql5.5 --datadir=/data/mysql/data
vim /etc/my.cnf
basedir=/usr/local/mysql5.5
datadir=/data/mysql/data
创建mysql管理员
/usr/bin/mysqladmin -u root password 'z'
连接数据库:
mysql -u root -p -P port
五、编译php
tar zxvf php-5.4.13.tar.gz
cd php-5.4.13
export LIBS="-lm -ltermcap -lresolv"
export DYLD_LIBRARY_PATH="/usr/local/mysql5.5/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
export LD_LIBRARY_PATH="/usr/local/mysql5.5/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
./configure --prefix=/usr/local/php5.4 \
--with-config-file-path=/etc \
--with-iconv-dir=/usr/local/ --with-freetype-dir \
--with-mysql=/usr/local/mysql5.5 \
--with-mysqli=/usr/local/mysql5.5/bin/mysql_config \
--with-jpeg-dir --with-png-dir --with-zlib \
--with-mhash --enable-sockets --enable-ftp \
--with-libxml-dir --enable-xml --disable-rpath \
--enable-bcmath \
--enable-shmop --enable-sysvsem \
--enable-inline-optimization --with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-mbstring --with-mcrypt --with-gd \
--enable-gd-native-ttf --with-openssl --with-mhash \
--enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl \
--enable-fpm \
--with-xmlrpc --enable-zip --enable-soap \
--without-pear
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /etc/php.ini
将php-fpm 作为服务运行
cp php-5.4.13/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cd /usr/local/php5.4/etc
mv php-fpm.conf.default php-fpm.conf
chmod 755 /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig --level 345 php-fpm on
服务方式启动php-fpm aaaaaa
六、编译Nginx
useradd www
安装pcre
tar zxvf pcre-8.32.tar.gz
cd pcre-8.32/
./configure --prefix=/usr/local/pcre
make && make install
安装nginx
tar zxvf nginx-1.0.15.tar.gz
cd nginx-1.0.15/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6
make && make install