VPS安装  linux+nginx+php+mysql 打造自己的vps

lrenwang , 2010/04/12 15:29 , Linux , 评论(0) , 阅读(23405) , Via 本站原创 | |

最新更新 2011-07-28  http://blog.lrenwang.com/lnmp_v2/

主要参照了 http://blog.s135.com/nginx_php_v6/
在此,对张宴表示由衷的感谢 !!

vps系统CentOS5.2
添加一个常用帐号
VPS所在地 量子数据 http://www.qdata.com.cn
useradd lrenwang
passwd lrenwang



一 安装准备
关闭防火墙
service iptables stop

关闭 SELINUX, cp 命令直接覆盖,不需要提示
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
setenforce 0
sed -i "s/alias cp='cp -i'/#alias cp='cp -i'/g" ~/.bashrc
su -

我下载的软件都放到 /home/lrenwang/soft
mkdir /home/lrenwang/soft/ver1 -p
cd /home/lrenwang/soft

配置yum
wget http://blog.lrenwang.com/down/CentOS-Base.repo
cp   CentOS-Base.repo  /etc/yum.repos.d/

卸载httpd(rmp -q httpd 查看是否安装)
yum remove -y httpd

更新所需的安装包
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 vsftpd patch zip


更新时区
cp  /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

下载lnmp所需的软件
wget http://sysoev.ru/nginx/nginx-0.8.34.tar.gz
wget http://www.php.net/get/php-5.2.13.tar.gz/from/this/mirror
wget http://php-fpm.org/downloads/php-5.2.13-fpm-0.5.13.diff.gz
ftp://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.1/mysql-5.1.45.tar.gz
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.tar.gz
wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0
wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0
wget http://pecl.php.net/get/memcache-2.2.5.tgz
wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.01.tar.gz
wget http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://pecl.php.net/get/imagick-2.3.0.tgz

下载配置文件
cd ver1
wget http://blog.lrenwang.com/down/ver1/my.cnf
wget http://blog.lrenwang.com/down/ver1/php.ini
wget http://blog.lrenwang.com/down/ver1/php-fpm.conf
wget http://blog.lrenwang.com/down/ver1/nginx.conf
wget http://blog.lrenwang.com/down/ver1/fcgi.conf
cd ../



二安装php5.2.13 mysql-5.1.38
1、编译安装PHP 5.2.13所需的支持库:
tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure --prefix=/usr/local
make
make install
cd ../
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 ../
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
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../

2、编译安装mysql-5.1.45.tar.gz

/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
tar zxvf mysql-5.1.45.tar.gz
cd mysql-5.1.45/
./configure --prefix=/usr/local/webserver/mysql/ --enable-assembler --with-charset=utf8 --with-extra-charsets=all --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase
make && make install
chmod +w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
ln -s /usr/local/webserver/mysql/lib/mysql/libmysqlclient.so.16 /usr/lib/
cd ../
mkdir /var/mysql/
cp ver1/my.cnf /var/mysql/my.cnf
chown mysql:mysql /var/mysql/

生成数据库 启动服务进程 修改密码
/usr/local/webserver/mysql/bin/mysql_install_db --basedir=/usr/local/webserver/mysql --datadir=/var/mysql/data --user=mysql
/usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/var/mysql/my.cnf  &
/usr/local/webserver/mysql/bin/mysqladmin -uroot password "123456" -p

进入mysql 查看状态(可以不做)
/usr/local/webserver/mysql/bin/mysql -uroot -p123456
status
exit

3、编译安装PHP(FastCGI模式)
tar zxvf php-5.2.13.tar.gz
gzip -cd php-5.2.13-fpm-0.5.13.diff.gz | patch -d php-5.2.13 -p1
cd php-5.2.13/
./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
make ZEND_EXTRA_LIBS='-liconv'
make install
cd ../
cp ver1/php.ini /usr/local/webserver/php/etc/php.ini

4、编译安装PHP5扩展模块
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

tar jxvf eaccelerator-0.9.6.tar.bz2
cd eaccelerator-0.9.6/
/usr/local/webserver/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-pdo-mysql=/usr/local/webserver/mysql
make
make install
cd ../

tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../

tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

5、如果不需要,在php.ini中 注释下面信息
extension = "memcache.so"
  extension = "pdo_mysql.so"
  extension = "imagick.so"
  
  把output_buffering = On
  改output_buffering = Off

6、eAccelerator加速PHP:
如果不需要,在php.ini文件的最末尾,删除以下配置信息:
[eaccelerator]
zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="32"
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

7、创建www用户和组,以及供blog.lrenwang.com使用的目录:
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /var/www/blog
chmod +w /var/www/blog
chown -R www:www /var/www/blog

8、创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
cp ver1/php-fpm.conf /usr/local/webserver/php/etc/php-fpm.conf

9、启动php-cgi进程,监听127.0.0.1的9000端口,进程数为64(根据内存情况来定),用户为
www:
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm start



三、安装Nginx 0.8.34
1、安装Nginx所需的pcre库:
tar zxvf pcre-8.01.tar.gz
cd pcre-8.01/
./configure
make && make install
cd ../

2、安装Nginx
tar zxvf nginx-0.8.34.tar.gz
cd nginx-0.8.34/
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../

3、创建Nginx日志目录
mkdir -p /data1/logs
chmod +w /data1/logs
chown -R www:www /data1/logs

4、创建Nginx配置文件
cp ver1/nginx.conf /usr/local/webserver/nginx/conf/nginx.conf
cp ver1/fcgi.conf /usr/local/webserver/nginx/conf/fcgi.conf

5、启动Nginx
ulimit -SHn 65535
/usr/local/webserver/nginx/sbin/nginx

四、配置开机自动启动Nginx + PHP +Mysql
echo "ulimit -SHn 65535" >> /etc/rc.d/rc.local
echo "/usr/local/webserver/php/sbin/php-fpm start" >> /etc/rc.d/rc.local
echo "/usr/local/webserver/nginx/sbin/nginx" >> /etc/rc.d/rc.local
echo "/usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/var/mysql/my.cnf  &" >> /etc/rc.d/rc.local




chkconfig --level 2345 vsftpd on
chkconfig --level 2345 iptables off

常用命令
数据库
    停止数据库
    
/usr/local/webserver/mysql/bin/mysqladmin -uroot -p123456 shutdown

    启动数据库
    
/usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/var/mysql/my.cnf  &

php
    
/usr/local/webserver/php/sbin/php-fpm start|stop|reload

nginx
    开始
    
/usr/local/webserver/nginx/sbin/nginx

    停止
  
/usr/local/webserver/nginx/sbin/nginx -s stop

  平滑加载
  
/usr/local/webserver/nginx/sbin/nginx -s reload



第一版写的比较仓促,如果发现什么问题,可以发我邮件 lrenwang@126.com

我会不断更新,感谢关注~!






Tags: , , ,
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]