RHEL 6.4系统中的LAMP环境搭建

一、环境准备

1.安装编译工具gcc、gcc-c++

  使用安装光盘作为yum源,安装gcc、gcc-c++,命令如下:

    yum -y install gcc

    yum -y install gcc-c++

2.关闭RPM包安装的Apache、MYSQL服务

1).关闭服务

    service httpd stop

    service mysqld stop

2).关闭自启动

    chkconfig httpd off

    chkconfig mysqld off

3.关闭SELinux和防火墙

1).关闭SELinux

    setenforce 0

    #临时生效

    vi /etc/selinux/config

    SELINUX=disabled

    #重启后永久生效

2).关闭防火墙

    iptables -F

4.关闭不必要的自启动服务

5.拷贝源码包放在/usr/src/lamp/目录下

二、编译安装

1.安装libxml2

  需先yum安装libxml2-devel和python-devel,命令如下:

    yum -y install libxml2-devel

    yum -y install python-devel        

  安装完成后源码包安装libxml2,命令如下:

    cd /usr/src/lamp

    tar zxf libxml2-2.9.1.tar.gz

    cd libxml2-2.9.1

    ./configure --prefix=/usr/local/libxml2/

     make

     make install

2.安装libmcrypt及libltdl

    cd /usr/src/lamp

    tar zxf libmcrypt-2.5.8.tar.gz

    cd libmcrypt-2.5.8

    ./configure --prefix=/usr/local/libmcrypt/

    make

    make install

    cd libltdl

    ./configure --enable-ltdl-install

    make

    make install

3.安装mhash

    cd /usr/src/lamp

    tar zxf mhash-0.9.9.9.tar.gz

    cd mhash-0.9.9.9

    ./configure

    make

    make install

4.安装mcrypt

    cd /usr/src/lamp

    tar zxf mcrypt-2.6.8.tar.gz

    cd mcrypt-2.6.8

    LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/lib ./configure --with-libmcrypt-prefix=/usr/local/libmcrypt

    make

    make install

5.安装zlib

    cd /usr/src/lamp

    tar zxf zlib-1.2.3.tar.gz

    cd zlib-1.2.3

   ./configure

  vi Makefile

  找到CFLAGS=-O3 -DUSE_MMAP,在后面加入 –fPIC 变成 CFLAGS=-O3 –DUSE_MMAP –fPIC

    make

    make install

6.安装libpng

    cd /usr/src/lamp

    tar zxf libpng-1.2.31.gz

    cd libpng-1.2.31

    ./configure --prefix=/usr/local/libpng

    make

    make install

7.安装jpeg6

   mkdir /usr/local/jpeg6        

    mkdir /usr/local/jpeg6/bin

    mkdir /usr/local/jpeg6/lib

    mkdir /usr/local/jpeg6/include

    mkdir -p /usr/local/jpeg6/man/man1

    yum -y install libtool*

    cd /usr/src/lamp

    unzip jpeg-6b.zip

    cd jpeg-6b

     chmod -R 777 *

    cp /usr/share/libtool/config/config.sub    .

    cp /usr/share/libtool/config/config.guess   .

    ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static

    make        

    make install

8.安装freetype

    cd /usr/src/lamp

    tar zxf freetype-2.3.5.tar

    cd freetype-2.3.5

    ./configure --prefix=/usr/local/freetype/

    make

    make install

9.安装GD库

   mkdir /usr/local/gd2

    cd /usr/src/lamp

    tar zxf gd-2.0.35.tar

    cd gd-2.0.35

   vi gd_png.c

   把 #include “png.h” 替换为 #include "/usr/local/libpng/include/png.h"

    ./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-  freetype=/usr/local/freetype/ --with-png=/usr/local/libpng/

    make

    make install

10. 安装Apache

    cd /usr/src/lamp

   tar  zxf  apr-1.4.6.tar.gz

   tar  zxf  apr-util-1.4.1.tar.gz

   tar zxf httpd-2.4.7.tar.gz

   cp  -r  apr-1.4.6  httpd-2.4.7/srclib/apr

   cp  -r  apr-util-1.4.1 httpd-2.4.7/srclib/apr-util

   tar zxf pcre-8.34.tar.gz

   cd pcre-8.34

   ./configure

   make

   make install

 yum install openssl-devel

    cd /usr/src/lamp/httpd-2.4.7

  ./configure --prefix=/usr/local/apache2/ --sysconfdir=/usr/local/apache2/etc/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable- rewrite=shared

     make

     make install

  启动Apache测试:

    /usr/local/apache2/bin/apachectl start

11.安装ncurses

    yum -y install ncurses-devel

    cd /usr/src/lamp

    tar zxf ncurses-5.9.tar.gz

    cd ncurses-5.9

    ./configure --with-shared --without-debug --without-ada --enable-overwrite

    make

    make install

12.安装cmake和bison

   yum -y install cmake

   yum -y install bison

13.安装MySQL

    groupadd mysql

    useradd -g mysql mysql

    cd /usr/src/lamp

    tar zxf mysql-5.5.23.tar.gz

    cd mysql-5.5.23

    cmake  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql    -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DEXTRA_CHARSETS=all   -DDEFAULT_CHARSET=utf8    -DDEFAULT_COLLATION=utf8_general_ci  -DWITH_MYISAM_STORAGE_ENGINE=1  -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1  -DWITH_READLINE=1    -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql  -DMYSQL_TCP_PORT=3306

选项:-DCMAKE_INSTALL_PREFIX=/usr/local/mysql            安装位置

      -DMYSQL_UNIX_ADDR=/tmp/mysql.sock                  指定socket(套接字)文件位置

      -DEXTRA_CHARSETS=all                               扩展字符支持

      -DDEFAULT_CHARSET=utf8                             默认字符集

      -DDEFAULT_COLLATION=utf8_general_ci                默认字符校对

      -DWITH_MYISAM_STORAGE_ENGINE=1                     安装myisam存储引擎

      -DWITH_INNOBASE_STORAGE_ENGINE=1                   安装innodb存储引擎

      -DWITH_MEMORY_STORAGE_ENGINE=1                     安装memory存储引擎

      -DWITH_READLINE=1                                  支持readline库

      -DENABLED_LOCAL_INFILE=1                           启用加载本地数据

      -DMYSQL_USER=mysql                                 指定mysql运行用户

      -DMYSQL_TCP_PORT=3306                              指定mysql端口

    make

    make install

    cd /usr/local/mysql/

    chown -R root .

    chown -R mysql data

    cp support-files/my-medium.cnf /etc/my.cnf

    /usr/local/mysql/scripts/mysql_install_db --user=mysql

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

 重启以后还要生效:

   vi /etc/rc.local

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

 设定mysql密码

   /usr/local/mysql/bin/mysqladmin -u root password 123456

14.安装PHP

  vi /usr/local/gd2/include/gd_io.h

  typedef struct gdIOCtx

   {

           ……

           void (*data);

          #加入此句

    }

    cd /usr/src/lamp

  tar zxf php-5.4.25.tar.gz

  cd php-5.4.25

  vi ext/gd/libgd/gd_compat.c

将#include <png.h> 改为#include </usr/local/libpng/include/png.h>

在#ifdef HAVE_GD_JPG下一行插入#include <stdio.h>

  ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6/  --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets  --with-pdo-mysql=/usr/local/mysql --without-pear

选项:--with-config-file-path=/usr/local/php/etc/        指定配置文件目录

    --with-apxs2=/usr/local/apache2/bin/apxs           指定apache动态模块位置

    --with-mysql=/usr/local/mysql/                     指定mysql位置

    --with-libxml-dir=/usr/local/libxml2/              指定libxml位置

    --with-jpeg-dir=/usr/local/jpeg6/                  指定jpeg位置

    --with-png-dir=/usr/local/libpng/                  指定libpng位置

    --with-freetype-dir=/usr/local/freetype/           指定freetype位置

    --with-gd=/usr/local/gd2/                          指定gd位置

    --with-mcrypt=/usr/local/libmcrypt/                指定libmcrypt位置

    --with-mysqli=/usr/local/mysql/bin/mysql_config    指定mysqli位置

    --enable-soap                                      支持soap服务

    --enable-mbstring=all                              支持多字节,字符串

    --enable-sockets                                   支持套接字

    --with-pdo-mysql=/usr/local/mysql                  启用mysql的pdo模块支持

    --without-pear      不安装pear(安装pear需要连接互联网。PEAR是PHP扩展与应用库)

   make

    make install

    mkdir /usr/local/php/etc

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

    vi /usr/local/apache2/etc/httpd.conf

     AddType application/x-httpd-php .php .phtml .phps         

     .......

     DirectoryIndex index.php index.html

  测试:vi /usr/local/apache2/htdocs/test.php

            <?php

                    phpinfo();

        ?>

       vi /usr/local/apache2/htdocs/mysql.php

           <?php

                 $link=mysql_connect('localhost','root','123');

                 if($link) echo 'iiiiiiiiiiii';

                 mysql_close();

            ?>

15.安装phpMyAdmin

    cd /usr/src/lamp

    tar zxf phpMyAdmin-4.1.4-all-languages.tar.gz

    cp -r phpMyAdmin-4.1.4-all-languages /usr/local/apache2/htdocs/phpmyadmin

    cd /usr/local/apache2/htdocs/phpmyadmin

    cp config.sample.inc.php config.inc.php

    vi config.inc.php

  将$cfg['Servers'][$i]['auth_type'] = 'cookie';改为$cfg['Servers'][$i]['auth_type'] = 'http';

16.搭建论坛

    cd /usr/src/lamp

    unzip Discuz_7.2_FULL_SC_UTF8.zip

    mv upload/ /usr/local/apache2/htdocs/luntan

    /usr/local/mysql/bin/mysql -u root -p

    mysql> create database luntan;

    mysql> grant all on luntan.* to zhangsan@'localhost' identified by '123456';

    cd /usr/local/apache2/htdocs/luntan/

    chown -R daemon config.inc.php p_w_uploads/ forumdata/ uc_client/data/cache/ templates/

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

    short_open_tag = Off 改为 short_open_tag = On

     /usr/local/apache2/bin/apachectl stop

     /usr/local/apache2/bin/apachectl start