nginx+php+mysql安装 一

.环境准备:

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

 

. 软件准备
    wget http://sysoev.ru/nginx/nginx-0.7.61.tar.gz
    wget http://www.php.net/get/php-5.2.10.tar.gz/from/this/mirror
    wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.10-fpm-0.5.11.diff.gz
   wge   http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.35.tar.gz/from/http://mysql.he.net/
    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-7.9.tar.gz
    wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.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.2.2.tgz
   
 
. 其他下载地址:
    wget http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.7.61.tar.gz
    wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.10.tar.gz
    wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.10-fpm-0.5.11.diff.gz
    wget http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.1.35.tar.gz
    wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.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/memcache/memcache-2.2.5.tgz
    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/pcre/pcre-7.9.tar.gz
    wget http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.5.3.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.2.2.tgz

 

wget http://www.nginx.com.cn/download/nginx-0.8.20.tar.gz

 

4安装PHP支持库
a) iconv

wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.tar.gz

      ./configure --prefix=/usr/local
      make
      make install

b) libmcrypt

wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz

      ./configure
      make
      make install
      /sbin/ldconfig

c)mhash

wget http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
      ./configure
      make
      make install

d)

      cd libltdl/
      ./configure --enable-ltdl-install
      make
      make install

 

 

  iv. 建立链接
      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

 

.编译安装mysql
    /usr/sbin/groupadd mysql
    /usr/sbin/useradd -g mysql mysql

wget http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.1.35.tar.gz
    tar zxvf mysql-5.1.35.tar.gz
    cd mysql-5.1.35/
    ./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all --enable-local-infile --enable-thread-safe-client --enable-assembler --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-unix-socket-path=/usr/local/tmp/mysql.sock --with-plugins=all --with-big-tables --with-readline --with-ssl --with-embedded-server

 

  

make

make install

chmod +w /usr/local/mysql/

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

/usr/local/mysql/bin/mysql_install_db

Vi /etc/my.cnf

 

[mysqld]

#datadir=/var/lib/mysql

datadir=/usr/local/mysql/data

socket=/var/lib/mysql/mysql.sock

user=mysql

# Default to using old password format for compatibility with mysql 3.x

# clients (those using the mysqlclient10 compatibility package).

old_passwords=1

 

# Disabling symbolic-links is recommended to prevent assorted security risks;

# to do so, uncomment this line:

# symbolic-links=0

 

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

 

启动脚本是:

/bin/sh /usr/local/mysql/bin/mysqld_safe -user=mysql &

 

添加为服务

cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql

chkconfig --level 345 mysql on

echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf

echo "/usr/local/lib" >>/etc/ld.so.conf

ldconfig

ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql

ln -s /usr/local/mysql/include/mysql /usr/include/mysql

service mysql start

/usr/local/mysql/bin/mysqladmin -u root password root    //root改为你需要的密码

service mysql restart

 

.  编译安装php

tar zxvf php-5.2.10.tar.gz
    gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1
    cd php-5.2.10/

 

   ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/php/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 --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 --without-pear --with-curl --with-curlwrappers

make ZEND_EXTRA_LIBS='-liconv'
make install

cp -a php.ini-recommended /usr/local/php/php.ini

编译安装PHP扩展
    i. memcache
客户端
      tar zxvf memcache-2.2.5.tgz
      cd memcache-2.2.5/
      /data/php-5.2.10/bin/phpize
      ./configure --with-php-config=/data/php-5.2.10/bin/php-config
      make
      make install
      cd ../
    ii. eaccelerator
加速引擎
      tar jxvf eaccelerator-0.9.5.3.tar.bz2
      cd eaccelerator-0.9.5.3/
      /data/php-5.2.10/bin/phpize
      ./configure --enable-eaccelerator=shared --with-php-config=/data/php-5.2.10/bin/php-config
      make
      make install
      cd ../
    iii. PDO_MYSQL
      tar zxvf PDO_MYSQL-1.0.2.tgz
      cd PDO_MYSQL-1.0.2/
      /data/php-5.2.10/bin/phpize
      ./configure --with-php-config=/data/php-5.2.10/bin/php-config --with-pdo-mysql=/data/mysql-5.1.35
      make
      make install
      cd ../
    iv. ImageMagick
      tar zxvf ImageMagick.tar.gz
      cd ImageMagick-6.5.1-2/
      ./configure
      make
      make install
      cd ../
    v. imagick
      tar zxvf imagick-2.2.2.tgz
      cd imagick-2.2.2/
      /data/php-5.2.10/bin/phpize
      ./configure --with-php-config=/data/php-5.2.10/bin/php-config
      make
      make install
修改PHP配置文件
    i.
手工修改:
     
查找/data/php-5.2.10/etc/php.ini中的extension_dir = "./"
 
  修改为extension_dir = "/data/php-5.2.10/lib/php/extensions/no-debug-non-zts-20060613/"
 
  并在此行后增加以下几行,然后保存:
 
  extension = "memcache.so"
 
  extension = "pdo_mysql.so"
 
  extension = "imagick.so"
 
  再查找output_buffering = Off
 
  修改为output_buffering = On
    ii.
自动修改:
     
若嫌手工修改麻烦,可执行以下shell命令,自动完成对php.ini文件的修改:
      sed -i 's#extension_dir = "./"#extension_dir = "/data/php-5.2.10/lib/php/extensions/no-debug-non-zts-20060613/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\nextension = "imagick.so"\n#' /data/php-5.2.10/etc/php.ini
      sed -i 's#output_buffering = Off#output_buffering = On#' /data/php-5.2.10/etc/php.ini
      sed -i "s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g" /data/php-5.2.10/etc/php.ini
    iii.
配置eAccelerator加速PHP
      mkdir -p /tmp/eaccelerator_cache
      vi /data/php-5.2.10/etc/php.ini
    跳到配置文件的最末尾,加上以下配置信息:
      [eaccelerator]
      zend_extension="/data/php-5.2.10/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
      eaccelerator.shm_size="64"
      eaccelerator.cache_dir="/tmp/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"
    iv.
创建www用户和组
      /usr/sbin/groupadd www
      /usr/sbin/useradd -g www www
      mkdir -p /data0/htdocs/blog
      chmod +w /data0/htdocs/blog
      chown -R www:www /data0/htdocs/blog
      mkdir -p /data0/htdocs/www
      chmod +w /data0/htdocs/www
      chown -R www:www /data0/htdocs/www  

你可能感兴趣的:(nginx,mysql,PHP,数据库,休闲)