CentOS5.5平台安装lnmp

这里是以php-fpm这个php补丁的形式运行php的.
第一步,准备
#yum -y install wget make
#yum -y install patch
//php启用fpm支持,需要打fpm这个补丁才可以的,所以需要先把patch命令安装上。
加快安装速度,这里我们使用sohu的镜像yum源的。
cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.bak
wget -O CentOS-Base.repo http://mirrors.sohu.com/help/CentOS-Base-sohu.repo
vi CentOS-Base.repo
将所有mirrorlist行注释掉,在行首添加#符号即可.有关更多镜像站点,请参考:http://blog.haohtml.com/index.php/archives/5669
 
 
=========================================================
 
 
第二步 利用CentOS Linux系统自带的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 libmcrypt libmcrypt-devel mhash mhash-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
 
 
===================================
 
 
第三步 下载所需软件到/usr/src
cd /usr/src
wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.14-fpm-0.5.14.diff.gz
wget http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gz
//wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
//wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
//wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
//wget http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
wget http://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.3.0.tgz
 
 
=================================
 
 
第四步 安装mysql(安装目录为/usr/local/mysql)
创建mysql服务进程的用户名和组
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql

tar zxvf mysql-5.5.3-m3.tar.gz

cd mysql-5.5.3-m3/
./configure –prefix=/usr/local/mysql/ –enable-assembler –with-extra-charsets=complex –enable-thread-safe-client –with-big-tables –with-readline –with-ssl –with-embedded-server –enable-local-infile –with-plugins=partition,innobase,myisammrg

make && make install

chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
初始化表,如果请指定mysql的数据保存位置,可以用  –datadir=/data/mysql/data 这个参数
/usr/local/mysql/bin/mysql_install_db –basedir=/usr/local/mysql –user=mysql
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
/usr/local/mysql/bin/mysqld_safe &
注:在configure的时候,到最后时候会出现这个错误的.
config.status: executing libtool commands
/bin/rm: cannot remove libtoolT': No such file or directory
config.status: executing default commands
这里没有理会.
//修改数据库root用户密码
/usr/local/mysql/bin/mysqladmin -u root password '123456'
/usr/local/mysql/bin/mysql -u root -p
然后输入root用户的密码,这里是123456,回车,这时进入mysql提示符下,说明mysql安装成功了,用exit退出mysql.
mysql>
 
 
=======================================
 
 
第五步 安装php
由于前面已经安装好了php所需的一些类库,所以这里安装方便的多了,记得这里是要打php-fpm补丁的.要先安装 patch 这个包(yum -y install patch)
cd /usr/src
tar zxvf php-5.2.14.tar.gz
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
cd php-5.2.14/
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/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
cp php.ini-dist /usr/local/php/etc/php.ini
 
 
=============================================
 
 
第六步 安装php扩展
如果需要更多的功能,可以安装一下几个软件
cd /usr/src
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../

########################################

tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd 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
cd ../

########################################

tar zxvf 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 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/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
 
修改php.ini文件
手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = "./"
#vi /usr/local/php/etc/php.ini
修改为
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
 
并在此行后增加以下几行,然后保存:
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"
再查找output_buffering = Off
修改为output_buffering = On
再查找; cgi.fix_pathinfo=0,把前面的;注释符号删除,改为cgi.fix_pathinfo=0,防止Nginx文件类型错误解析漏洞。
配置eAccelerator加速PHP:
#mkdir -p /usr/local/eaccelerator_cache
#vi /usr/local/php/etc/php.ini
按shift+g键跳到配置文件的最末尾,加上以下配置信息
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/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"
//创建www用户,php-fpm和nginx统一使用这个
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
vi /usr/local/php/etc/php-fpm.conf
取消以下两行的注释,并将服务用户名和用户所在组(nobody),修改为www
<value name="user">nobody</value>
<value name="group">nobody</value>
启用php-fpm
/usr/local/php/sbin/php-fpm start
 
 
======================================
 
 
第七步 安装NGINX
tar zxvf pcre-8.10.tar.gz
cd pcre-8.10/
./configure
make && make install
cd ../

########################################

tar zxvf nginx-0.8.46.tar.gz
cd nginx-0.8.46/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../
修改 /usr/local/nginx/conf/nginx.conf,删除user nobody;行前面的注释,并修改为 user www www;
将以下几行前面的注释删除,将修改fastcgi_param后面的路径
location ~ \.php$ {
root           html;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
include        fastcgi_params;
}
测试nginx.conf配置文件
/usr/local/nginx/sbin/nginx -t
启用nginx
/usr/local/nginx/sbin/nginx
 
 
第八步 结尾工作
#vi /etc/rc.local
按shift+g快捷键,在末尾增加以下内容:
ulimit -SHn 65535
/usr/local/php/sbin/php-fpm start
/usr/local/nginx/sbin/nginx
测试是否支持php
vi /usr/local/nginx/html/phpinfo.php
输入内容 <?php phpinfo(); ?>
浏览http://ip/phpinfo.php,可以看到php的相关信息,可以查看扩展是否支持.
以上使用的是nginx的默认配置,为了充分发挥nginx的性能,实际生产过程中,我们还需要对nginx进行一些配置优化,请参考:Nginx优化配置(转)
 
 
 
使用技巧:
在不停止Nginx服务的情况下平滑变更Nginx配置
1、修改/usr/local/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:
/usr/local/nginx/sbin/nginx -t
如果屏幕显示以下两行信息,说明配置文件正确:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
2、平滑重启:
①、对于Nginx 0.8.x版本,现在平滑重启Nginx配置非常简单,执行以下命令即可:
/usr/local/nginx/sbin/nginx -s reload
②、对于Nginx 0.8.x之前的版本,平滑重启稍微麻烦一些,按照以下步骤进行即可。输入以下命令查看Nginx主进程号:
ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
屏幕显示的即为Nginx主进程号,例如:
6302
这时,执行以下命令即可使修改过的Nginx配置文件生效:
kill -HUP 6302
或者无需这么麻烦,找到Nginx的Pid文件:
kill -HUP cat /usr/local/nginx/nginx.pid`
检查ImageMagick安装是否成功,也可以用以下命令查看
convert -version

Leave a Reply

Your email address will not be published.