lnmp
2013-04-22linux操作系统,如何编译安装LNMP(Nginx、MySQL、PHP)搭建稳定的web服务器呢?php需要支持mysql,所以需要在安装php之前安装mysql,nginx不依赖其他两个程序,先后编译无影响。
1、安装编译环境:
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 bison lynx
2、下载所需安装包
#nginx 1.2
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.13.tar.gz
http://nginx.org/download/nginx-1.2.8.tar.gz
http://mirrors.sohu.com/lfs/lfs-packages/6.8/zlib-1.2.5.tar.bz2
http://www.openssl.org/source/openssl-1.0.0e.tar.gz
#mysql 5.5
http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.30.tar.gz
#ftp://61.135.158.199/pub/mysql-5.5.30.tar.gz
#http://download.softagency.net/mysql/Downloads/MySQL-5.5/mysql-5.5.30.tar.gz
#php 5.3
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
http://prdownloads.sourceforge.net/libpng/libpng-1.2.46.tar.xz?download
http://www.ijg.org/files/jpegsrc.v8c.tar.gz
http://download.savannah.gnu.org/releases/freetype/freetype-2.4.6.tar.gz
http://techtrunch.com/downloads/gd-2.0.35.tar.gz
http://xmlsoft.org/sources/libxml2-2.7.7.tar.gz
http://xmlsoft.org/sources/libxslt-1.1.26.tar.gz
http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz
http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.16-stable.tar.gz
"http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"
"http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"
"http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"
http://my.php.net/get/php-5.3.24.tar.gz/from/us.php.net/mirror
http://cn.php.net/get/php-5.3.24.tar.bz2/from/this/mirror
http://cn.php.net/get/php-5.4.14.tar.bz2/from/this/mirror
#after install php
http://pecl.php.net/get/memcache-3.0.6.tgz
#ftp://mirror.aarnet.edu.au/pub/imagemagick/ImageMagick-6.6.6-5.tar.gz
http://acelnmp.googlecode.com/files/ImageMagick-6.7.2-10.tar.gz
http://pecl.php.net/get/imagick-3.0.1.tgz
http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
#http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
http://acelnmp.googlecode.com/files/eaccelerator-0.9.6.1.tar.bz2
#32 bit ZendGuard
http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
#64 bit ZendGuard
http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
3、编译nginx
nginx需要提前安装pcre,及zlib,openssl源码头文件
#!/bin/bash
export LNMP=/opt/LNMP
cd $LNMP
tar zxf untar/pcre-8.13.tar.gz
pushd pcre-8.13
./configure;make;make install
popd
tar zxf untar/nginx-1.2.8.tar.gz
tar jxf untar/zlib-1.2.5.tar.bz2
tar zxf untar/openssl-1.0.1c.tar.gz
pushd nginx-1.2.8
./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-zlib=../zlib-1.2.5 \
--with-openssl=../openssl-1.0.1c \
--with-pcre=../pcre-8.13
make;make install
popd
groupadd www
useradd -g www -d /dev/null -s /sbin/nologin www
cp $LNMP/conf/init.nginx /etc/init.d/nginx
cp $LNMP/conf/*.conf /usr/local/nginx/conf
mkdir -p /data/logs/nginx
cp conf/iftop /usr/local/sbin/
cp conf/netstat2 /bin
cp conf/nmon /bin
chmod 755 /etc/init.d/nginx
/etc/init.d/nginx start
chkconfig nginx on
netstat -ntl |grep 80
4、安装mysql-5.5.30.tar.gz
#!/bin/bash
export LNMP=/opt/LNMP
cd $LNMP
tar zxf untar/cmake-2.8.8.tar.gz
pushd cmake-2.8.8
./bootstrap && gmake && gmake install
popd
groupadd mysql
useradd -g mysql mysql
mkdir -p /usr/local/mysql
mkdir -p /var/lib/mysql
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /var/lib/mysql
tar zxf untar/mysql-5.5.30.tar.gz
#basename mysql-5.5.30.tar.gz
pushd mysql-5.5.30
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/var/lib/mysql \
-DMYSQL_USER=mysql
make;make install;
popd
#创建my.cnf配置文件
#cp untar/conf/my.cnf /usr/local/mysql/
#cp /opt/LNMP/mysql-5.5.30/support-files/my-large.cnf /usr/local/mysql/my.cnf
cat > /usr/local/mysql/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
old_passwords=1
innodb_file_per_table
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
EOF
cd /usr/local/mysql
./scripts/mysql_install_db --datadir=/var/lib/mysql --user=mysql
cp /opt/LNMP/mysql-5.5.30/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig mysqld on
/etc/init.d/mysqld start
./bin/mysqladmin -u root password 'password1'
#./bin/mysqld_safe &
netstat -ntlp |grep 3306
cat >> ~/.bash_profile << EOF
export PATH=$PATH:/usr/local/mysql/bin
EOF
source ~/.bash_profile
cat >> /etc/ld.so.conf.d/mysql.conf << EOF
/usr/local/mysql/lib
EOF
cat >> ~/my.sh << EOF
mysql -uroot -ppassword1 -Dmysql
EOF
chmod 755 ~/my.sh
#删除不必要的用户
mysql -uroot -ppassword1 -e”drop user ”@’localhost’”
mysql -uroot -ppassword1 -e”drop user ”@’`hostname`’”
mysql -uroot -ppassword1 -e”drop user ‘root’@'`hostname`’”
mysql -uroot -ppassword1 -e”drop user root@’::1′”
#创建数据库
mysql -uroot -ppassword1 -e”create database postfix”
#创建用户
mysql -uroot -ppassword1 -e”CREATE USER ‘postfix’@'localhost’ IDENTIFIED BY ’123456′;”
mysql -uroot -ppassword1 -e”GRANT ALL ON postfix.* TO ‘postfix’@'localhost’;”
#让创建的用户生效
mysql -uroot -ppassword1 -e”commit”
mysql -uroot -ppassword1 -e”flush privileges;”
5、安装php依赖包
#!/bin/bash
####################php##################3
export LNMP=/opt/LNMP
cd $LNMP
pushd zlib-1.2.5
./configure && make && make instal/
popd
tar xf untar/libpng-1.2.46.tar
pushd libpng-1.2.46
./configure;make;make install
popd
tar zxf untar/jpegsrc.v8c.tar.gz
pushd jpeg-8c
./configure -enable-shared -enable-static
make && make install
popd
tar zxf untar/freetype-2.4.6.tar.gz
pushd freetype-2.4.6
./configure;make;make install
popd
tar zxf untar/gd-2.0.35.tar.gz
pushd gd-2.0.35
./configure;make;make install
popd
tar -zxf untar/libxml2-2.7.7.tar.gz
pushd libxml2-2.7.7
./configure;make;make install
popd
#if get this err
#./.libs/libxml2.so: undefined reference to `gzopen64'
#ldd ./.libs/libxml2.so
#cd zlib-1.2.5
#make uninstall
#make install
tar zxf untar/libiconv-1.14.tar.gz
pushd libiconv-1.14
./configure --prefix=/usr/local
"3pre-php.sh" 92L, 2481C
tar xzf untar/libxslt-1.1.26.tar.gz && cd libxslt-1.1.26
./configure && make && make install && cd ../
tar zxf untar/autoconf-2.13.tar.gz && cd autoconf-2.13
./configure --prefix=/usr/local/autoconf-2.13;make;make install && cd ..
tar zxf untar/libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/ && ./configure && make && make install
ln -s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install && make && make install
cd /opt/LNMP
tar zxf untar/mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/ && ./configure && make && make install && cd ../
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 zxf untar/mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure ; make ; make install ; cd ../
#tar zxf untar/libevent-1.4.14b-stable.tar.gz
#cd libevent-1.4.14b-stable && ./configure && make && make install && cd ..
#/sbin/ldconfig
tar zxf untar/libevent-2.0.16-stable.tar.gz
pushd libevent-2.0.16-stable
./configure && make && make install
popd
/sbin/ldconfig
chown -R root:root *
6、安装php
#!/bin/bash
LNMP=/opt/LNMP
cd $LNMP
# php 5.3.24
export PHP_AUTOCONF=/usr/local/autoconf-2.13/bin/autoconf
export PHP_AUTOHEADER=/usr/local/autoconf-2.13/bin/autoheader
tar jxf untar/php-5.3.24.tar.bz2
#tar jxf untar/openssl-1.0.1c.tar.gz
pushd php-5.3.24
./buildconf --force
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-magic-quotes \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext
#--with-imap=/usr/local/imap-2007f \
#--with-imap-ssl=/usr/local/openssl
make ZEND_EXTRA_LIBS='-liconv'
make test
make install
popd
mkdir -p /usr/local/php/etc
cp untar/conf/php.ini /usr/local/php/etc
cp untar/conf/php-fpm.conf /usr/local/php/etc
cp untar/conf/init.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig php-fpm on
cd ../
ln -sf /usr/local/php/bin/php /usr/bin/php
ln -sf /usr/local/php/bin/phpize /usr/bin/phpize
ln -sf /usr/local/php/sbin/php-fpm /usr/bin/php-fpm
#start php-fpm 9002
#/etc/init.d/php-fpm restart
#netstat -ntl |grep 9002
#########################end##################
7、安装php优化包
#!/bin/bash
##################php#######addtional##################
LNMP=/data/LNMP
#extension eaccelerator
cd /opt/LNMP
tar jxf untar/eaccelerator-0.9.6.1.tar.bz2
pushd 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
popd
mkdir -p /usr/local/php/eaccelerator_cache && chmod 777 /usr/local/php/eaccelerator_cache
#/usr/local/php/bin/php -v
#extension memcache
cd /opt/LNMP
tar zxf untar/memcache-3.0.6.tgz && cd memcache-3.0.6/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install && cd ../
tar zxf untar/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 zxf untar/ImageMagick-6.7.2-10.tar.gz
pushd ImageMagick-6.7.2-10
./configure
make && make install
popd
tar zxf untar/imagick-3.0.1.tgz
pushd imagick-3.0.1
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make;make install
popd
cd /opt/LNMP
x86=`uname -m`
printf "$x86 \n"
zend_32()
{
tar zxf untar/ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
rm -rf /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ZendGuardLoader.so
cp /opt/LNMP/ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/ZendGuardLoader.so \
/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626
}
zend_64()
{
tar zxf untar/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
rm -rf /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ZendGuardLoader.so
cp /opt/LNMP/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so \
/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626
}
case "$x86" in
i686|i386|i586)
zend_32 && exit 0
;;
x86_64)
zend_64 || exit 0
;;
*)
exit 2
esac
#######php-fpm########3
/etc/init.d/php-fpm restart
#netstat -ntl |grep 9002
pushd /usr/local/nginx/html
cat > p.php <
EOF
popd
#########################end##################