下面分享一个源码安装LNMP的脚本:
适用于CentOS或者是Redhat 系统,32位或64位通用
本人在CentOS 5.7 x64 和 6.0 x64上测试通过,在redhat 5.5 x86上也测试通过,并且线上安装的时候,也是用的这个脚本里面的软件基本上都是最新版本。
PHP 5.3.8 nginx 1.0.10 mysql用的是percona server 5.5.16
脚本如下,附件可下载:
#!/bin/bash
#written by xiaosu
#install mysql
mkdir -p /data/mysql
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
chown -R mysql:mysql /data/mysql
yum -y install gcc-c++ ncurses-devel openssl-devel bison gd-devel libxml2-devel bzip2-devel curl-devel zlib-devel pcre-devel autoconf
tar zxvf cmake-2.8.5.tar.gz
cd cmake-2.8.5
./configure
if [ $? != 0 ]
then exit
fi
make &&make install
cd ..
tar zxvf Percona-Server-5.5.16-rel22.0.tar.gz
CC=gcc \
#CHOST="x86_64-pc-linux-gnu" \
CFLAGS=" -O3 \
-fomit-frame-pointer \
-pipe \
-march=nocona \
-mfpmath=sse \
#-m128bit-long-double \
-mmmx \
-msse \
-msse2 \
-maccumulate-outgoing-args \
#-m64 \
-ftree-loop-linear \
-fprefetch-loop-arrays \
-freg-struct-return \
-fgcse-sm \
-fgcse-las \
-frename-registers \
-fforce-addr \
-fivopts \
-ftree-vectorize \
-ftracer \
-frename-registers \
-minline-all-stringops \
-fbranch-target-load-optimize2 \
-DBIG_JOINS=1 \
-DHAVE_DLOPEN=1 -O3" \
CXX=g++ \
CXXFLAGS="-DBIG_JOINS=1 -DHAVE_DLOPEN=1 -felide-constructors -fno-rtti -O3"
cd Percona-Server-5.5.16-rel22.0
cmake . \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DSYSCONFDIR:PATH=/etc \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql \
-DENABLED_PROFILING:BOOL=ON \
-DENABLE_DEBUG_SYNC:BOOL=OFF \
-DMYSQL_DATADIR:PATH=/data/mysql \
-DMYSQL_MAINTAINER_MODE:BOOL=OFF \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk,gb2312 \
-DWITH_BIG_TABLES:BOOL=ON \
-DWITH_FAST_MUTEXES:BOOL=ON \
-DENABLE-PROFILING:BOOL=ON \
-DWITH_SSL:STRING=bundled \
-DWITH_UNIT_TESTS:BOOL=OFF \
-DWITH_ZLIB:STRING=bundled \
-DWITH_PARTITION_STORAGE_ENGINE:BOOL=ON \
-DMYSQL_USER=mysql \
-DWITH_PLUGINS=heap,csv,partition,innodb_plugin,myisam \
-DEFAULT_COLLATION=utf8_general_ci \
-DEFAULT_CHARSET=utf8 \
-DENABLED_ASSEMBLER:BOOL=ON \
if [ $? != 0 ]
then exit
fi
make && make install
yes|cp support-files/my-huge.cnf /etc/my.cnf
sed -i '/\[mysqld\]/a\datadir\t\t= \/data\/mysql' /etc/my.cnf
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
sed -i 's/PATH=\$PATH:\$HOME\/bin/PATH=\$PATH:\$HOME\/bin:\/usr\/local\/mysql\/bin/' /root/.bash_profile
source /root/.bash_profile
echo "/usr/local/mysql/lib" >> /etc/ld.so.conf.d/mysql.conf
/sbin/ldconfig
cd -
cd ..
#install php with php-fpm
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 && cd ../../
tar zxvf mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9/ && ./configure
make && make install && cd ../
tar zxvf mcrypt-2.6.8.tar.gz &&cd mcrypt-2.6.8/
LD_LIBRARY_PATH=/usr/local/lib ./configure
make && make install && cd ../
groupadd www
useradd -g www -s /sbin/nologin www
tar xjvf php-5.3.8.tar.bz2
cd php-5.3.8
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-mhash --enable-sockets --with-libxml-dir --enable-xml --disable-rpath --enable-safe-mode --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 --without-pear --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-calendar --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --disable-ipv6 --disable-debug --with-pdo-mysql=mysqlnd --enable-bcmath --enable-soap
make
make install
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cp php.ini-production /usr/local/php/etc/php.ini
cd ..
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
sed -i 's/^;pid = run\/php-fpm.pid/pid = run\/php-fpm.pid/' php-fpm.conf
sed -i 's/^;pm.start_servers = 20/pm.start_servers = 20/' php-fpm.conf
sed -i 's/^;pm.min_spare_servers = 5/pm.min_spare_servers = 5/' php-fpm.conf
sed -i 's/^;pm.max_spare_servers = 35/pm.max_spare_servers = 35/' php-fpm.conf
sed -i 's/^;pm.max_requests = 500/pm.max_requests = 500/' php-fpm.conf
service php-fpm start
#install nginx
cd -
tar xzvf nginx-1.0.10.tar.gz
cd nginx-1.0.10
./configure --user=www --group=www --prefix=/usr/local/nginx
make
make install
cd ..
rm -rf nginx-1.0.10
第一步先装cmake,然后再装percona,再装php的一些依赖库,再装php,最后装nginx,使用的时候,将相应的源码包放到跟脚本同级的目录即可。