【服务器配置】CentOS+Nginx+PHP+Mysql环境配置(一)

用户 流年岁月 2014-8-21 6127

本帖最后由 流年岁月 于 2014-8-21 04:54 编辑

[利用yum命令配置、升级所需程序库]
    # sudo -s
    # LANG=C
    # yum -y install gcc gcc-c++ autoconf

    #yum -y install make     //如果不安装make,那么cmake的时候会出问题

    # yum -y install cmake

    # yum -y install bison

    接下来最好手动编译这些库: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
    ↑安装、升级这些程序库

[下载环境所需文件到指定目录]
↑ 在根目录建立software文件夹
# cd /software
↑ 进入software文件夹
# wget http://sysoev.ru/nginx/nginx-0.7.19.tar.gz
# wget http://www.php.net/get/php-5.2.6.tar.gz/from/this/mirror
# wget http://php-fpm.anight.org/downloads/head/php-5.2.6-fpm-0.5.9.diff.gz
# wget http://blog.s135.com/soft/linux/mysql/mysql-5.1.26-rc.tar.gz
# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.12.tar.gz
# wget http://mirror.optus.net/sourceforge/m/mc/mcrypt/libmcrypt-2.5.8.tar.gz
# wget http://mirror.optus.net/sourceforge/m/mc/mcrypt/mcrypt-2.6.7.tar.gz
# wget http://pecl.php.net/get/memcache-2.2.3.tgz
# wget http://mirror.optus.net/sourceforge/m/mh/mhash/mhash-0.9.9.tar.gz
# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.7.tar.gz
# wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
↑ 下载这些文件到software目录

[编译安装PHP 5.2.6所需的支持库]

    # tar zxvf libiconv-1.12.tar.gz
    ↑ 解压(tar) 参数(zxvf) 文件名(libiconv-1.12.tar.gz)
    # cd libiconv-1.12/
    ↑ 进入解压出来的文件的文件夹(libiconv-1.12)
    # ./configure --prefix=/usr/local
    ↑ 配置安装信息 指定安装目录为/usr/local
    # make
    ↑ make安装文件
    # make install
    ↑ 开始安装
    # cd ../
    ↑ 返回上级目录(此处即software目录)

    # 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 http://www.cnblogs.com/

    # tar zxvf mhash-0.9.9.tar.gz
    # cd mhash-0.9.9/
    # ./configure
    # make
    # make install
    # cd ../

    # cp /usr/local/lib/libmcrypt.* /usr/lib

    #ln -sf /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4     //////此处针对64位系统
    # ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

    # tar zxvf mcrypt-2.6.7.tar.gz
    # cd mcrypt-2.6.7/
    # ./configure            /////////此处针对centOS6.0,用这个命令    #./configure --with-libmcrypt-prefix=/usr/local    如果是64位系统则只需要 ./configure   如果提示mhash版本低的错误,则这样预编译 #LD_LIBRARY_PATH=/usr/local/lib  ./configure

    64  位安装时,此处可能会提示错误:configure: error: *** libmcrypt was not found     应这样解决:ln -s  /usr/local/bin/libmcrypt-config  /usr/bin/libmcrypt-config   实在不行,直接拷贝 cp /usr/local/bin/libmcrypt-config  /usr/bin/ 即可
    # make
    # make install
    # cd ../

    接下来必须先安装GD库需要的包
    zlib-1.1.4安装配置 
    #./configure --shared \\shared生成zlib的共享库文件 
    #make && make install

    freetype
           tar -xvjf freetype-2.1.3.tar.gz
           cd freetype-2.1.3
           ./configure
           make
           make install

    jpeg
    tar -xvzf jpegsrc.v6b.tar.gz
    cd jpeg-6b/
    ./configure
    makedir /usr/local/man & /usr/local/man/man1
    make install
    make install-lib

    png
           tar -xvjf libpng-1.2.5.tar.bz2 
           cd libpng-1.2.5
           #cp scripts/makefile.gcmmx makefile \\makefile.gcmmx是针对MMX指令集优化的
           make
           make install
    最后ldconfig刷新一下
    ldconfig -v 
    确认有
    libjpeg.so.62 =>; libjpeg.so.62.0.0
    libpng.so.3 =>; libpng.so.3.1.2.5
    libpng12.so.0 =>; libpng12.so.0.1.2.5
    libfreetype.so.6 =>; libfreetype.so.6.3.2

    开始安装GD2
    tar -zxvf gd-2.0.27.tar.gz
    cd gd-2.0.27/
    ./configure --prefix=/usr/local/gd2
    确保配置完成以后有
    Support for PNG library:          yes 
    Support for JPEG library:         yes 
    Support for Freetype 2.x library: yes

    make

    make install

    cp gd.h /usr/local/lib  或者 cp gd.h /usr/local/gd2 \\编译PHP的时候会缺少这个文件出错

[编译安装MySQL 5.1.26-rc]
安装mysql 需要安装ncurse库
#tar -zxvf ncurses-5.9
#cd ncurses-5.9
#./configure
#make
#make install


    # /usr/sbin/groupadd mysql
    ↑ 建立mysql用户组
    # /usr/sbin/useradd -g mysql mysql
    ↑ 建立mysql用户到mysql用户组中
    # tar zxvf mysql-5.1.26-rc.tar.gz
    # cd mysql-5.1.26-rc/
    # ./configure --prefix=/usr/local/webserver/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile
    # make && make install
    # chmod +w /usr/local/webserver/mysql
    # chown -R mysql:mysql /usr/local/webserver/mysql
    # cp support-files/my-medium.cnf /usr/local/webserver/mysql/my.cnf
    # cd ../

    # /usr/local/webserver/mysql/bin/mysql_install_db --defaults-file=/usr/local/webserver/mysql/my.cnf --basedir=/usr/local/webserver/mysql --datadir=/usr/local/webserver/mysql/data --user=mysql --pid-file=/usr/local/webserver/mysql/mysql.pid --skip-locking --port=3306 --socket=/tmp/mysql.sock
    ↑ 以mysql用户帐号的身份建立数据表

    # /bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/usr/local/webserver/mysql/my.cnf &
    ↑ 启动MySQL(最后的&表示在后台运行)

64位系统安装mysql5.5.15

先安装 cmake和bison:

#yum -y install cmake
#yum -y install bison

安装mysql:

#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql/ -DMYSQL_DATADIR=/usr/local/webserver/mysql/data -DWITH_INNOBASE_STORAGE_ENGINE=1  -DMYSQL_UNIX_ADDR=/tmp/mysql.sock   -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306  -DWITH_DEBUG=0 

#make

#make install

  复制配置文件

[root@xuhost mysql-5.5.9]# cp support-files/my-medium.cnf /etc/my.cnf

复制启动脚本
[root@xuhost mysql-5.5.9]# cp support-files/mysql.server /etc/init.d/mysqld
[root@xuhost mysql-5.5.9]# chmod 755 /etc/init.d/mysqld

初始化数据表

./mysql_install_db --user=mysql --basedir=/usr/local/webserver/mysql/ --datadir=/usr/local/webserver/mysql/data/ 

  启动数据库
[root@xuhost mysql5.5.9]# /etc/init.d/mysqld start

设置数据库root用户密码:
./mysqladmin -u root password      回车之后输入两次密码即可

设置生产环境,安全数据库设置:退出bin目录
执行:# bin/mysql_secure_installation   回车之后按照提示操作即可

此时启动数据库时,可能会遇到这个错误:“Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!”

解决办法:在/etc/my.cnf 的  [mysqld]选项中 加上   user=mysql 即可

http://bbs.zblogcn.com/static/image/smiley/default/smile.gif流年岁月http://bbs.zblogcn.com/static/image/smiley/default/sad.gif

最新回复 (0)
全部楼主
    • ZBlogger技术交流中心
      2
          
返回