1、LAMP架构介绍

LAMP (linux+apache(httpd)+mysql+php 简称为LAMP(LAMP指的Linux(操作系统)、Apache HTTP 服务器,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web应用平台。)
三个角色可以装在不同的服务器上但是apache+php 必须在一台服务器上
LAMP三者工作思路:
第一种是动态访问:首先用户登录用户名访问apache(httpd),apache需要经过php的module(模块)在mysql中读取相应的用户名与密码。(mysql中是不存在任何的图片,与文件的。存的内容是数据如,用户名对应的密码。)
第二种是静态访问:用户登录一个网站后,可以看到的图片就是静态的访问。(直接从服务器获取到的内容不经过mysql的是静态访问)

2、MySQL_MariaDB介绍

MySQL官网 https://www.mysql.com
Mariadb官网 https://mariadb.com/

MySQL是一个关系型数据库,由mysql ab公司开发,mysql在2008年被sun公司收购(10亿刀),2009年sun公司被oracle公司收购(74亿刀)
Mariadb为MySQL的一个分支,MariaDB主要由SkySQL公司(现更名为MariaDB公司)维护,SkySQL公司由MySQL原作者带领大部分原班人马创立.
Community 社区版本(开源版本)、
Enterprise 企业版、 GA(GenerallyAvailable)指通用版本在生产环境中用的、DMR(Development Milestone Release)开发里程碑发布版 、RC(Release Candidate)发行候选版本、Beta开放测试版本、
Alpha内部测试版本
Mariadb5.5版本对应MySQL的5.5,10.0对应MySQL5.6

3、MySQL安装 (总结)

mysql的几个常用的安装方式:rpm(不能定义安装的路径)、源码、二进制免编译(能定义安装的路径这是与rpm的不同之一)
这里选择二进制方式进行安装, 因为二进制包只需解压即可,不需要执行cmake/configure,manke,make install等过程,然后进行简单配置后就可以使用了

[root@chy01 src]# uname -a
Linux chy01 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
(首先区分linux系统为32还是64然后下载mysql包)
[root@chy01 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz  
(下载二进制mysql包)
[root@chy01 src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz 
(解压mysql包)
[root@chy01 src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql (移动mysql到/usr/local/mysql下)
[root@chy01 src]# cd /usr/local/mysql/ (进入此目录下)
[root@chy01 mysql]# ls (进入后查看文件)
bin      data  include  man         README   share      support-files
COPYING  docs  lib      mysql-test  scripts  sql-bench
[root@chy01 mysql]# useradd -s /sbin/nologin -M mysql  (增加mysql用户)
[root@chy01 mysql]# mkdir -p /data/mysql
(创建data目录,此目录下存放的是数据库)
[root@chy01 mysql]# useradd mysql (增加mysql用户)
[root@chy01 mysql]#  chown -R mysql /data/mysql 给这个mysql给权限  
[root@chy01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper
(初始化时报了一个错误,解决方法如下
[root@chy01 mysql]# yum list |grep perl |grep -i dumper
perl-Data-Dumper.x86_64                 2.145-3.el7                    base     
perl-Data-Dumper-Concise.noarch         2.020-6.el7                    epel     
perl-Data-Dumper-Names.noarch           0.03-17.el7                    epel     
perl-XML-Dumper.noarch                  0.81-17.el7                    base    
(模糊搜索perl 里面的dumper包)
[root@chy01 mysql]# yum install -y perl-Data-Dumper.x86_64 
(找到4个dumper包以后一个一个的测试,然后安装)
[root@chy01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
(当再次编译时发现不报错就证明安装的dumper包是正确的)
[root@chy01 mysql]# echo $?
0
(编译后马上用echo 测试,这个测试的前提是马上就要测试中间不要有任何的其它操作)
第二种方法是编译后查看有没有(如下的两个ok,如有就证明成功了)
OK
Filling help tables...2017-07-26 08:23:02 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-07-26 08:23:02 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-07-26 08:23:02 0 [Note] ./bin/mysqld (mysqld 5.6.35) starting as process 4652 ...
2017-07-26 08:23:02 4652 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-07-26 08:23:02 4652 [Note] InnoDB: The InnoDB memory heap is disabled
2017-07-26 08:23:02 4652 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-07-26 08:23:02 4652 [Note] InnoDB: Memory barrier is not used
2017-07-26 08:23:02 4652 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-07-26 08:23:02 4652 [Note] InnoDB: Using Linux native AIO
2017-07-26 08:23:02 4652 [Note] InnoDB: Using CPU crc32 instructions
2017-07-26 08:23:02 4652 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-07-26 08:23:02 4652 [Note] InnoDB: Completed initialization of buffer pool
2017-07-26 08:23:02 4652 [Note] InnoDB: Highest supported file format is Barracuda.
2017-07-26 08:23:02 4652 [Note] InnoDB: 128 rollback segment(s) are active.
2017-07-26 08:23:02 4652 [Note] InnoDB: Waiting for purge to start
2017-07-26 08:23:02 4652 [Note] InnoDB: 5.6.35 started; log sequence number 1625977
2017-07-26 08:23:02 4652 [Note] Binlog end
2017-07-26 08:23:02 4652 [Note] InnoDB: FTS optimize thread exiting.
2017-07-26 08:23:02 4652 [Note] InnoDB: Starting shutdown...
2017-07-26 08:23:04 4652 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
[root@chy01 mysql]# ls support-files/my-default.cnf 
support-files/my-default.cnf
(如上是mysql的模板配置文件)
[root@chy01 mysql]# cat /etc/my.cnf
(mysql的配置文件就是/etc/my.cnf,如果要更改此位置就需要在启动时指定文件)
[root@chy01 mysql]# rpm -qf /etc/my.cnf
mariadb-libs-5.5.52-1.el7.x86_64
(系统下有一个默认的mysq是rpm安装的)
[root@chy01 mysql]# cp support-files/my-default.cnf  /etc/my.cnf 
cp:是否覆盖"/etc/my.cnf"? y
(需要cp mysql配置文件到/etc/my.cnf下)
[root@chy01 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
(cp support-files/mysql.server这个到/etc/init.d/mysqld(这个里面配置启动脚本)
[root@chy01 mysql]# vi /etc/init.d/mysqld  (增加如下两行配置)
basedir=/usr/local/mysql(这里是mysql的主目录)
datadir=/data/mysql(这是mysql的数据库目录)
[root@chy01 mysql]# ls -l /etc/init.d/mysqld 
-rwxr-xr-x 1 root root 10902 7月  26 08:40 /etc/init.d/mysqld (查看权限是否为755)
[root@chy01 mysql]# chkconfig --add mysqld(增加开机启动的选项)
[root@chy01 mysql]# chkconfig --list
注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 
      如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
      欲查看对特定 target 启用的服务请执行
      'systemctl list-dependencies [target]'。
mysqld          0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@chy01 mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/chy01.err'.
. SUCCESS! (启动mysql第一种方法)
[root@chy01 mysql]# service mysqld start 
Starting MySQL. SUCCESS! 
(启动mysql第二种方法)
[root@chy01 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql & 
(第三种用命令行启动)
[root@chy01 mysql]# ps -aux |grep mysql
root       5570  0.0  0.1 113256  1584 pts/0    S    08:50   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql
mysql      5673  0.2 29.7 973048 455708 pts/0   Sl   08:50   0:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/chy01.err --pid-file=/data/mysql/chy01.pid
root       5721  0.0  0.0 112664   976 pts/0    R+   08:53   0:00 grep --color=auto mysql
[root@chy01 mysql]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2053/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2875/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      5673/mysqld         
tcp6       0      0 :::22                   :::*                    LISTEN      2053/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2875/master        
(启动成功)
[root@chy01 mysql]# killall mysqld
(关闭由命令行启动的方式)

登录mysql用户

[root@chy01 mysql]# echo  'export  PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile  (需要做mysql的环境变量,如果不做环境变量不能使用mysq命令)
[root@chy01 mysql]# tail -n1 /etc/profile(查看增加环境变量的文件)
export  PATH=/usr/local/mysql/bin:$PATH
[root@chy01 mysql]# source /etc/profile
[root@chy01 mysql]# mysql -uroot (用root用户登录测试一下)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

4、MariaDB安装

如上介绍了mysql的安装方法,如下是mariadb的安装方法,思路都是一样的。

[root@chy01 src]# cd /usr/local/src
(进入到cd /usr/local/src 里面)
[root@chy src]#  wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
(将mariadb下载到/src目录下)
[root@chy src]# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz 
(解压包到/src目录下)
[root@chy src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb (移动mariadb到指定目录下)
[root@chy src]# cd !$
cd /usr/local/mariadb
(进入到mariadb目录下)
[root@chy mariadb]# useradd -s /sbin/nologin -M mysql1 (增加mysql1用户并且不创建mysql1的家目录)
[root@chy mariadb]# mkdir -p /data/mariadb (创建mariadb的数据库/data/)
[root@chy mariadb]# chown -R mysql1 /data/mariadb (指定/data的属主为mysql1)
[root@chy mariadb]# ./scripts/mysql_install_db --user=mysql1 --basedir=/usr/local/mariadb/ --datadir=/data/mariadb
(初始化mariadb,初始化这里需要注意一个问题就是--basedir这里是basedir并不是datadir的原因是之前在虚拟机上装过另一个数据库mysql,那个数据库定义的是datadir,所以这边定义时就要注意这个问题)
[root@chy mariadb]# echo $?
0
(测试的第一种方法成功)
[root@chy mariadb]# ./scripts/mysql_install_db --user=mysql1 --basedir=/usr/local/mariadb/ --datadir=/data/mariadb
Installing MariaDB/MySQL system tables in '/data/mariadb' ...
OK
(看是否成功可以看过程中是否有OK字样,有证明成功)
[root@chy mariadb]# ls support-files/
binary-configure        my-large.cnf            mysql-log-rotate        wsrep_notify
magic                   my-medium.cnf           mysql.server            
my-huge.cnf             my-small.cnf            policy/                 
my-innodb-heavy-4G.cnf  mysqld_multi.server     wsrep.cnf       
(进入到mariadb下可以看到和mysql模板配置文件不一样的地方。在mariadb中这几个配置不一样的地方最大的区别是缓存大小)
[root@chy mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf 
(拷贝最小的模板配置文件到/usr/local/mariadb/my.cnf (这里需要注意因为之前有my.cnf是属于mysql的所以这里就不能在将模板配置文件cp到my.cnf只能将配置文件cp到/usr/local/mariadb目录下取名为my.cnf)
[root@chy mariadb]# cp support-files/mysql.server /etc/init.d/mariadb
(并且拷贝启动脚本到/etc/init.d/mariadb目录下)
[root@chy mariadb]# vim /usr/local/mariadb/my.cnf  (此配置文件根据自己需求改动即可)
[root@chy mariadb]# vim /etc/init.d/mariadb 
(增加mariadb的启动脚本,如下内容)
basedir=/usr/local/mariadb
datadir=/data/mariadb
conf=$basedir/my.cnf
(这里增加完成后,还要找到启动脚本在启动脚本中在增加一行内容)
case "$mode" in
  'start')
    # Start daemon

    # Safeguard (relative paths, core dumps..)
    cd $basedir

    echo $echo_n "Starting MySQL"
    if test -x $bindir/mysqld_safe
    then
      # Give extra arguments to mysqld with the my.cnf file. This script
      # may be overwritten at next upgrade.
      $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
      wait_for_ready; return_value=$?
(找到这一行内容在$bindir/mysqld_safe 与--datadir="$datadir"中间增加一行--defaults-file="$conf")
$bindir/mysqld_safe  --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
(增加的意思是增加它的启动脚本)
这里启动时报错:
[root@chy ~]# /etc/init.d/mariadb start 
Starting mariadb (via systemctl):  Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
                                                           [失败]
   解决方法:
 [root@chy mariadb]# vim /etc/my.cnf
   [mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K
user=mysql1(增加一行是因为我的用户是mysql1)

解决的文档:http://www.debugrun.com/a/o5rqKfE.html  (此文档可以查思路)

5、apache安装总结

Apache官网 http://www.apache.org

[root@chy src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.26.tar.gz
[root@chy src]#  wget http://mirrors.hust.edu.cn/apache/apr/apr-1.5.2.tar.gz
[root@chy src]#  wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.5.4.tar.gz
(下载3个包,其中有两个包是qpr包和apr-util,如下是区别:apache 2.2和2.4的安装是有区别的,区别在于:2.4需要安装apr与apr-util函数库,与2.2的数据库是不一样的)
apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便地移植(从linux移植到windows)
)
[root@chy src]# tar zxvf httpd-2.4.26.tar.gz
[root@chy src]#  tar zxvf apr-util-1.5.4.tar.gz
[root@chy src]#  tar zxvf apr-1.5.2.tar.gz
(解压三个包)
[root@chy src]# cd apr-1.5.2/
(首先安装apr)
[root@chy apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@chy apr-1.5.2]# echo $?
0
[root@chy apr-1.5.2]# make && make install
[root@chy apr-1.5.2]# echo $?
0
[root@chy apr-1.5.2]# cd /usr/local/src/apr-util-1.5.4
(然后安装util)
[root@chy apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
(编译安装)
[root@chy apr-util-1.5.4]# echo $?
0
[root@chy apr-util-1.5.4]# make && make install
[root@chy apr-util-1.5.4]# echo $?
0(编译成功)
[root@chy apr-util-1.5.4]# cd /usr/local/src/httpd-2.4.26
(最后开始编译httpd)
[root@chy httpd-2.4.26]#./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
(这里报了一个错误checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/)
[root@chy httpd-2.4.26]# yum list |grep pcre 
pcre.x86_64                                8.32-15.el7_2.1             @anaconda
pcre.i686                                  8.32-15.el7_2.1             base     
pcre-devel.i686                            8.32-15.el7_2.1             base     
pcre-devel.x86_64                          8.32-15.el7_2.1             base     
pcre-static.i686                           8.32-15.el7_2.1             base     
pcre-static.x86_64                         8.32-15.el7_2.1             base     
pcre-tools.x86_64                          8.32-15.el7_2.1             base    
(查看有关pcre的包后安装,pcre-devel的因为我们用的是库)
[root@chy httpd-2.4.26]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
(再次编译时,看有没有错误)
[root@chy httpd-2.4.26]# echo $?
0
(编译成功)
[root@chy httpd-2.4.26]# make && make install
[root@chy httpd-2.4.26]# echo $?
0
(编译成功)
[root@chy httpd-2.4.26]# /usr/local/apache2.4/bin/httpd -M =[root@chy apache2.4]# /usr/local/apache2.4/bin/apachectl -M
(查看apache加载的模块)
[root@chy httpd-2.4.26]# /usr/local/apache2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::338e:589c:fa07:65e5. Set the 'ServerName' directive globally to suppress this message
[root@chy httpd-2.4.26]# ps aux |grep httpd
root      42811  0.0  0.1  95476  2532 ?        Ss   15:47   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    42812  0.0  0.2 382304  4428 ?        Sl   15:47   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    42813  0.0  0.2 382304  4428 ?        Sl   15:47   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    42814  0.0  0.2 382304  4428 ?        Sl   15:47   0:00 /usr/local/apache2.4/bin/httpd -k start
root      42897  0.0  0.0 112664   972 pts/0    R+   15:48   0:00 grep --color=auto httpd
(查看进程,启动成功)
编译内容详解:
./configure \   //这里的反斜杠是脱义字符,加上它我们可以把一行命令写成多行
--prefix=/usr/local/apache2.4 \(指定apache路径)
--with-apr=/usr/local/apr \(指定apacehe apr)
--with-apr-util=/usr/local/apr-util \(指定apache apr-util)
--enable-so \ (此参数支持动态扩展模块,模块是一个为.so的文件)
--enable-mods-shared=most(加载大多数使用的模块)
[root@chy apache2.4]# ls bin/httpd 
bin/httpd (apache启动文件)
[root@chy apache2.4]# ls conf/
extra  httpd.conf  magic  mime.types  original
(apache配置文件)
[root@chy apache2.4]# ls htdocs/
index.html
(存放访问页)
[root@chy apache2.4]# ls logs/
access_log  error_log  httpd.pid
(apache日志存在的目录)
[root@chy apache2.4]# ls modules/
httpd.exp               mod_buffer.so               mod_lbmethod_heartbeat.so  mod_request.so
mod_access_compat.so    mod_cache_disk.so           mod_log_config.so          mod_rewrite.so
mod_actions.so          mod_cache.so                mod_log_debug.so           mod_sed.so
mod_alias.so            mod_cache_socache.so        mod_logio.so               mod_session_cookie.so
(此目录是存放模块的,模块分为静态模块动态模块,两者的区别为静态将模块编译进了主二进制文件里/bin/httpd里,扩展模块是一个.so的文件,此文件在[root@chy apache2.4]# ls /usr/local/apache2.4/modules/
里面。

apache 设置开机自启

[root@chy ~]# cp /usr/local/apache2.4/bin/apachectl /etc/init.d/apache2
(首先需要将apache的启动文档cp到/etc/inid.d的目录下,apache2的名称是自己取的,这个名称没有特定要求)
[root@chy ~]# vim /etc/init.d/apache2 
(然后编辑此内容)
# chkconfig: 35 20 80
#description: Apache2
(增加这两行内容,第一行后面的3个数字的意思分别是:在哪些运行级别启动apache(3,5);启动序号(S20);关闭序号(K80)。
3和5也就是说在第三启动级别和第五启动级别的时候会默认启动apache
20就是指系统起来的时候有很多的服务需要启动,而这个程序排在第二十位启动,以此类推
80就是指系统关闭的时候,这个服务顺序排在第80位关闭
注意:这2行缺一不可,#号不能省略,一定要有)
[root@chy ~]# chkconfig --add apache2 (增加到开机自启,这里的apache2要与之前的/etc/init.d/apache2的名称一致)
[root@chy ~]# netstat -antp |grep 80
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1980/sshd           
tcp6       0      0 :::80                   :::*                    LISTEN      2596/httpd          
tcp6       0      0 :::22                   :::*                    LISTEN      1980/sshd    
(测试可以看到启动了httpd)

6 安装php5总结

php 官网 http://www.php.net

[root@chy src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
(下载php包)
[root@chy src]# tar zxvf php-5.6.30.tar.gz 
(解压php包)
[root@chy src]# cd php-5.6.30
(进入到Php)
[root@chy php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mariadb --with-pdo-mysql=/usr/local/mariadb --with-mysqli=/usr/local/mariadb/bin/mariadb_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
(编译时出现了第一个问题,checking for RAND_egd... no
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's 
解决方法:[root@chy php-5.6.30]# yum install -y openssl-devel.x86_64   
第二个问题checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
解决方法:[root@chy php-5.6.30]# yum install -y bzip2-devel.x86_64 
第三个问题hecking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-vpx-dir=
configure: error: jpeglib.h not found.
解决方法:[root@chy php-5.6.30]# yum install -y libjpeg-devel
第四个问题:If configure fails try --with-xpm-dir=
configure: error: freetype-config not found.
解决方法:[root@chy php-5.6.30]# yum install -y freetype-devel.x86_64 
)
第五个问题:checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决方法:[root@chy php-5.6.30]# yum install epel-release
然后在安装:[root@chy php-5.6.30]# yum install libmcrypt
[root@chy php-5.6.30]# yum install libmcrypt-devel
(最后安装此包)
第六个问题:configure: error: Cannot find libmysqlclient_r under /usr/local/mariadb.
Note that the MySQL client library is not bundled anymore!
解决方法:
[root@chy php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc   --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
(编译的时候,不加--with-mysql=/usr/local/mariadb --with-pdo-mysql=/usr/local/mariadb --with-mysqli=/usr/local/mariadb/bin/mariadb_config (去掉这些配置)
[root@chy php-5.6.30]# make && make install  (make 与make install)
[root@chy php-5.6.30]# echo $?
0
(检测成功)
[root@chy php-5.6.30]# cp php.ini-production  /usr/local/php/etc/php.ini
(然后cp配置文件到 /etc/php.ini下 )
[root@chy php-5.6.30]# ls /usr/local/php/
bin  etc  include  lib  php
(php目录的文件)
[root@chy php-5.6.30]# ls /usr/local/php/bin/
pear  peardev  pecl  phar  phar.phar  php  php-cgi  php-config  phpize
(php的配置文件)
[root@chy php-5.6.30]# du -sh /usr/local/apache2.4/modules/libphp5.so 
36M /usr/local/apache2.4/modules/libphp5.so
(此文件是php与apache结合的文件)
[root@chy php-5.6.30]# /usr/local/php/bin/php -m
(查看php的模块)
[root@chy php-5.6.30]# cp php
php5.spec            php5.spec.in         php.gif              php.ini-development  php.ini-production
(php.ini-development  php.ini-production这两个文件的区别在于php.ini-development 它在测试环境中运行,php.ini-production线上的环境中运行)

7、apache7

[root@chy src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
[root@chy src]# tar jxf php-7.1.6.tar.bz2 
(解压包)
[root@chy src]# cd php-7.1.6
[root@chy php-7.1.6]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-mariadb=/usr/local/mariadb --with-mariadbi=/usr/local/mariadb/bin/mariadb_config  --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
然后后make && make install 

mysql与php的版本根据自己的需求看着装即可,我是因为要做实验就都安装了而已。
小提示:如上的操作是基于centos7操作系统。