目录:    

    1.配置系统软件源

    2.Apache的安装    

      2.1 Apache的下载

      2.2 Apache的安装

    3.mysql的安装

      3.1 mysql的下载

      3.2 mysql的安装

    4.php的安装

      4.1 php下载

      4.2 php安装

    5.测试

      5.1 测试Apache连接php

      5.2 测试php连接mysql

    

  1. 配置系统软件源

     本次安装使用的系统软件源为网易163开源镜像软件源。

    http://mirrors.163.com/.help/

    Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache

    http://mirrors.163.com/.help/centos.html

    Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_02

        

    mkdir -p /etc/yum.repos.d/repo  #在/etc/yum.repos.d/ 目录下创建repo文件夹

     mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo/  #将/etc/yum.repos.d/目录文件夹下面的所有后缀是repo的文件,移动到/etc/yum.repos.d/repo文件夹下

     wget http://mirrors.163.com/.help/CentOS6-Base-163.repo   #从网易163镜像源服务器上下载centos6.5的repo文件

    Centos6.5 安装配置 Apache +mysql +php 操作文档_php_03

    提示找不到wget服务 ,需要安装wget服务,安装wget服务,需要repo文件,需要将原repo文件还原至原文件夹

    mv /etc/yum.repos.d/repo/*repo /etc/yum.repos.d/

    yum clean all

    yum makecache

    yum -y install wget

    Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_04

    Centos6.5 安装配置 Apache +mysql +php 操作文档_php_05

    

     mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo/  #将/etc/yum.repos.d/目录文件夹下面的所有后缀是repo的文件,移动到/etc/yum.repos.d/repo文件夹下

     wget http://mirrors.163.com/.help/CentOS6-Base-163.repo   #从网易163镜像源服务器上下载centos6.5的repo文件

    Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_06

     mv CentOS6-Base-163.repo /etc/yum.repos.d/   #将Centos6-Base-163.repo 移动至/etc/yum.repos.d文件夹下

     ll /etc/yum.repos.d/    #查看权限

    Centos6.5 安装配置 Apache +mysql +php 操作文档_php_07

     vi /etc/yum.repos.d/CentOS6-Base-163.repo   

     修改所有 gpgcheck=0

    Centos6.5 安装配置 Apache +mysql +php 操作文档_php_08

    yum clean all

    yum makecache

    yum repolist

    Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_09


2.apache的安装

    2.1Apache的下载

    http://www.apache.org/dyn/closer.cgi

    Centos6.5 安装配置 Apache +mysql +php 操作文档_php_10

    

    Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_11

    Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_12

    2.2 apache 的安装

    yum -y install gcc make tar libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel   #安装一些需要的服务及插件

    Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_13 

    将httpd-2.4.32.tar.gz上传至/usr/local/src文件夹

    Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_14

    tar -zxvf httpd-2.4.32.tar.gz   #解压缩软件包

    

    Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_15

    ./configure --prefix=/usr/local/apache2 --enable-rewrite --enable-so --enable-headers --enable-expires --with-mpm=worker --enable-modules=most --enable-deflate     #编译安装

    Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_16

    找不到apr ,需要安装apr

    wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz   #下载apr-1.4.5.tar.gz

    wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz      #下载apr-util-1.3.12.tar.gz

            wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip      #下载 pcre-8.10.zip

            Centos6.5 安装配置 Apache +mysql +php 操作文档_php_17

            yum remove apr-util-devel apr apr-util-mysql apr-docs apr-devel apr-util apr-util-docs    

            Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_18

            a. 解决apr not found 问题

            tar -zxf apr-1.4.5.tar.gz

            cd apr-1.4.5

            ls

            Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_19

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

            Centos6.5 安装配置 Apache +mysql +php 操作文档_php_20

            make && make install

            Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_21

            b.解决APR-util not found问题:

            tar -zxf apr-util-1.3.12.tar.gz

            ls    

            cd apr-util-1.3.12

            ls

           Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_22 

            ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config

            Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_23

            make

            Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_24

            make install

            Centos6.5 安装配置 Apache +mysql +php 操作文档_php_25

    ./configure仍提示APR-util not found,增加--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

        ./configure --prefix=/usr/local/apache2 --enable-rewrite --enable-so --enable-headers --enable-expires --with-mpm=worker --enable-modules=most --enable-deflate --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util  执行文件

        Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_26

        make && make install  (此处我安装的是 2.4.29版本的http),经过多次排查错误,终于编译安装成功。

        Centos6.5 安装配置 Apache +mysql +php 操作文档_php_27

2.3  查看安装的版本:

        /usr/local/apache2/bin/apachectl -v

        Centos6.5 安装配置 Apache +mysql +php 操作文档_php_28


三、 Mysql的安装

    3.1mysql的下载

        Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_29

    Centos6.5 安装配置 Apache +mysql +php 操作文档_php_30


    Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_31

    

    

Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_32


Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_33


3.2  mysql 的安装

       安装插件;

    yum -y install gcc gcc-c++ make tar openssl openssl-devel cmake ncurses ncurses-devel 

       Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_34

    (1) 创建数据库文件夹 、创建数据库组  创建数据库用户、

        mkdir -p /usr/local/mysql        #安装数据库路径

        mkdir -p /data/mysql                # 数据库路径

        groupadd mysql

        useradd -g mysql -M -s /sbin/nologin mysql

        Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_35

    (2)上传数据库安装包,解压缩数据库包

        cd /usr/local/src

        ls

        tar -zxvf mysql-5.7.22.tar.gz 

        Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_36

        ls

        cd mysql-5.7.22

        Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_37

    

        cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_DATADIR=/usr/local/mysql/mydata -DSYSCONFDIR=/etc -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 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_SSL=yes -DWITH_BOOST=/usr/local/boost/boost_1_59_0 -DMYSQL_USER=mysql


        Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_38

        提示 没有找到 boost,解决办法:

        (1)在/usr/local 下创建一个名为boost的文件夹

            mkdir -p /usr/local/boost

         (2)进入这个新建的文件夹然后下载boost

             wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

        (3)解压:

               tar -zxvf boost_1_59_0.tar.gz

        Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_39

        (4)  进行配置

                ./bootstrap.sh

        (5)  编译:

                ./b2

        (6) 安装

                ./b2 install

        编译安装完成后,会把boost头文件拷贝到/usr/local/include/目录下,库文件在/usr/local/lib/下


安装cmake(最新版本)

        (1) 获取源码:依然下载到/usr/local/src目录下,cd /usr/local/src,获取软件包:

                  wget https://cmake.org/files/v3.8/cmake-3.8.0.tar.gz

        (2)  解压:

                    tar -zxvf cmake-3.8.0.tar.gz

         (3) 进入cmake目录:

                    cd cmake-3.8.0

            (4) ./bootsrtap

            (5)  gmake

            (6)  gmake install

            (7) 添加环境变量(此步骤很重要,不然运行cmake的时候会提示找不到 CMAKE_ROOT)

                    用vi在文件/etc/profile 文件中增加变量,使其永久有效:

                    vi  /etc/provile

                    在文件末尾追加以下两行代码:

                    

        PATH=/usr/local/src/cmake-3.8.0/bin:$PATH

        export PATH

            然后执行以下操作:

                source /etc/profile          #使其生效

                 echo $PATH             #查看PATH值

        


切换到MySQL目录,继续 cmake

        cd /usr/local/src/mysql-5.7.22

        cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_DATADIR=/usr/local/mysql/mydata -DSYSCONFDIR=/etc -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 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_SSL=yes -DWITH_BOOST=/usr/local/boost/boost_1_59_0 -DMYSQL_USER=mysql

        Centos6.5 安装配置 Apache +mysql +php 操作文档_php_40

        (经过多次的排除问题,终于cmake成功)

        然后进行make  &&  make install     (编译 安装  大概需要半个小时左右)

        Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_41

        

        然后到mysql的安装目录bin下,初始化数据库:

            cd  /usr/local/mysql/bin

            ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql --socket=/usr/local/mysql/mysql.sock

            运行后最后一句[note] 生成了一个mysql默认密码,复制到一个地方,保存下来

          Centos6.5 安装配置 Apache +mysql +php 操作文档_php_42  

     添加mysql服务,拷贝mysql配置文件:

     回到mysql安装目录 cd ..
     进入support-files目录 cd support-files
     复制启动文件 cp -a mysql.server /etc/init.d/mysql  
//-a 可以把原来的属性一起复制过来

        Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_43

        

        启动mysql

        Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_44        出现上面的错误,需要修改 /etc/my.cnf配置文件

        Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_45

        查找/usr/local/mysql 目录下面是不是有mysql.sock文件夹,有的话,需要删掉 ,就可以启动成功了。

        Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_46            

            设置开机自启动:

                chkconfig mysql on

            

    登陆mysql:

        到 mysql安装目录下的bin目录下:

            cd /usr/local/mysql/bin

            ./mysql -uroot -p

            Enter password:            //输入之前保存的默认密码

        Centos6.5 安装配置 Apache +mysql +php 操作文档_php_47

        

        修改root密码:

        SET PASSWORD = PASSWORD('mysql123');

            Centos6.5 安装配置 Apache +mysql +php 操作文档_php_48

            

            更新mysql的系统权限相关表;

            flush privileges;

            Centos6.5 安装配置 Apache +mysql +php 操作文档_php_49

        

四:      PHP安装

        4.1  PHP的下载:

        http://php.net/downloads.php

         Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_50 

     Centos6.5 安装配置 Apache +mysql +php 操作文档_php_51   

    4.2  PHP的安装:

       yum -y install epel-release gcc gcc-c++ make tar pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel 

   Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_52

  Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_53   

        上传php安装包:

        cd /usr/local/src

        ls

      Centos6.5 安装配置 Apache +mysql +php 操作文档_php_54

       

      tar -zxvf php-7.2.7.tar.gz 

        ls

         cd     

    Centos6.5 安装配置 Apache +mysql +php 操作文档_php_55

    

cp -frp /usr/lib64/libldap* /usr/lib/

 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --with-apxs2=/usr/local/apache2/bin/apxs --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

    

Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_56


        make && make install

        Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_57

    

        /usr/local/php/bin/php -v   查看版本

        Centos6.5 安装配置 Apache +mysql +php 操作文档_php_58


五.  测试:

    1.测试apache 连接php

        /usr/local/apache2/bin/apachectl -k start

        ps auxfw | grep apache

        Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_59

        cd /usr/local/apache2/htdocs/

        ls

        vim index.html

        Centos6.5 安装配置 Apache +mysql +php 操作文档_php_60


        Centos6.5 安装配置 Apache +mysql +php 操作文档_php_61

            vim /usr/local/apache2/conf/httpd.conf

            Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_62

            Centos6.5 安装配置 Apache +mysql +php 操作文档_mysql_63

        /usr/local/apache2/bin/apachectl -k graceful

       Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_64

        解决以上的错误:

         vi /etc/httpd/conf/httpd.conf   加入一句  ServerName  localhost:80


        cd /usr/local/apache2/htdocs

        vim test.php

        Centos6.5 安装配置 Apache +mysql +php 操作文档_php_65

        Centos6.5 安装配置 Apache +mysql +php 操作文档_Apache_66


5.2 测试php连接mysql

    

    vim testmysql.php

    

<?PHP

    $link=mysqli_connect("127.0.0.1","root","mysql123");

    if($link){

        echo"ok,测试成功  恭喜恭喜";

    }else{

        echo"error";

    }

?>

~    


Centos6.5 安装配置 Apache +mysql +php 操作文档_php_67