Centos5.7下nginx1.2.0+mysql5.5.24+php5.4.3的安装


1)nginx1.2.0的安装

wget  http://nginx.org/download/nginx-1.2.0.tar.gz

tar xzf  nginx-1.2.0.tar.gz

cd nginx-1.2.0

./configure

make && make install


2)mysql5.5.24的安装

wget  http://www.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.24.tar.gz/from/http://mirror.services.wisc.edu/mysql/

tar xzf mysql-5.5.24.tar.gz

mysql5.5以后开始采用cmake 编译

安装cmake

如果是干净的系统

yum -y install gcc libxml2-dev curl screen \

libpng12-dev autoconf libpcre3-dev make bzip2 \

libevent-dev patch libjpeg62-dev libcurl4-openssl-dev \

libfreetype6-dev g++ libtool libncurses5-dev psmisc lrzsz

然后运行

yum -y install cmake

cd  mysql-5.5.24

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/data/mysql/data \

-DDEFAULT_CHARSET=utf8 \

-DWITH_READLINE=1 \

-DWITH_SSL=system \

-DWITH_EMBEDDED_SERVER=1 \

-DENABLED_LOCAL_INFILE=1 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_DEBUG=0

make && make install

cp support-files/my-medium.cnf /usr/local/mysql/my.cnf

chmod +x /usr/local/mysql

chown -R mysql.mysql /usr/local/mysql


下面几步主要是配置mysql开机启动

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

chmod +x /etc/init.d/mysql

chkconfig -list

chkconfig -add mysql

chkconfig mysql on`

chkconfig -list mysql

安装默认数据库表

/usr/local/mysql/scripts/mysql_install_db –basedir=/usr/local/mysql –datadir=/home/mysql/data –user=mysql

启动mysql   /etc/init.d/mysql  start


3)php5.4.3安装

wget  http://www.php.net/get/php-5.4.3.tar.gz/from/cn2.php.net/mirror

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.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://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"

wget http://imagemagick.mirrorcatalogs.com/ImageMagick-6.7.6-9.tar.gz

wget http://pecl.php.net/get/imagick-3.1.0RC1.tgz

编译安装php5.4.3所需支持库

tar zxvf libiconv-1.14.tar.gz

cd libiconv-1.14

./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

ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config


export LD_LIBRARY_PATH=/usr/local/lib:LD_LIBRARY_PATH

tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/

/sbin/ldconfig

./configure

make

make install

cd ../

编译php

安装依赖包

yum install ncurses-devel libxml2-devel bzip2-devel libcurl-devel \

curl-devel libjpeg-devel libpng-devel freetype-devel net-snmp-devel

tar xvzf php-5.4.3.tar.gz

cd php-5.4.3

./configure –prefix=/usr/local/php5.4.3 –with-config-file-path=/usr/local/php5.4.3/etc \

–with-mysql=/usr/local/mysql/ –with-mysqli=/usr/local/mysql/bin/mysql_config \

–with-pdo-mysql=/usr/local/mysql/ –with-iconv-dir=/usr/local –enable-fpm  \

–disable-phar –with-fpm-user=www-data –with-fpm-group=www-data –with-pcre-regex \

–with-zlib –with-bz2 –enable-calendar –with-curl –enable-dba –with-libxml-dir \

–enable-ftp –with-gd –with-jpeg-dir –with-png-dir –with-zlib-dir –with-freetype-dir \

–enable-gd-native-ttf –enable-gd-jis-conv –with-mhash –enable-mbstring –with-mcrypt  \

–enable-pcntl  –enable-xml –disable-rpath  –enable-shmop –enable-sockets –enable-zip \

–enable-bcmath –with-snmp –disable-ipv6


make ZEND_EXTRA_LIBS='-liconv'

make test  

此时如果是64位操作系统,会出现"

libmysqlclient.so.18: cannot open shared object file: No such file or directory"的错误

解决这个错误只需要

ln -s /usr/local/mysql/lib/libmysqlclient.so.18  /usr/lib64/ 即可

make install

cp php.ini-production /usr/local/php5.4.3/etc/php.ini

编译安装PHP5扩展模块

wget http://pecl.php.net/get/memcache-3.0.5.tgz

tar zxvf memcache-3.0.5.tgz

cd memcache-3.0.5/

/usr/local/php5.4.3/bin/phpize

./configure –with-php-config=/usr/local/php5.4.3/bin/php-config

make

make install

cd ../

wget  http://pecl.php.net/get/memcached-2.0.1.tgz

tar xvzf memcached-2.0.1.tgz

cd memcached-2.0.1

/usr/local/php5.4.3/bin/phpize

./configure –with-php-config=/usr/local/php5.4.3/bin/php-config

会出现错误提示“memcached support requires libmemcached. Use –with-libmemcached-dir=”

需要安装libmemcached

centos如果需要通过yum安装libmemcached 那需要完成以下几步操作


1. 从下面下载最新的centalt-release rpm

http://centos.alt.ru/repository/centos/5/x86_64/

2. 安装 centalt-release rpm:

 

rpm -Uvh centalt-release*rpm

3. 安装libmemcached-devel rpm包:

 

yum install libmemcached-devel


make

make install

cd ../


tar zxvf ImageMagick-6.7.6-9.tar.gz

cd ImageMagick-6.7.6-9/

./configure –prefix=/usr/local/ImageMagick/ 

make

make install

cd ../

tar zxvf imagick-3.1.0RC1.tgz

cd imagick-3.1.0RC1/

/usr/local/php5.4.3/bin/phpize

./configure –with-php-config=/usr/local/php5.4.3/bin/php-config –with-imagick=/usr/local/ImageMagick

make

出现“ fatal error: wand/MagickWand.h: No such file or directory "错误提示


解决办法:

1.确认已安装pkgconfig,否则安装pkgconfig

2.完成以下两步

yum install gtk+-devel

export PKG_CONFIG_PATH=/usr/local/ImageMagick/lib/pkgconfig/

然后重新进行./configure,make操作

make install

cd ../

修改php配置

vim  /usr/local/php5.4.3/etc/php.ini 

最后增加:

;change for hugwww

extension_dir = /usr/local/php5.4.3/lib/php/extensions/no-debug-non-zts-20100525/

extension = "memcache.so"

extension = "memcached.so"

extension = "imagick.so"

启动php-fpm

cd /usr/local/php5.4.3/etc/

cp php-fpm.conf.default php-fpm.conf

groupadd www-data

useradd -g www-data www-data -s /usr/sbin/nologin

/usr/local/php5.4.3/sbin/php-fpm

查看是否启动,看到9000端口表示启动成功

netstat -antp |grep :9000 

修改nginx配置文件 nginx.conf

去掉下面文字前的注释符


        location ~ \.php$ {

            root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME    /xxx/xxx$fastcgi_script_name;

            include        fastcgi_params;

        }

其中/xxxx/xxxx为ningx的web根目录,如果不修改,访问php文件可能会出现“no input file specified ”

最后重新启动nginx

可以写一个测试php文件放在nginx的web根目录下

<?php

phpinfo();

?>

在浏览器中打开  http://xxx.xxxx.xxx/test.php 看到php信息即php安装配置正确