LAMP架构(Ⅰ)——Apache、mysql、maridb、php

Stella981
• 阅读 528

LAMP架构(Ⅰ)

一、LAMP架构介绍

LAMP:Linux+Apache(httpd)+Maridb(Mysql)+PHP,常用来搭建动态网站或者服务器的开源软件。

习惯上,apache一般是指httpd,当然Apache还有很多的其他软件。Appache是最常用的web服务软件,而MYSQL是比较小型的数据库软件,MySQL存储用户名;密码和数据、图片之类的放在静态文件里。 这两个软件及PHP都可以安装到windows机器上。

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

Apache和PHP需要安装到同一台机器上,因为PHP是作为Apache的一个模块存在的,两个必须在一起

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

二、MySQL_MariaDB介绍

  • MySQL是一个关系型数据库,由mysql ab公司开发,mysql在2008年被sun公司收购(10亿刀),2009年sun公司被oracle公司收购(74亿刀)
  • MySQL官网https://www.mysql.com 最新版本5.7GA/8.0DMR
  • MySQL5.6变化比较大,5.7性能上有很大提升
  • Mariadb为MySQL的一个分支,官网https://mariadb.com/最新版本10.2
  • MariaDB主要由SkySQL公司(现更名为MariaDB公司)维护,SkySQL公司由MySQL原作者带领大部分原班人马创立.
  • Mariadb5.5版本对应MySQL的5.5,10.0对应MySQL5.6
  • Community 社区版本,Enterprise 企业版,GA(Generally Available)指通用版本,在生产环境中用的,DMR(Development Milestone Release)开发里程碑发布版,RC(Release Candidate)发行候选版本,Beta开放测试版本,Alpha内部测试版本

三、MySQL安装

3.1下载MySQL软件包

[root@ying01 ~]# uname -i
x86_64
[root@ying01 ~]# cd /usr/local/src/
[root@ying01 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
--2018-06-23 11:57:00--  http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
正在解析主机 mirrors.sohu.com (mirrors.sohu.com)... 221.236.12.140
正在连接 mirrors.sohu.com (mirrors.sohu.com)|221.236.12.140|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:316320366 (302M) [application/octet-stream]
正在保存至: “mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz”

3.2 初始化Mysql

把之前下载的包,解压

[root@ying01 src]# ls
httpd-2.4.33  httpd-2.4.33.tar.gz  mysql-5.6.36-linux-glibc2.5-x86_64  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
[root@ying01 src]# tar zxf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz           //解压包
[root@ying01 src]# ls /usr/local                                               //准备放到这个目录下
bin  etc  games  include  lib  lib64  libexec  sbin  share  src
[root@ying01 src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql      //移到usr/local下,且改为mysql名称
[root@ying01 src]# cd /usr/local/mysql/
[root@ying01 mysql]# ls                                                        
bin  COPYING  data  docs  include  lib  man  mysql-test  README  scripts  share  sql-bench  support-files
[root@ying01 mysql]# useradd mysql                                            //增加mysql用户

需要创建数据库目录,这里/data/已经存在,那就直接初始化;

[root@ying01 mysql]# ls /data/                        //data目录存在,就不用再创建
mariadb  mysql  wwwroot  yumdata            
[root@ying01 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
  • ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
    • --user=mysql 指定用户 ;
    • --datadir=/data/mysql 指定数据库目录;

因此执行此步前,必须创建用户,指定目录;

发现上面有错误,缺少Perl模块,缺少Dumper的支持;谷歌查询安装如下包

[root@ying01 mysql]# yum install -y perl-Data-Dumper
已加载插件:fastestmirror

再次初始化mysql

[root@ying01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

安装信息省略

[root@ying01 mysql]# echo $?           //检查上步是否正确,0位正确
0

3.3 配置文件

首先复制配置文件mysql的模板配置文件my-default.cnf,但是系统自带已经存在,我们只需要修改一下即可;

[root@ying01 mysql]# ls support-files/                                 //放置配置文件和启动脚本的目录
binary-configure  magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@ying01 mysql]# ls support-files/my-default.cnf                  //这个是mysql的模板配置文件
support-files/my-default.cnf
[root@ying01 mysql]# vim support-files/my-default.cnf                 
[root@ying01 mysql]# cp support-files/my-default.cnf /etc/my.cnf^C    //按道理要复制到其他地方,但是已经存在,不执行,看下一步;
[root@ying01 mysql]# ls /etc/my.cnf                                   //这里有自带的配置文件my.cnf
/etc/my.cnf
[root@ying01 mysql]# rpm -qf /etc/my.cnf                              //查看这个配置文件的来源
mariadb-libs-5.5.56-2.el7.x86_64                                      //发现来自mariadb
[root@ying01 mysql]# vim /etc/my.cnf

按下图更改配置文件my.cnf;

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

启动脚本

[root@ying01 mysql]# ls support-files/                                    //mysql的启动脚本也在此目录下
binary-configure  magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@ying01 mysql]# cp support-files/mysql.server /etc/init.d/mysqld     //把mysql.server复制到mysqld这个新目录
[root@ying01 mysql]# vim !$                                               //编辑此脚本文件
vim /etc/init.d/mysqld                                                                                                 

.....                          //下面为在编辑mysqld下

basedir=/usr/local/mysql       //指定mysql 的程序目录
datadir=/data/mysql            //指定日期目录

定义mysqld为755权限;

[root@ying01 mysql]# ls -l !$                                           //查看权限是不是755
ls -l /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10592 6月  24 08:16 /etc/init.d/mysqld     

增加到系统列表服务:chkconfig --add mysqld

[root@ying01 mysql]# chkconfig --add mysqld
[root@ying01 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:关        //系统服务开启
netconsole         0:关    1:关    2:关    3:关    4:关    5:关    6:关
network            0:关    1:关    2:关    3:关    4:关    5:关    6:关

3.4 启动与关闭服务

**常规启动 **

  • 启动:service mysqld start
    - /etc/init.d/mysqld start
  • 关闭:service mysqld stop
[root@ying01 mysql]# /etc/init.d/mysqld start^C
[root@ying01 mysql]# service mysqld start
Starting MySQL.Logging to '/data/mysql/ying01.err'.
 SUCCESS! 

用命令行启动

  • /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql/
    • --defaults-file=/etc/my.cnf 定义默认的配置文件
    • --user=mysql 定义用户
    • --datadir=/data/mysql/ 定义数据目录
[root@ying01 mysql]# service mysqld stop      //关闭服务
Shutting down MySQL.. SUCCESS! 
[root@ying01 mysql]# !ps                      //查看进程,已经关闭
ps aux |grep mysql
root      2932  0.0  0.0 112720   984 pts/0    S+   08:57   0:00 grep --color=auto mysql
[root@ying01 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql/ &
[1] 3018             //用命令行启动,需要加上&,把它放入后台
[root@ying01 mysql]# 180624 09:05:50 mysqld_safe Logging to '/data/mysql/ying01.err'.
180624 09:05:50 mysqld_safe Starting mysqld daemon with databases from /data/mysql
[root@ying01 mysql]# !ps                      //查看进程,已经开启
ps aux |grep mysql
root      3018  0.0  0.0 113304  1604 pts/0    S    09:05   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql/                  //此进程,为我们之前的命令行
mysql     3143  0.4 23.9 1300828 449568 pts/0  Sl   09:05   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/ying01.err --pid-file=/data/mysql/ying01.pid --socket=/tmp/mysql.sock
root      3175  0.0  0.0 112720   984 pts/0    R+   09:08   0:00 grep --color=auto mysql
[root@ying01 mysql]# !net                     //查看网络链接,有3306端口,说明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      690/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      928/master          
tcp6       0      0 :::22                   :::*                    LISTEN      690/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      928/master          
tcp6       0      0 :::3306                 :::*                    LISTEN      3143/mysqld         

用killall 杀进程,尽量不要用kill PID

[root@ying01 mysql]# killall mysqld       //杀死进程
[root@ying01 mysql]# 180624 09:13:20 mysqld_safe mysqld from pid file /data/mysql/ying01.pid ended
[root@ying01 mysql]# !ps
ps aux |grep mysql
root      3224  0.0  0.0 112720   984 pts/0    S+   09:14   0:00 grep --color=auto mysql
[1]+  完成                  /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql/
[root@ying01 mysql]# !ps                   //查看进程
ps aux |grep mysql
root      3226  0.0  0.0 112720   984 pts/0    S+   09:14   0:00 grep --color=auto mysql

mysql的引擎innodb和 myisam 先了解;

四、MariaDB安装

MariaDB和mysql同源,因此安装方式也是一模一样的;

下载MariaDB包

[root@ying01 ~]# cd /usr/local/src/
[root@ying01 src]# ls
httpd-2.4.33  httpd-2.4.33.tar.gz  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
[root@ying01 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
--2018-06-24 09:21:00--  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
正在解析主机 downloads.mariadb.com (downloads.mariadb.com)... 51.255.94.155, 2001:41d0:1004:249b::
正在连接 downloads.mariadb.com (downloads.mariadb.com)|51.255.94.155|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:541295045 (516M) [application/octet-stream]
正在保存至: “mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz”

100%[===================================================================================================================>] 541,295,045  723KB/s 用时 12m 12s

2018-06-24 09:33:16 (722 KB/s) - 已保存 “mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz” [541295045/541295045])

[root@ying01 src]# ls
httpd-2.4.33  httpd-2.4.33.tar.gz  mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
[root@ying01 src]# 

解压,并移到/usr/local/mariadb下

[root@ying01 src]# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz 
[root@ying01 src]# ls
httpd-2.4.33         mariadb-10.2.6-linux-glibc_214-x86_64         mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
httpd-2.4.33.tar.gz  mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
[root@ying01 src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb    //移到local下面
[root@ying01 src]# cd !$
cd /usr/local/mariadb
[root@ying01 mariadb]# ls
bin      COPYING.thirdparty  data         docs               include         lib  mysql-test  README-wsrep  share      support-files
COPYING  CREDITS             DESTINATION  EXCEPTIONS-CLIENT  INSTALL-BINARY  man  README.md   scripts       sql-bench

初始化,此处和mysql一样

[root@ying01 mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb

安装省略......

[root@ying01 mariadb]# echo $?          //检测上步正确
0

把mariadb的默认配置文件与启动脚本文件复制一份,并改如下名称;

[root@ying01 mariadb]# cp support-files/my-small.cnf  /usr/local/mariadb/my.cnf  //配置文件,路径和mysql不一样,为了区分
[root@ying01 mariadb]# cp support-files/mysql.server /etc/init.d/mariadb         //启动脚本文件

按下图编辑启动脚本文件: vim /etc/init.d/mariadb

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

启动mariadb服务:/etc/init.d/mariadb start

[root@ying01 mariadb]# ps aux |grep mysql                                   //查看有没有mysql进程,两者会相冲突
root      4324  0.0  0.0 112720   984 pts/0    S+   11:47   0:00 grep --color=auto mysql
[root@ying01 mariadb]# /etc/init.d/mariadb start                            //启动服务
Reloading systemd:                                         [  确定  ]
Starting mariadb (via systemctl):                          [  确定  ]
[root@ying01 mariadb]# ps aux |grep mariadb                                 //再次查看进程,确认启动
root      6210  0.0  0.0 115432  1744 ?        S    17:36   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/ying01.pid
mysql     6326  4.1  2.6 1583932 49724 ?       Sl   17:36   0:02 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mysql/ying01.err --pid-file=/data/mysql/ying01.pid --socket=/tmp/mysql.sock --port=3306
root      6383  0.0  0.0 112720   980 pts/1    R+   17:37   0:00 grep --color=auto mariadb
[root@ying01 mariadb]#  netstat -lntp                                      //查看网络链接,有3306端口
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      690/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      928/master          
tcp6       0      0 :::22                   :::*                    LISTEN      690/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      928/master          
tcp6       0      0 :::3306                 :::*                    LISTEN      6326/mysqld   

- 有个小问题:进程中:--datadir=/data/mysql 这里怎么还是mysql?而不是--datadir=/data/mariadb?

解决:那是因为刚才没有修改配置文件 /usr/local/mariadb/my.cnf;在那里面我们没有指定相应的目录;它会自动加载mysql的配置文件目录;

在配置文件按下图添加目录

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

先停止服务,在杀掉mysqld进程,再次开启mariadb服务

[root@ying01 ~]# /etc/init.d/mariadb stop
Stopping mariadb (via systemctl):                          [  确定  ]
[root@ying01 ~]# killall mysqld
[root@ying01 ~]# ps aux |grep mariadb
root      2368  0.0  0.0 112720   980 pts/0    S+   09:58   0:00 grep --color=auto mariadb
[root@ying01 ~]# /etc/init.d/mariadb start 
Starting mariadb (via systemctl):                          [  确定  ]
[root@ying01 ~]# ps aux |grep mariadb
root      2394  0.2  0.0 115432  1748 ?        S    09:59   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/ying01.pid
mysql     2513  3.8  2.9 1583832 55896 ?       Sl   09:59   0:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mariadb/ying01.err --pid-file=/data/mariadb/ying01.pid --socket=/tmp/mysql.sock --port=3306
root      2549  0.0  0.0 112720   980 pts/0    R+   09:59   0:00 grep --color=auto mariadb
[root@ying01 ~]# 

请看下图方框,看到比较清楚:

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

五、Apache安装

5.1 安装前准备工作

分别下载:2.4.33源码包,apr-1.6.3,apr-util-1.6.1;后面两个是通用函数库;

[root@ying01 ~]# cd /usr/local/src
[root@ying01 src]# wget  http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz
--2018-06-24 22:12:15--  http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz
正在解析主机 mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
正在连接 mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.8.193|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:9076901 (8.7M) [application/octet-stream]
正在保存至: “httpd-2.4.33.tar.gz.1”

100%[===================================================================================================================>] 9,076,901   3.37MB/s 用时 2.6s   

2018-06-24 22:12:18 (3.37 MB/s) - 已保存 “httpd-2.4.33.tar.gz.1” [9076901/9076901])

[root@ying01 src]# wget  http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
--2018-06-24 22:12:41--  http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
正在解析主机 mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
正在连接 mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.8.193|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1072661 (1.0M) [application/octet-stream]
正在保存至: “apr-1.6.3.tar.gz”

100%[===================================================================================================================>] 1,072,661   1.41MB/s 用时 0.7s   

2018-06-24 22:12:42 (1.41 MB/s) - 已保存 “apr-1.6.3.tar.gz” [1072661/1072661])

[root@ying01 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2 
--2018-06-24 22:13:10--  http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2
正在解析主机 mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
正在连接 mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.8.193|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:428595 (419K) [application/octet-stream]
正在保存至: “apr-util-1.6.1.tar.bz2”

100%[===================================================================================================================>] 428,595     1.01MB/s 用时 0.4s   

2018-06-24 22:13:11 (1.01 MB/s) - 已保存 “apr-util-1.6.1.tar.bz2” [428595/428595])

下载完后,查看相应的包

[root@ying01 src]# ls
apr-1.6.3.tar.gz        httpd-2.4.33         httpd-2.4.33.tar.gz.1                         mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
apr-util-1.6.1.tar.bz2  httpd-2.4.33.tar.gz  mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz

依次解压包

[root@ying01 src]# tar zxf httpd-2.4.33.tar.gz
[root@ying01 src]# tar zxf apr-1.6.3.tar.gz
[root@ying01 src]# tar jxf apr-util-1.6.1.tar.bz2            //注意此包解压方式与其他两个不同
[root@ying01 src]# ls
apr-1.6.3               httpd-2.4.33.tar.gz
apr-1.6.3.tar.gz        httpd-2.4.33.tar.gz.1
apr-util-1.6.1          mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
apr-util-1.6.1.tar.bz2  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
httpd-2.4.33

5.2 安装apr-1.6.3

定义到apr-1.6.3目录下,

[root@ying01 src]# cd apr-1.6.3/
[root@ying01 apr-1.6.3]# ls
apr-config.in  build-outputs.mk  helpers       misc           strings
apr.dep        CHANGES           include       mmap           support
apr.dsp        CMakeLists.txt    libapr.dep    network_io     tables
apr.dsw        config.layout     libapr.dsp    NOTICE         test
apr.mak        configure         libapr.mak    NWGNUmakefile  threadproc
apr.pc.in      configure.in      libapr.rc     passwd         time
apr.spec       docs              LICENSE       poll           tools
atomic         dso               locks         random         user
build          emacs-mode        Makefile.in   README
buildconf      encoding          Makefile.win  README.cmake
build.conf     file_io           memory        shmem

安装包: ./configure --prefix=/usr/local/apr

[root@ying01 apr-1.6.3]# ./configure --prefix=/usr/local/apr    

省略 配置检测.....

[root@ying01 apr-1.6.3]# echo $?                     //检查上步是否正确 0代表正确
0

执行 make && make install

[root@ying01 apr-1.6.3]# make && make install

5.3 安装apr-util-1.6.1

[root@ying01 apr-1.6.3]# ls /usr/local/apr/
bin  build-1  include  lib
[root@ying01 apr-1.6.3]# cd ../apr-util-1.6.1/
[root@ying01 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

执行 make && make install

[root@ying01 apr-util-1.6.1]# make && make install

此时发现错误,缺少expat.h包

xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录
 #include <expat.h>
                   ^
编译中断。
make[1]: *** [xml/apr_xml.lo] 错误 1
make[1]: 离开目录“/usr/local/src/apr-util-1.6.1”
make: *** [all-recursive] 错误 1
[root@ying01 apr-util-1.6.1]# 

执行 yum install -y expat*

[root@ying01 apr-util-1.6.1]# yum install -y expat*
已加载插件:fastestmirror
base           

再次 make && make install

[root@ying01 apr-util-1.6.1]# make && make install


See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config
[root@ying01 apr-util-1.6.1]# echo $?
0
[root@ying01 apr-util-1.6.1]# ls /usr/local/apr-util/  
bin  include  lib

5.4 安装apache2.4

先定义到 httpd-2.4.33/目录下

[root@ying01 apr-util-1.6.1]# cd ..
[root@ying01 src]# ls
apr-1.6.3         apr-util-1.6.1          httpd-2.4.33         httpd-2.4.33.tar.gz.1                         mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
apr-1.6.3.tar.gz  apr-util-1.6.1.tar.bz2  httpd-2.4.33.tar.gz  mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
[root@ying01 src]# cd httpd-2.4.33/

执行安装

[root@ying01 httpd-2.4.33]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most

省略....

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
[root@ying01 httpd-2.4.33]# echo $?          //报错
1

此处报错,按提示,我们查找安装包:yum list |grep pcre

[root@ying01 httpd-2.4.33]# yum list |grep pcre
pcre.x86_64                               8.32-17.el7                  @anaconda
ghc-pcre-light.x86_64                     0.4-13.el7                   epel     
ghc-pcre-light-devel.x86_64               0.4-13.el7                   epel     
mingw32-pcre.noarch                       8.38-1.el7                   epel     
mingw32-pcre-static.noarch                8.38-1.el7                   epel     
mingw64-pcre.noarch                       8.38-1.el7                   epel     
mingw64-pcre-static.noarch                8.38-1.el7                   epel     
pcre.i686                                 8.32-17.el7                  base     
pcre-devel.i686                           8.32-17.el7                  base     
pcre-devel.x86_64                         8.32-17.el7                  base     
pcre-static.i686                          8.32-17.el7                  base     
pcre-static.x86_64                        8.32-17.el7                  base     
pcre-tools.x86_64                         8.32-17.el7                  base     
pcre2.i686                                10.23-2.el7                  base     
pcre2.x86_64                              10.23-2.el7                  base     
pcre2-devel.i686                          10.23-2.el7                  base     
pcre2-devel.x86_64                        10.23-2.el7                  base     
pcre2-static.i686                         10.23-2.el7                  base     
pcre2-static.x86_64                       10.23-2.el7                  base     
pcre2-tools.x86_64                        10.23-2.el7                  base     
pcre2-utf16.i686                          10.23-2.el7                  base     
pcre2-utf16.x86_64                        10.23-2.el7                  base     
pcre2-utf32.i686                          10.23-2.el7                  base     
pcre2-utf32.x86_64                        10.23-2.el7                  base     

安装 yum install -y pcre-devel

[root@ying01 httpd-2.4.33]# yum install -y pcre-devel
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirror01.idc.hinet.net
 * extras: mirrors.aliyun.com
 * updates: centos.ustc.edu.cn

再次配置

[root@ying01 httpd-2.4.33]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most


省略.......

    Server Version: 2.4.33
    Install prefix: /usr/local/apache2.4
    C compiler:     gcc -std=gnu99
    CFLAGS:          -g -O2 -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E

[root@ying01 httpd-2.4.33]# echo $?        //配置成功
0

执行make

[root@ying01 httpd-2.4.33]# make

执行make install

[root@ying01 httpd-2.4.33]# make install

安装成功,查看apache2.4目录下的目录

[root@ying01 httpd-2.4.33]# cd /usr/local/apache2.4/
[root@ying01 apache2.4]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules
[root@ying01 apache2.4]# ls bin/httpd 
bin/httpd
[root@ying01 apache2.4]# ls -l bin/httpd 
-rwxr-xr-x 1 root root 2348432 6月  25 11:55 bin/httpd
[root@ying01 apache2.4]# du -sh !$
du -sh bin/httpd
2.3M    bin/httpd
[root@ying01 apache2.4]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules
[root@ying01 apache2.4]# ls conf/
extra  httpd.conf  magic  mime.types  original
[root@ying01 apache2.4]# ls htdocs/
index.html
[root@ying01 apache2.4]# ls logs/
[root@ying01 apache2.4]# ls man
man1  man8
[root@ying01 apache2.4]# ls modules/                        //默认模板
httpd.exp             mod_authz_dbd.so        mod_deflate.so              mod_log_config.so      mod_proxy_scgi.so      mod_socache_dbm.so
mod_access_compat.so  mod_authz_dbm.so        mod_dir.so                  mod_log_debug.so       mod_proxy.so           mod_socache_memcache.so
mod_actions.so        mod_authz_groupfile.so  mod_dumpio.so               mod_logio.so           mod_proxy_uwsgi.so     mod_socache_shmcb.so
mod_alias.so          mod_authz_host.so       mod_env.so                  mod_macro.so           mod_proxy_wstunnel.so  mod_speling.so
mod_allowmethods.so   mod_authz_owner.so      mod_expires.so              mod_mime.so            mod_ratelimit.so       mod_ssl.so
mod_auth_basic.so     mod_authz_user.so       mod_ext_filter.so           mod_negotiation.so     mod_remoteip.so        mod_status.so
mod_auth_digest.so    mod_autoindex.so        mod_file_cache.so           mod_proxy_ajp.so       mod_reqtimeout.so      mod_substitute.so
mod_auth_form.so      mod_buffer.so           mod_filter.so               mod_proxy_balancer.so  mod_request.so         mod_unique_id.so
mod_authn_anon.so     mod_cache_disk.so       mod_headers.so              mod_proxy_connect.so   mod_rewrite.so         mod_unixd.so
mod_authn_core.so     mod_cache.so            mod_include.so              mod_proxy_express.so   mod_sed.so             mod_userdir.so
mod_authn_dbd.so      mod_cache_socache.so    mod_info.so                 mod_proxy_fcgi.so      mod_session_cookie.so  mod_version.so
mod_authn_dbm.so      mod_cgid.so             mod_lbmethod_bybusyness.so  mod_proxy_fdpass.so    mod_session_dbd.so     mod_vhost_alias.so
mod_authn_file.so     mod_dav_fs.so           mod_lbmethod_byrequests.so  mod_proxy_ftp.so       mod_session.so         mod_watchdog.so
mod_authn_socache.so  mod_dav.so              mod_lbmethod_bytraffic.so   mod_proxy_hcheck.so    mod_setenvif.so
mod_authz_core.so     mod_dbd.so              mod_lbmethod_heartbeat.so   mod_proxy_http.so      mod_slotmem_shm.so

在/apache2.4/bin/目录下

root@ying01 apache2.4]# ls /usr/local/apache2.4/bin/
ab         apxs      dbmmanage  envvars-std  htcacheclean  htdigest  httpd      logresolve
apachectl  checkgid  envvars    fcgistarter  htdbm         htpasswd  httxt2dbm  rotatelogs
[root@ying01 apache2.4]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::16dc:89c:b761:e115. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_event_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)

5.5 启动httpd服务

启动httpd服务:/usr/local/apache2.4/bin/apachectl start

[root@ying01 apache2.4]# /usr/local/apache2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::16dc:89c:b761:e115. Set the 'ServerName' directive globally to suppress this message

查看有关httpd的进程

[root@ying01 apache2.4]# ps aux |grep httpd
root     59382  0.0  0.1  95580  2524 ?        Ss   12:42   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon   59383  0.0  0.2 382408  4432 ?        Sl   12:42   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon   59384  0.0  0.2 382408  4432 ?        Sl   12:42   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon   59385  0.1  0.2 382408  4428 ?        Sl   12:42   0:00 /usr/local/apache2.4/bin/httpd -k start
root     59484  0.0  0.0 112720   984 pts/0    R+   12:43   0:00 grep --color=auto httpd
[root@ying01 apache2.4]# netstat -lntp               //80端口就是httpd
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      664/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      800/master          
tcp6       0      0 :::80                   :::*                    LISTEN      59382/httpd         
tcp6       0      0 :::22                   :::*                    LISTEN      664/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      800/mast

configure的命令格式也可以这样书写; \是转义字符,后面可以换行添加多行命令;

[root@ying01 httpd-2.4.33]# ./configure \
> --prefix=/usr/local/apache2.4 \
> --with-apr=/usr/local/apr \
> --with-apr-util=/usr/local/apr-util \
> --enable-so \
> --enable-mods-shared=most

六、安装PHP5

虽然目前最新版本的PHP为PHP7,但是还有批量的PHP5在使用,而且一些论坛软件不支持PHP7,因此也需要掌握PHP5和PHP7;

在/usr/local/src/目录下,下载源码

[root@ying01 apache2.4]# cd /usr/local/src/
[root@ying01 src]# wget http://cn2.php.net/distributions/php-5.6.32.tar.bz2

解压 php-5.6.32.tar.bz2

[root@ying01 src]# ls
apr-1.6.3         apr-util-1.6.1.tar.bz2  httpd-2.4.33.tar.gz.1                         php-5.6.32.tar.bz2
apr-1.6.3.tar.gz  httpd-2.4.33            mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
apr-util-1.6.1    httpd-2.4.33.tar.gz     mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
[root@ying01 src]# du -sh php-5.6.32.tar.bz2 
15M    php-5.6.32.tar.bz2
[root@ying01 src]# tar -xjf php-5.6.32.tar.bz2 

进入php-5.6.32 目录下,进行配置

[root@ying01 src]# cd php-5.6.32/
[root@ying01 php-5.6.32]# ./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/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_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
  • –prefix=/usr/local/php 指定的安装目录;
  • –with-apxs2=/usr/local/apache2/bin/apxs 该文件是Apache的一个工具,可以将扩展模块添加到Apache的module文件;
  • –with-config-file-path=/usr/local/php/etc 指定配置文件所在路径;
  • –with-mysql=/usr/local/mysql 指定mysql的路径;
  • –with-mysqli=/usr/local/mysql/bin/mysql_config
  • –with-pdo-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config 上面两项参数是指定相关mysql库
  • –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 以上参数是指定PHP相关的一些模块(通用)。

执行配置后,发现错误:error: jpeglib.h not found.

checking for T1lib support... no
checking whether to enable truetype string function in GD... yes
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-vpx-dir=<DIR>
configure: error: jpeglib.h not found.
[root@ying01 php-5.6.32]# echo $?
1

安装 yum install -y libjpeg-devel;安装完后继续配置

[root@ying01 php-5.6.32]# yum install -y libjpeg-devel

有出现错误:error: png.h not found.

checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.
[root@ying01 php-5.6.32]# 

继续按提示安装包;安装完后继续配置

[root@ying01 php-5.6.32]# yum install -y libpng-devel

错误提示:缺少包

If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.
[root@ying01 php-5.6.32]# 

继续按提示安装包;安装完后继续配置

[root@ying01 php-5.6.32]# yum install -y freetype-devel

又有错误

configure: error: mcrypt.h not found. Please reinstall libmcrypt.
[root@ying01 php-5.6.32]# 

若没有安装扩展源,需要安装

[root@ying01 php-5.6.32]# yum install epel-release

已经安装 则,继续安装; 安装完后继续配置

[root@ying01 php-5.6.32]# yum install libmcrypt-devel

终于看到曙光了,出现下面的提示,说明配置成功;

省略......

Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
[root@ying01 php-5.6.32]# 
[root@ying01 php-5.6.32]# echo $?                        //检测是否正确
0

然后安装 make 和make install

[root@ying01 php-5.6.32]# make

省略.....
Build complete.
Don't forget to run 'make test'.

[root@ying01 php-5.6.32]# make install
  • 查看php5下有哪些模块:/usr/local/php/bin/php -m

    [root@ying01 php-5.6.32]# ls /usr/local/php/ bin etc include lib php [root@ying01 php-5.6.32]# ls /usr/local/php/bin/ pear peardev pecl phar phar.phar php php-cgi php-config phpize [root@ying01 php-5.6.32]# du -sh !$ du -sh /usr/local/php/bin/ 71M /usr/local/php/bin/ [root@ying01 php-5.6.32]# du -sh /usr/local/apache2.4/modules/libphp5.so 36M /usr/local/apache2.4/modules/libphp5.so [root@ying01 php-5.6.32]# /usr/local/php/bin/php -m //查看模块 [PHP Modules] bz2 Core ctype date dom ereg exif fileinfo filter gd hash iconv json libxml mbstring mcrypt mysql mysqli openssl pcre PDO pdo_mysql pdo_sqlite Phar posix Reflection session SimpleXML soap sockets SPL sqlite3 standard tokenizer xml xmlreader xmlwriter zlib

    [Zend Modules]

  • 前面已经讲过php作为httpd的模块存在;因此php 不需要启动;

我们查看httpd的模块;此时能看到 php5_module (shared)

[root@ying01 php-5.6.32]# /usr/local/apache2.4/bin/httpd -M |tail -5
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::16dc:89c:b761:e115. Set the 'ServerName' directive globally to suppress this message
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)
 php5_module (shared)                      //作为httpd的模块

查看模块libphp5.so文件的权限

[root@ying01 php-5.6.32]# ls -l /usr/local/apache2.4/modules/libphp5.so 
-rwxr-xr-x 1 root root 37743776 6月  25 13:56 /usr/local/apache2.4/modules/libphp5.so
[root@ying01 php-5.6.32]# vim /usr/local/apache2.4/conf/httpd.conf      //进入httpd的配置文件

此时为配置文件里面的模块,增减#可以随用随取

LoadModule dir_module modules/mod_dir.so
#LoadModule actions_module modules/mod_actions.so
#LoadModule speling_module modules/mod_speling.so
#LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module        modules/libphp5.so               //能够看到libphp5.so  
  • php的参考配置文件
  • php.ini-production 生产环境用
  • php.ini-development 开发环境和测试环境下用
[root@ying01 php-5.6.32]# /usr/local/php/bin/php -i |less
[root@ying01 php-5.6.32]# ls /usr/local/php/etc
pear.conf
[root@ying01 php-5.6.32]# cp php.ini-production  /usr/local/php/etc/php.ini   //参考文件;production适合生产环境;de
[root@ying01 php-5.6.32]# /usr/local/php/bin/php -i |less

此时我们能看到已经加载到此配置文件

Virtual Directory Support => enabled
Configuration File (php.ini) Path => /usr/local/php/etc   
Loaded Configuration File => /usr/local/php/etc/php.ini         //此时已经加载
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)

七、PHP7的安装

在/usr/local/src/目录下,下载php7源码

[root@ying01 src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

解压:tar jxf php-7.1.6.tar.bz2

[root@ying01 src]# tar jxf php-7.1.6.tar.bz2

进入php-7.1.6 目录下,进行配置

[root@ying01 src]# cd php-7.1.6/
[root@ying01 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-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_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编译

[root@ying01 php-5.6.32]# make

省略.....


Build complete.
Don't forget to run 'make test'.

make install安装

[root@ying01 php-7.1.6]# make install

查看php7的模块,和php5 一样

[root@ying01 php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so 
/usr/local/apache2.4/modules/libphp7.so
[root@ying01 php-7.1.6]# du -sh !$
du -sh /usr/local/apache2.4/modules/libphp7.so
37M    /usr/local/apache2.4/modules/libphp7.so
[root@ying01 php-7.1.6]# /usr/local/php7/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

查看httpd的模块;此时能看到 php5_module (shared)和 php7_module (shared);再次说明php是作为httpd的模块存在;

[root@ying01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::16dc:89c:b761:e115. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_event_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)
 php5_module (shared)
 php7_module (shared)

八、 Apache和PHP结合

Apache(httpd)的主配置文件:/usr/local/apache2.4/conf/httpd.conf

在启动httpd服务的时候,总会有以下警告;通过更改配置文件,可以取消;

[root@ying01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::16dc:89c:b761:e115. Set the 'ServerName' directive globally to suppress this message                //提示,警告的意思
httpd (pid 59382) already running
[root@ying01 php-7.1.6]# ps aux |grep httpd                          //查看httpd进程
root     56216  0.0  0.0 112720   984 pts/0    S+   17:06   0:00 grep --color=auto httpd
root     59382  0.0  0.1  95580  2524 ?        Ss   12:42   0:01 /usr/local/apache2.4/bin/httpd -k start
daemon   59383  0.0  0.2 382408  4432 ?        Sl   12:42   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon   59384  0.0  0.2 382408  4432 ?        Sl   12:42   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon   59385  0.0  0.2 382408  4428 ?        Sl   12:42   0:00 /usr/local/apache2.4/bin/httpd -k start
[root@ying01 php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf

按下图更改配置文件:/usr/local/apache2.4/conf/httpd.conf

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

这个也需要不要让php7加载,因为不能同时调用两个php

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

关闭服务,再次启动,就没有加载警告信息

[root@ying01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl stop
[root@ying01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl start

8.1 修改denied

此时我们无法网页192.168.112.136

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

此时我们开始排查问题:

第一步:在windows上ping 192.168.112.168 是否通畅;

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

第二步:IP通畅,那么我们检查端口,先在window启用telnet,只选择客户端,服务端危险;

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

第三步:开始检查端口;

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

第四步:iptables -nvL查看无端口,指定80端口

[root@ying01 php-7.1.6]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT 

第五步:再次用telnet测试端口;

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

第六步:此时我们再浏览器再访问192.168.112.168

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

  • 探索能够访问的原理

此时能够显示,那是因为在配置文件里面

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

把 Require all granted 改为Require all denied;保存配置文件

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

此时我们为了安全起见,不重启配置文件;用以下命令检测配置、加载配置验证;

[root@ying01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -t          //检查更改配置是否语法错误
Syntax OK
[root@ying01 php-7.1.6]# /usr/local/apache2.4//bin/apachectl graceful   //加载配置成功

此时我们再浏览器再访问192.168.112.168,显示:禁止访问

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

在 配置文件httpd.conf 还需要把此处更改为granted;否则会出现403状态码,一般为200;

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

8.2 解析php

检测配置,加载配置

[root@ying01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@ying01 php-7.1.6]# /usr/local/apache2.4//bin/apachectl graceful

在配置文件里面增加如下内容,意思解析php

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

添加如下内容,就会直接跳转到主页

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

新建一个1.php

[root@ying01 php-7.1.6]# vim /usr/local/apache2.4/htdocs/1.php

以下为内容

<?php
   phpinfo();   //打印php的所有函数
?>

此时我们再浏览器中,看是否解析PHP (在配置中增加内容,不需要重启php)

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

php能够支持解析;那么把它加上#,代表不加载

#AddType application/x-httpd-php .php

检查,加载配置文件httpd.conf

[root@ying01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@ying01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl graceful

此时打开浏览器,我们发现不解析php,只是源代码;

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

问题总结:

如果浏览器不能解析php,那么需要从以下几点来入手:

第一步:查看有没有加载php模块;

[root@ying01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -M |tail -5
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)
 php5_module (shared)
 

第二步:查看没有php模块文件

[root@ying01 php-7.1.6]# ls /usr/local/apache2.4/modules/libphp5.so 
/usr/local/apache2.4/modules/libphp5.so
[root@ying01 php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf

第三步:前面两项有,在httpd.con的配置文件中,有加载模块;

LoadModule php5_module        modules/libphp5.so

第四步:之前都有,在httpd.con的配置文件中,有没有此项;

    AddType application/x-httpd-php .php

第五步:在httpd.con的配置文件中,下面加 index.php

<IfModule dir_module>
    DirectoryIndex index.html index.php       //能够跳转到索引页
</IfModule>

8.3 加载php7

因为php7与php5不能同时加载,此时需要在httpd.con的配置文件中,把php7模块加载,把php5注释掉;

#LoadModule php5_module        modules/libphp5.so         
LoadModule php7_module        modules/libphp7.so   

检查,加载配置文件httpd.conf

[root@ying01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@ying01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl graceful

此时再次通过浏览器,查看

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

九、Apache默认虚拟主机

一台服务器可以访问多个网站,每个网站都是一个虚拟主机 概念:域名(主机名)、DNS、解析域名、hosts 任何一个域名解析到这台机器,都可以访问的虚拟主机就是默认虚拟主机

9.1 windows下host用法

第一步:按下图找到host文件

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

第二步:按下图添加域名;

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

第三步:ping 设置的域名是否通畅;

Microsoft Windows [版本 10.0.17134.112]
(c) 2018 Microsoft Corporation。保留所有权利。

C:\Users\zqsgq>www.abc.com
'www.abc.com' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

C:\Users\zqsgq>ping www.abc.com

正在 Ping www.abc.com [192.168.112.136] 具有 32 字节的数据:
来自 192.168.112.136 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.112.136 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.112.136 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.112.136 的回复: 字节=32 时间<1ms TTL=64

192.168.112.136 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms

C:\Users\zqsgq>ping test.com

正在 Ping www.abc.com [192.168.112.136] 具有 32 字节的数据:
来自 192.168.112.136 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.112.136 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.112.136 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.112.136 的回复: 字节=32 时间<1ms TTL=64

192.168.112.136 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms

C:\Users\zqsgq>ping ying.com

正在 Ping www.abc.com [192.168.112.136] 具有 32 字节的数据:
来自 192.168.112.136 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.112.136 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.112.136 的回复: 字节=32 时间=1ms TTL=64
来自 192.168.112.136 的回复: 字节=32 时间<1ms TTL=64

192.168.112.136 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 1ms,平均 = 0ms

C:\Users\zqsgq>

第四步:在浏览器访问域名

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

LAMP架构(Ⅰ)——Apache、mysql、maridb、php

9.2 linux下配置虚拟主机

第一步:编辑配置文件httpd.conf,去掉以下的#号,使虚拟主机的配置文件生效

# Virtual hosts
Include conf/extra/httpd-vhosts.conf    //去掉#号    加载虚拟主机的配置文件

第二步:进入虚拟主机配置文件中;

以下内容需要更改

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com                            //定义管理员的邮箱
    DocumentRoot "/usr/local/aprche2.4/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/usr/local/aprche2.4/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>

更改为以下内容:

<VirtualHost *:80>
    DocumentRoot "/data/wwwroot/abc.com"                //定义网站的根目录
    ServerName abc.com                                  //定义域名,只能写1个
    ServerAlias www.abc.com www.123.com                 //定义别名,可以写多个
    ErrorLog "logs/abc.com-error_log"                   //定义错误日志
    CustomLog "logs/abc.com-access_log" common          //定义访问日志
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/data/wwwroot/111.com"
    ServerName 111.com
    ServerAlias www.example.com
    ErrorLog "logs/111.com-error_log"
    CustomLog "logs/111.com-access_log" common
</VirtualHost>

第三步: 创建和虚拟主机对应的站点根目录,以及新建相应index.php

[root@ying01 php-7.1.6]# mkdir /data/wwwroot/
[root@ying01 php-7.1.6]# mkdir /data/wwwroot/abc.com
[root@ying01 php-7.1.6]# mkdir /data/wwwroot/111.com
[root@ying01 php-7.1.6]# vim /data/wwwroot/abc.com/index.php
[root@ying01 php-7.1.6]# vim /data/wwwroot/111.com/index.php
[root@ying01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -t            //需要检查配置语法
[root@ying01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl graceful      //需要加载

第四步:ping 设置的www.abc.com,此时明显是外网的域名;

[root@ying01 wwwroot]# ping www.abc.com
PING abc.com (199.181.132.250) 56(84) bytes of data.
64 bytes from 199.181.132.250 (199.181.132.250): icmp_seq=1 ttl=128 time=176 ms
64 bytes from 199.181.132.250 (199.181.132.250): icmp_seq=2 ttl=128 time=160 ms
^C
--- abc.com ping statistics ---
3 packets transmitted, 2 received, 33% packet loss, time 8490ms
rtt min/avg/max/mdev = 160.519/168.407/176.296/7.899 ms

第五步:用curl -x192.168.112.136:80 abc.com 来测试

[root@ying01 wwwroot]# curl -x192.168.112.136:80 abc.com
abc.com[root@ying01 wwwroot]# curl -x192.168.112.136:80 www.abc.com       //指向abc.com
abc.com[root@ying01 wwwroot]# curl -x192.168.112.136:80 www.qq.com        //qq都指向abc.com
abc.com[root@ying01 wwwroot]# curl -x192.168.112.136:80 www.126.com
abc.com[root@ying01 wwwroot]# curl -x192.168.112.136:80 www.example.com   //这个别名,指向111.com
111.com[root@ying01 wwwroot]# curl -x192.168.112.136:80 www.111.com       //www.111.com因为不是设置的所有指向abc.com
abc.com[root@ying01 wwwroot]# curl -x192.168.112.136:80 111.com
点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Easter79 Easter79
2年前
Twitter的分布式自增ID算法snowflake (Java版)
概述分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移
Wesley13 Wesley13
2年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
2年前
PHP创建多级树型结构
<!lang:php<?php$areaarray(array('id'1,'pid'0,'name''中国'),array('id'5,'pid'0,'name''美国'),array('id'2,'pid'1,'name''吉林'),array('id'4,'pid'2,'n
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
为什么mysql不推荐使用雪花ID作为主键
作者:毛辰飞背景在mysql中设计表的时候,mysql官方推荐不要使用uuid或者不连续不重复的雪花id(long形且唯一),而是推荐连续自增的主键id,官方的推荐是auto_increment,那么为什么不建议采用uuid,使用uuid究
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这