CentOS5安装LNMP

以myhost123 1GB的VPS,系统为CentOS5为例,我们讲述一下如何手工编译LNMP,也就是大家常用的网站环境。
完成安装后,可以访问http://IP/info.php来看是否安装正确
这是一个基本完成的脚本(最后一部分需要手工修改),我们用的都是基本配置,大家可以根据自己的需要修改脚本并将其设置为适合你自己的脚本。

编译前准备

#! /bin/bash

INSTALL_BASEDIR=’/opt/lnmp_install’
mkdir -p $INSTALL_BASEDIR
cd $INSTALL_BASEDIR

yum -y update
yum -y install gcc gcc-c++ autoconf automake make libtool libevent libevent-devel gmp gmp-devel
yum -y install gd gd-devel freetype freetype-devel fontconfig fontconfig-devel libjpeg libjpeg-devel zlib zlib-devel pcre pcre-devel
yum -y install ncurses ncurses-devel libmcrypt mhash curl curl-devel db4 db4-devel libxml2 libxml2-devel
yum -y install libxslt libxslt-devel ntsysv ntp
yum -y install net-snmp*

一、安装MYSQL

### start install mysql

wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.59.tar.gz/from/ht…
tar zxf mysql-5.1.59.tar.gz
cd $INSTALL_BASEDIR/mysql-5.1.59
./configure –prefix=/usr/local/mysql \
–with-unix-socket-path=/var/lib/mysql/mysql.sock \
–localstatedir=/var/lib/mysql/data \
–with-charset=utf8 –with-collation=utf8_general_ci \
–with-extra-charsets=all –enable-assembler –with-pthread
make -j4 && make install
groupadd mysql
useradd mysql -s /sbin/nologin -g mysql -M
yes y | cp support-files/my-medium.cnf /etc/my.cnf
sed -i ‘s/^skip-locking/skip-external-locking/g’ /etc/my.cnf
chown mysql.root -R /usr/local/mysql
/usr/local/mysql/bin/mysql_install_db –user=mysql
chown mysql.mysql -R /var/lib/mysql/
ln -s /usr/local/mysql/bin/* /usr/local/bin
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
/etc/init.d/mysqld start
netstat -lntp|grep 3306
echo “if you see 3306 port,then mysql install right”
sleep 10

##setup ldconfig
cat <<END_ENTRIES >> /etc/ld.so.conf
/usr/local/lib
/usr/lib/mysql
END_ENTRIES
ldconfig

二、安装php之前所需安装的几个软件包

###start install php-preview
cd $INSTALL_BASEDIR
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar zxf libmcrypt-2.5.7.tar.gz
cd $INSTALL_BASEDIR/libmcrypt-2.5.7
./configure && make && make check
make install

cd $INSTALL_BASEDIR
wget http://ncu.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9….
tar jxf mhash-0.9.9.9.tar.bz2
cd  $INSTALL_BASEDIR/mhash-0.9.9.9
./configure && make && make check
make install

cd $INSTALL_BASEDIR
wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.t…
tar zxf mcrypt-2.6.8.tar.gz
cd $INSTALL_BASEDIR/mcrypt-2.6.8
LD_LIBRARY_PATH=/usr/local/lib ./configure
make &&  make check
make install

三、安装PHP
###start install php
cd $INSTALL_BASEDIR
wget http://www.php.net/get/php-5.3.15.tar.bz2/from/this/mirror
tar jxf php-5.3.15.tar.bz2
cd $INSTALL_BASEDIR/php-5.3.15
./configure –prefix=/usr/local/php \
–with-mysql=/usr/local/mysql \
–with-mysql-sock=/var/lib/mysql/mysql.sock \
–with-gd –enable-gd-native-ttf \
–enable-gd-jis-conv –with-freetype-dir \
–with-jpeg-dir –with-png-dir –with-zlib –with-zlib-dir \
–with-curl –with-curlwrappers –with-pic –enable-bcmath \
–with-xsl -with-openssl \
–with-pdo-mysql –with-gettext \
–with-gmp –with-db4 –with-iconv \
–with-mcrypt \
–with-mhash \
–with-snmp \
–enable-xml –enable-mbstring \
–enable-sockets \
–enable-inline-optimization \
–enable-calendar \
–enable-dba \
–enable-exif \
–enable-ftp \
–enable-soap –enable-zip –enable-sysvsem \
–enable-fpm
make -j4 && make install
cp php.ini-production /usr/local/php/lib/php.ini
ln -s /usr/local/php/bin/* /usr/local/bin/
cp $INSTALL_BASEDIR/php-5.3.15/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 700 /etc/init.d/php-fpm

四、安装php加速器

## install eaccelerator
cd $INSTALL_BASEDIR
wget http://sourceforge.net/projects/eaccelerator/files/eaccelerator/eAcceler…
tar jxf eaccelerator-0.9.6.1.tar.bz2
cd $INSTALL_BASEDIR/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
cat <<END_ENTRIES >> /usr/local/php/lib/php.ini
[eaccelerator]
extension_dir=”/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/”
extension=”eaccelerator.so”
eaccelerator.shm_size=”32″
eaccelerator.cache_dir=”/tmp/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=”"
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”0″
eaccelerator.shm_prune_period=”0″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
END_ENTRIES
mkdir /tmp/eaccelerator
chmod 777 /tmp/eaccelerator
php -v
echo “install php ok”
sleep 10

五、安装NGINX
### install nginx
cd $INSTALL_BASEDIR
wget http://nginx.org/download/nginx-1.2.2.tar.gz
tar zxf nginx-1.2.2.tar.gz
cd $INSTALL_BASEDIR/nginx-1.2.2
./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module
make && make install

###config php and nginx
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
sed -i ‘s#;pid = run/php-fpm.pid#pid = run/php-fpm.pid#g’ /usr/local/php/etc/php-fpm.conf
sed -i ‘s#;error_log = log/php-fpm.log#error_log = log/php-fpm.log#g’ /usr/local/php/etc/php-fpm.conf
sed -i ‘s#;log_level = notice#log_level = notice#g’ /usr/local/php/etc/php-fpm.conf
sed -i ‘s#pm.start_servers = 2#pm.start_servers = 10#g’ /usr/local/php/etc/php-fpm.conf
sed -i ‘s#pm.max_children = 5#pm.max_children = 25#g’ /usr/local/php/etc/php-fpm.conf
sed -i ‘s#pm.max_spare_servers = 3#pm.max_spare_servers = 15#g’ /usr/local/php/etc/php-fpm.conf
sed -i ‘s#pm.min_spare_servers = 1#pm.min_spare_servers = 5#g’ /usr/local/php/etc/php-fpm.conf

cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf_bak
echo ‘fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;’ >> /usr/local/nginx/conf/fastcgi_params
touch /usr/local/nginx/html/info.php
cat <<END_ENTRIES >> /usr/local/nginx/html/info.php
<?php
phpinfo();
?>
END_ENTRIES

/etc/init.d/php-fpm start
/usr/local/nginx/sbin/nginx

chkconfig –level 345 mysqld on
chkconfig –level 345 php-fpm on
echo “/usr/local/nginx/sbin/nginx” > /etc/rc.local
echo “install ok,now you can see http://ip/info.php”

最后需要手工的部分“:
1、修改/usr/local/nginx.conf,将以下一段前面的注释符(也是是#)去掉,注意
#fastcgi_pass  unix:/tmp/php-cgi.sock;这一行不要修改即可。
#   location ~ .*\.(php|php5)?$
#    {
#fastcgi_pass  unix:/tmp/php-cgi.sock;
#      fastcgi_pass  127.0.0.1:8888;
#      fastcgi_index index.cgi;
#            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#            include        fastcgi_params;
#    }
2、设置mysql密码
mysql -e “grant all on *.* to root@’localhost’ identified by ‘你自己的密码‘”
也可以将以上手工修改的部分修改到脚本中。
如按照以上步骤安装,则网站主目录为nginx的默认路径/usr/local/nginx/html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值