LAMP架构(一)

LAMP架构介绍

Linux:操作系统

Apache(httpd):提供web服务的软件

MySQL:存储数据的,不能存图片和文件什么的,

PHP:脚本语言,和shell类似但更复杂,做网址为主

httpd、MySQL和PHP可以在一台机器,也可以分开(httpd和PHP一定要在一起)

MySQL/MariaDB介绍

Mariadb是MySQL的一个分支,官网https://mariadb.com/最新版本10.2

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主要由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安装

MySQL的几个常用安装包:rpm、源码、二进制免编译

二进制免编译:在Linux系统上做了编译,再把编译好的文件打包压缩发布,不用配置和编译,直接拿来用;和rpm包类似,但优于rpm包可以自定义安装目录,rpm只能固定安装目录。

追求极致性能的话,最好自己编译。

1、下载mysql的包,下到之前约定的目录cd /usr/local/src/,软件包区分平台(64位和32位)

  [root@zyshanlinux-001 ~]# cd /usr/local/src
  [root@zyshanlinux-001 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
  --2018-06-25 22:01:08--  http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-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
  长度:314581668 (300M) [application/octet-stream]
  正在保存至: “mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz”
  ​
  100%[============================================>] 314,581,668  375KB/s 用时 17m 30s
  ​
  2018-06-25 22:18:38 (293 KB/s) - 已保存 “mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz” [314581668/314581668])

2、下载后解压

  [root@zyshanlinux-001 src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
  mysql-5.6.35-linux-glibc2.5-x86_64/README
  mysql-5.6.35-linux-glibc2.5-x86_64/data/test/db.opt

3、解压后把mysql包改名放到/usr/local/目录下

  [root@zyshanlinux-001 src]# ls /usr/local/mysql
  ls: 无法访问/usr/local/mysql: 没有那个文件或目录
  [root@zyshanlinux-001 src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
  [root@zyshanlinux-001 src]# ls /usr/local/mysql
  bin      data  include  man         README   share      support-files
  COPYING  docs  lib      mysql-test  scripts  sql-bench

4、并跳转到改名字后的目录下

  [root@zyshanlinux-001 src]# cd !$
  cd /usr/local/mysql
  [root@zyshanlinux-001 mysql]# ls
  bin      data  include  man         README   share      support-files
  COPYING  docs  lib      mysql-test  scripts  sql-bench

5、创建mysql用户,新建data目录

  [root@zyshanlinux-001 mysql]# useradd mysql
  [root@zyshanlinux-001 mysql]# mkdir /data/
  [root@zyshanlinux-001 mysql]# ls /data/
  [root@zyshanlinux-001 mysql]# 

6、指定用户为mysql,指定datadir(mysql数据存放目录),它会在目录data中创建mysql目录,但必须先有data目录(即父目录),整个过程是初始化

  [root@zyshanlinux-001 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

告警:少了模块,模块叫Dumper

解决思路:少了包或者模块,去安装包,不知道名字就去模糊搜索

  [root@zyshanlinux-001 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     
  [root@zyshanlinux-001 mysql]# 

搜索到的结果有4个包,可以考虑逐个尝试有可能解决,但我知道是第一个。直接安装,再执行告警前的命令

  [root@zyshanlinux-001 mysql]# yum install -y perl-Data-Dumper
  [root@zyshanlinux-001 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

怎么知道执行的过程是否对?

第一种方法:执行反馈中有2个OK

  OK
  ​
  Filling help tables...2018-06-25 23:03:58 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
  2018-06-25 23:03:58 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
  2018-06-25 23:03:58 0 [Note] ./bin/mysqld (mysqld 5.6.35) starting as process 2965 ...
  2018-06-25 23:03:58 2965 [Note] InnoDB: Using atomics to ref count buffer pool pages
  2018-06-25 23:03:58 2965 [Note] InnoDB: The InnoDB memory heap is disabled
  2018-06-25 23:03:58 2965 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
  2018-06-25 23:03:58 2965 [Note] InnoDB: Memory barrier is not used
  2018-06-25 23:03:58 2965 [Note] InnoDB: Compressed tables use zlib 1.2.3
  2018-06-25 23:03:58 2965 [Note] InnoDB: Using Linux native AIO
  2018-06-25 23:03:58 2965 [Note] InnoDB: Using CPU crc32 instructions
  2018-06-25 23:03:58 2965 [Note] InnoDB: Initializing buffer pool, size = 128.0M
  2018-06-25 23:03:58 2965 [Note] InnoDB: Completed initialization of buffer pool
  2018-06-25 23:03:58 2965 [Note] InnoDB: Highest supported file format is Barracuda.
  2018-06-25 23:03:58 2965 [Note] InnoDB: 128 rollback segment(s) are active.
  2018-06-25 23:03:58 2965 [Note] InnoDB: Waiting for purge to start
  2018-06-25 23:03:58 2965 [Note] InnoDB: 5.6.35 started; log sequence number 1625977
  2018-06-25 23:03:58 2965 [Note] Binlog end
  2018-06-25 23:03:58 2965 [Note] InnoDB: FTS optimize thread exiting.
  2018-06-25 23:03:58 2965 [Note] InnoDB: Starting shutdown...
  2018-06-25 23:04:00 2965 [Note] InnoDB: Shutdown completed; log sequence number 1625987
  OK

第二种方法:echo $?反馈是0,要记住echo $?是检验上一条命令是否对的,所以在执行完上条命令后不要执行任何其他命令,马上执行echo $?

  [root@zyshanlinux-001 mysql]# echo $?
  [root@zyshanlinux-001 mysql]# 0

7、拷贝配置文件和启动脚本

  [root@zyshanlinux-001 mysql]# ls support-files/my-default.cnf
  support-files/my-default.cnf                  ##配置文件路径##

可以用命令cp support-files/my-default.cnf /etc/my.cnf

拷贝配置文件到/etc/my.cnf

  [root@zyshanlinux-001 mysql]# ls /etc/my.cnf  ##其实系统该目录下已经有了my.cnf的##
  /etc/my.cnf
  [root@zyshanlinux-001 mysql]# rpm -qf /etc/my.cnf  ##查看是哪个rpm包安装的,是mariadb##
  mariadb-libs-5.5.56-2.el7.x86_64

也可以选用系统原有的,但需要该一下my.cnf文件内容,把下面

  [root@zyshanlinux-001 mysql]# vi /etc/my.cnf
  [root@zyshanlinux-001 mysql]# vim !$
  vim /etc/my.cnf
  ​
  [mysqld]
  datadir=/var/lib/mysql
  socket=/var/lib/mysql/mysql.sock
  # Disabling symbolic-links is recommended to prevent assorted security risks
  symbolic-links=0
  # Settings user and group are ignored when systemd is used.
  # If you need to run mysqld under a different user or group,
  # customize your systemd unit file for mariadb according to the
  # instructions in http://fedoraproject.org/wiki/Systemd
  ​
  [mysqld_safe]
  log-error=/var/log/mariadb/mariadb.log
  pid-file=/var/run/mariadb/mariadb.pid
  ​
  #
  # include all files from the config directory
  #
  !includedir /etc/my.cnf.d

改为

  [mysqld]
  datadir=/data/mysql  ##改路径##
  socket=/tmp/mysql.sock  ##改路径##
  # Disabling symbolic-links is recommended to prevent assorted security risks
  symbolic-links=0
  # Settings user and group are ignored when systemd is used.
  # If you need to run mysqld under a different user or group,
  # customize your systemd unit file for mariadb according to the
  # instructions in http://fedoraproject.org/wiki/Systemd
  ​
  [mysqld_safe]
  #log-error=/var/log/mariadb/mariadb.log  ##注释掉##
  #pid-file=/var/run/mariadb/mariadb.pid  ##注释掉##
  ​
  #
  # include all files from the config directory
  #
  #!includedir /etc/my.cnf.d  ##注释掉##

把启动脚本放到/etc/init.d/里面去

  [root@zyshanlinux-001 mysql]# ls /etc/init.d/mysqld
  ls: 无法访问/etc/init.d/mysqld: 没有那个文件或目录
  [root@zyshanlinux-001 mysql]# ls /etc/init.d/
  123  functions  netconsole  network  README
  [root@zyshanlinux-001 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
  [root@zyshanlinux-001 mysql]# ls /etc/init.d/mysqld
  /etc/init.d/mysqld 

还要做一下编辑

  [root@zyshanlinux-001 mysql]# vi !$
  vi /etc/init.d/mysqld
  ##在编辑中把下面的路径加上##
  basedir=/usr/local/mysql  ##指定mysql的程序目录
  datadir=/data/mysql  ##定义在data目录下

做权限的变更

  ##默认权限是755,就不用修改##
  [root@zyshanlinux-001 mysql]# ls -l /etc/init.d/mysqld
  -rwxr-xr-x 1 root root 10902 6月  26 20:20 /etc/init.d/mysqld
  ##如果不是需要更改权限##
  [root@zyshanlinux-001 mysql]# chmod 755

如果需要开机启动,需要添加到系统服务列表

  [root@zyshanlinux-001 mysql]# chkconfig --list
  ​
  注:该输出结果只显示 SysV 服务,并不包含
  原生 systemd 服务。SysV 配置数据
  可能被原生 systemd 配置覆盖。 
  ​
        要列出 systemd 服务,请执行 'systemctl list-unit-files'。
        查看在具体 target 启用的服务请执行
        'systemctl list-dependencies [target]'。
  ​
  netconsole      0:关 1:关 2:关 3:关 4:关 5:关 6:关
  network         0:关 1:关 2:开 3:开 4:开 5:开 6:关
  [root@zyshanlinux-001 mysql]# chkconfig --add mysqld  ##添加到系统服务列表
  [root@zyshanlinux-001 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:关

也可以用命令启动

  [root@zyshanlinux-001 mysql]# /etc/init.d/mysqld start
  ##也可以##
  [root@zyshanlinux-001 mysql]# service mysqld start
  Starting MySQL.Logging to '/data/mysql/zyshanlinux-001.err'.
  ....... SUCCESS! ##启动成功

查看进程

  [root@zyshanlinux-001 ~]# ps aux |grep mysql

查看端口:3306(2186/mysqld)

  [root@zyshanlinux-001 ~]# netstat -lntp

场景:没有启动脚本模板,可以用命令行启动

--defaults-file=/etc/my.cnf配置文件放在前面

$丢到后台运行去

[root@zyshanlinux-001 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &[1] 2315[root@zyshanlinux-001 mysql]# 180626 20:41:32 mysqld_safe Logging to '/data/mysql/zyshanlinux-001.err'.180626 20:41:32 mysqld_safe Starting mysqld daemon with databases from /data/mysql

命令行无法关闭mysql服务,必须杀死

[root@zyshanlinux-001 mysql]# killall mysqld

经验:

killall优于kill,以为mysql在读写的时候,用killall是先停止读写,等待缓存里面的数据读写完成再停止服务:而kill则会导致数据丢失,因为它是直接停止服务,甚至会损害表。只能慢慢的等。

mysql有2个常用的引擎:innodb(存储空间大)、myisam(存储空间小)

MariaDB安装

1、把Mariadb包下到/usr/local/src/目录下

  [root@zyshanlinux-001 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

2、解压包

  tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz

3、把解压的包放到/usr/local/改名为mariadb

  [root@zyshanlinux-001 src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb

4、跳转到该目录

  [root@zyshanlinux-001 src]# cd /usr/local/mariadb

5、创建用户,数据目录,初始化

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

6、确认初始化命令正确

  [root@zyshanlinux-001 mariadb]# echo $?
  0

7、配置文件,分别按照内存大小选择不同的配置文件,由于试验内存不大只有2G,选用my-small.cnf配置文件

  [root@zyshanlinux-001 mariadb]# cd /usr/local/mariadb/
  [root@zyshanlinux-001 mariadb]# ls
  bin                 data               include         mysql-test    share
  COPYING             DESTINATION        INSTALL-BINARY  README.md     sql-bench
  COPYING.thirdparty  docs               lib             README-wsrep  support-files
  CREDITS             EXCEPTIONS-CLIENT  man             scripts
  [root@zyshanlinux-001 mariadb]# ls support-files/
  binary-configure  my-innodb-heavy-4G.cnf  my-small.cnf         mysql.server  wsrep_notify
  magic             my-large.cnf            mysqld_multi.server  policy
  my-huge.cnf       my-medium.cnf           mysql-log-rotate     wsrep.cnf

8、拷贝配置文件模板和启动脚本,配置文件基本不用改,启动脚本需要编辑一下

  [root@zyshanlinux-001 mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
  [root@zyshanlinux-001 mariadb]# cp support-files/mysql.server /etc/init.d/mariadb
  [root@zyshanlinux-001 mariadb]# vim !$
  vim /etc/init.d/mariadb  ##编辑,需要修改2个地方
  ​
  basedir=
  datadir=
  ##改为##
  basedir=/usr/local/mariadb
  datadir=/data/mariadb
  conf=$basedir/my.cnf  ##增加一行,指定配置文件所在的路径
  ​
  $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
  ##改为##
  $bindir/mysqld_safe --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &

9、由于mariadb和mysql所监听的端口是一致的,所以2个服务只能运行一个,在运行mariadb之前,需要检测mysql是否有运行,有运行结束掉mysql

  [root@zyshanlinux-001 mariadb]# ps aux |grep mysql
  root      3013  0.0  0.0  11816  1604 pts/0    S    20:50   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/zyshanlinux-001.pid
  mysql     3149  0.1 24.3 973096 456232 pts/0   Sl   20:50   0:11 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/zyshanlinux-001.err --pid-file=/data/mysql/zyshanlinux-001.pid --socket=/tmp/mysql.sock
  root      3920  0.0  0.0 112720   972 pts/0    R+   22:56   0:00 grep --color=auto mysql
  [root@zyshanlinux-001 mariadb]# service mysqld stop
  Shutting down MySQL.. SUCCESS! 
  [root@zyshanlinux-001 mariadb]# ps aux |grep mysql
  root      3947  0.0  0.0 112720   972 pts/0    R+   22:56   0:00 grep --color=auto mysql

10、运行mariadb服务,用ps确认mariadb确实是启动了

[root@zyshanlinux-001 ~]# service mariadb start
Starting mariadb (via systemctl):                          [  确定  ]
[root@zyshanlinux-001 ~]# ps aux |grep mariadb
root      1961  0.1  0.0 115432  1756 ?        S    07:36   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/zyshanlinux-001.pid
mysql     2080  2.5  3.0 1125076 56564 ?       Sl   07:36   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/zyshanlinux-001.err --pid-file=/data/mariadb/zyshanlinux-001.pid --socket=/tmp/mysql.sock --port=3306
root      2119  0.0  0.0 112720   972 pts/0    R+   07:36   0:00 grep --color=auto mariadb

查看端口,端口也没问题

[root@zyshanlinux-001 mariadb]# netstat -ltnp
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      1091/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1312/master         
tcp6       0      0 :::22                   :::*                    LISTEN      1091/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1312/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      4150/mysqld 

11、mariadb和mysql的区别,两者安装都差不多,但在mariadb安装的时候单独定义配置文件所在的路径,目的是为了和mysql不产生冲突;假如只安装了mariadb,把my.cnf就放在etc下,启动脚本就不需要去定义conf和变量了。

[root@zyshanlinux-001 mariadb]# ls /etc/my.cnf/etc/my.cnf[root@zyshanlinux-001 mariadb]# ps aux |grep mysqlroot 4034 0.0 0.0 115432 1744 ? S 22:59 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/zyshanlinux-001.pidmysql 4150 0.6 3.5 1125176 66680 ? Sl 22:59 0:04 /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/zyshanlinux-001.err --pid-file=/data/mysql/zyshanlinux-001.pid --socket=/tmp/mysql.sock --port=3306root 4250 0.0 0.0 112720 968 pts/0 R+ 23:09 0:00 grep --color=auto mysql[root@zyshanlinux-001 mariadb]# ps aux |grep mariadbroot 4034 0.0 0.0 115432 1744 ? S 22:59 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/zyshanlinux-001.pidmysql 4150 0.4 3.5 1125176 66680 ? Sl 22:59 0:04 /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/zyshanlinux-001.err --pid-file=/data/mysql/zyshanlinux-001.pid --socket=/tmp/mysql.sock --port=3306root 4271 0.0 0.0 112720 968 pts/0 R+ 23:14 0:00 grep --color=auto mariadb[root@zyshanlinux-001 mariadb]# /etc/init.d/mariadb stopStopping mariadb (via systemctl): [ 确定 ][root@zyshanlinux-001 mariadb]# ps aux |grep mariadbroot 4315 0.0 0.0 112720 972 pts/0 R+ 23:14 0:00 grep --color=auto mariadb[root@zyshanlinux-001 mariadb]# ps aux |grep mysqlroot 4317 0.0 0.0 112720 968 pts/0 R+ 23:14 0:00 grep --color=auto mysql[root@zyshanlinux-001 mariadb]# vim /usr/local/mariadb/my.cnf

##编辑my.cnf,把

[mysqld]port = 3306socket = /tmp/mysql.sock

改为

[mysqld]datadir = /data/mariadb ##指定数据目录port = 3306socket = /tmp/mysql.sock

[root@zyshanlinux-001 mariadb]# /etc/init.d/mariadb startStarting mariadb (via systemctl): [ 确定 ][root@zyshanlinux-001 mariadb]# ps aux |grep mariadbroot 4357 0.0 0.0 115432 1752 ? S 23:16 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/zyshanlinux-001.pidmysql 4476 0.9 3.2 1125076 61580 ? Sl 23:16 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/zyshanlinux-001.err --pid-file=/data/mariadb/zyshanlinux-001.pid --socket=/tmp/mysql.sock --port=3306root 4512 0.0 0.0 112720 972 pts/0 R+ 23:16 0:00 grep --color=auto mariadb

Apache安装

Apache是一个基金会的名字,httpd才是我们要安装的软件包,早期它的名字就叫apache

Apache官网www.apache.org

1、下载Apache包和apr和apr-util

[root@zyshanlinux-001 src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz
[root@zyshanlinux-001 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
[root@zyshanlinux-001 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2

httpd2.2和httpd2.4的安装不太一样有区别,涉及到依赖的软件apr,apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便地移植(从linux移植到windows);httpd2.2和httpd2.4依赖的apr版本也不一样,系统自带的apr和我们要安装的2.4是不匹配的,所以无法使用yum安装的apr,需要自己编译

2、解压

[root@zyshanlinux-001 src]# tar zxvf httpd-2.4.33.tar.gz
[root@zyshanlinux-001 src]# tar zxvf apr-1.6.3.tar.gz
[root@zyshanlinux-001 src]# tar jxvf apr-util-1.6.1.tar.bz2

3、安装apr-1.6.3

[root@zyshanlinux-001 apr-1.6.3]# cd apr-1.6.3
[root@zyshanlinux-001 apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@zyshanlinux-001 apr-1.6.3]# echo $?
0
[root@zyshanlinux-001 apr-1.6.3]# make && make install
[root@zyshanlinux-001 apr-1.6.3]# ls /usr/local/apr/
bin  build-1  include  lib

4、安装apr-util-1.6.1

[root@zyshanlinux-001 apr-1.6.3]# cd /usr/local/src/apr-util-1.5.4
[root@zyshanlinux-001 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr                                                               ##依赖apr##
[root@zyshanlinux-001 apr-util-1.6.1]# make && make install
 [root@zyshanlinux-001 apr-util-1.6.1]# ls /usr/local/apr-util/
bin  include  lib

5、安装httpd-2.4.33

[root@zyshanlinux-001 apr-util-1.6.1]# cd ..
[root@zyshanlinux-001 src]# cd /usr/local/src/httpd-2.4.33
                                                                     ##起名2.4与2.2区分##
[root@zyshanlinux-001 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
##依赖apr##                                          ##动态扩展##       ##支持哪些模块,大多数
...
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/                   ##报错##
[root@zyshanlinux-001 httpd-2.4.33]# yum list |grep pcre  ##解决思路,查一下yum list
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
[root@zyshanlinux-001 httpd-2.4.33]# yum install -y pcre-devel  ##安装解决库问题
##遇到这种输出错误,仔细看看,一般都可查到或猜到答案##
[root@zyshanlinux-001 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: summary of build options:

    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@zyshanlinux-001 httpd-2.4.33]# echo $?
0
[root@zyshanlinux-001 httpd-2.4.33]# make && make install
[root@zyshanlinux-001 httpd-2.4.33]# cd /usr/local/apache2.4/
[root@zyshanlinux-001 apache2.4]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules
[root@zyshanlinux-001 apache2.4]# ls -l bin/httpd
-rwxr-xr-x 1 root root 2348432 6月  27 08:44 bin/httpd  ##核心二进制文件
[root@zyshanlinux-001 apache2.4]# du -sh !$
du -sh bin/httpd
2.3M	bin/httpd
[root@zyshanlinux-001 apache2.4]# ls conf/  ##配置文件
extra  httpd.conf  magic  mime.types  original
[root@zyshanlinux-001 apache2.4]# ls htdocs/
index.html  ##默认访问网站
[root@zyshanlinux-001 apache2.4]# ls logs/  ##访问和错误日志
[root@zyshanlinux-001 apache2.4]# ls man  ##帮助文档
man1  man8
[root@zyshanlinux-001 apache2.4]# ls modules/  ##加载的模块放置处,每个模块代表一种功能
[root@zyshanlinux-001 apache2.4]# du -sh modules/
6.4M	modules/
##查看模块##
[root@zyshanlinux-001 apache2.4]# /usr/local/apache2.4/bin/apachectl -M
##或者##
[root@zyshanlinux-001 apache2.4]# /usr/local/apache2.4/bin/httpd -M
##这里并不是报错,只是要你定义下'ServerName'##
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::8fc3:bbdf:ba89:22a7. 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)

上面括号里面表示:shared动态是一个扩展的文件、static静态直接把模块编译进了主二进制文件/vin/httpd

运行httpd服务,不用开机启动,直接命令启动就好

[root@zyshanlinux-001 apache2.4]# /usr/local/apache2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::8fc3:bbdf:ba89:22a7. Set the 'ServerName' directive globally to suppress this message
[root@zyshanlinux-001 apache2.4]# ps aux |grep httpd
root     33892  0.0  0.1  97644  2536 ?        Ss   09:03   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon   33893  0.7  0.2 384472  4428 ?        Sl   09:03   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon   33894  0.0  0.2 384472  4428 ?        Sl   09:03   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon   33895  0.0  0.2 384472  4428 ?        Sl   09:03   0:00 /usr/local/apache2.4/bin/httpd -k start
root     33978  0.0  0.0 112720   968 pts/0    S+   09:04   0:00 grep --color=auto httpd
[root@zyshanlinux-001 apache2.4]# 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      1090/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1441/master         
tcp6       0      0 :::80                   :::*                    LISTEN      33892/httpd         
tcp6       0      0 :::22                   :::*                    LISTEN      1090/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1441/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      2080/mysqld

httpd默认监听80端口,mysqld默认监听3306端口,25是发邮件的,22是远程登录的

安装PHP5

PHP官网www.php.net

当前主流版本为5.6/7.1

1、进入约定下载目录

[root@zyshanlinux-001 ~]# cd /usr/local/src/
[root@zyshanlinux-001 src]#

2、下载PHP5包,解压,进入解压目录

[root@zyshanlinux-001 src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
[root@zyshanlinux-001 src]# tar zxf php-5.6.30.tar.gz
[root@zyshanlinux-001 src]# cd php-5.6.30

3、配置,初始化;把PHP放到最后安装是由于,需要用到apache的工具,所以要先安装apache,安装PHP的时候才能定义apache的工具

[root@zyshanlinux-001 php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs##apache的工具路径## --with-config-file-path=/usr/local/php/etc##PHP的配置文件##  --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config##这3个是mysql和PHP的驱动## --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需要的模块##

4、错误解决,第一次安装PHP有许多库是缺失的,根据错误一一解决,库都是devel结尾的

configure: error: xml2-config not found. Please check your libxml2 installation.
[root@zyshanlinux-001 php-5.6.30]# yum install -y libxml2-devel

configure: error: Cannot find OpenSSL's <evp.h>
[root@zyshanlinux-001 php-5.6.30]# yum install -y openssl-devel

configure: error: Please reinstall the BZip2 distribution
[root@zyshanlinux-001 php-5.6.30]# yum install -y bzip2-devel

configure: error: libjpeg.h not found.
##需要更换源,原本的源里面没有这个软件包##
[root@zyshanlinux-001 php-5.6.30]# yum install -y libjpeg-devel

configure: error: png.h not found.
[root@zyshanlinux-001 php-5.6.30]# yum install -y libpng-devel

configure: error: freetype-config not found.
[root@zyshanlinux-001 php-5.6.30]# yum install -y freetype-devel

configure: error: mcrypt.h not found. Please reinstall libmcrypt.
##如果之前没有安装过epel这个扩展源,因为mcrypt这个库实在epel这个扩展源里面##
[root@zyshanlinux-001 php-5.6.30]# yum install epel-release
[root@zyshanlinux-001 php-5.6.30]# yum install -y libmcrypt-devel

5、安装成功

+--------------------------------------------------------------------+
| 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@zyshanlinux-001 php-5.6.30]# echo $?
0

6、make && make install

  program: phpize
  program: php-config
Installing man pages:             /usr/local/php/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.0
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.3.0
[PEAR] PEAR           - installed: 1.10.1
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/usr/local/src/php-5.6.30/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/

[root@zyshanlinux-001 php-5.6.30]# ls /usr/local/php/
bin  etc  include  lib  php
[root@zyshanlinux-001 php-5.6.30]# ls /usr/local/php/bin/  ##核心文件
pear  peardev  pecl  phar  phar.phar  php  php-cgi  php-config  phpize
[root@zyshanlinux-001 php-5.6.30]# du -sh /usr/local/php/bin/php
36M	/usr/local/php/bin/php
##apache和PHP是通过下面的.so连接起来的##
[root@zyshanlinux-001 php-5.6.30]# du -sh /usr/local/apache2.4/modules/libphp5.so
37M	/usr/local/apache2.4/modules/libphp5.so

查看PHP加载的模块

[root@zyshanlinux-001 php-5.6.30]# /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是通过apache加载,以模块的形式来运行

[root@zyshanlinux-001 php-5.6.30]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::8fc3:bbdf:ba89:22a7. 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)  ##非常重要的,缺失apache就支持PHP了##

配置文件[root@zyshanlinux-001 php-5.6.30]# vi /usr/local/apache2.4/conf/httpd.conf

随用随取,只要去掉#号就可以

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  ##取用的模块

用命令/usr/local/php/bin/php -i |less可以查看PHP的一些信息

[root@zyshanlinux-001 php-5.6.30]# /usr/local/php/bin/php -i |less



phpinfo()
PHP Version => 5.6.30

System => Linux zyshanlinux-001 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64
Build Date => Jun 27 2018 10:35:47
Configure Command =>  './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'
Server API => Command Line Interface
Virtual Directory Support => enabled
Configuration File (php.ini) Path => /usr/local/php/etc
Loaded Configuration File => (none)
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
PHP API => 20131106
PHP Extension => 20131226
Zend Extension => 220131226
Zend Extension Build => API220131226,TS
PHP Extension Build => API20131226,TS
Debug Build => no
Thread Safety => enabled
Zend Signal Handling => disabled
Zend Memory Manager => enabled
Zend Multibyte Support => provided by mbstring
IPv6 Support => enabled
DTrace Support => disabled

Registered PHP Streams => https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar

复制参考配置文件到/usr/local/php/etc/php.ini,因为前面初始化的时候有定义了路径

[root@zyshanlinux-001 php-5.6.30]# ls /usr/local/php/etc
pear.conf
[root@zyshanlinux-001 php-5.6.30]# cp php.ini-production  /usr/local/php/etc/php.ini
[root@zyshanlinux-001 php-5.6.30]# /usr/local/php/bin/php -i |less
Loaded Configuration File => /usr/local/php/etc/php.ini  ##会在配置文件上增加这一行##

安装PHP7

1、安装php-7.1.6步骤与上面类似,定义的目录名字和配置文件路径不一样,没有--with-mysql反而是--with-mysqli

[root@zyshanlinux-001 ~]# cd /usr/local/src
[root@zyshanlinux-001 php-7.1.6]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
[root@zyshanlinux-001 php-7.1.6]# tar jxvf php-7.1.6.tar.bz2
[root@zyshanlinux-001 php-7.1.6]# cd php-7.1.6
[root@zyshanlinux-001 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
[root@zyshanlinux-001 php-7.1.6]# make && make install
[root@zyshanlinux-001 php-7.1.6]# echo $?
0
[root@zyshanlinux-001 php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so
/usr/local/apache2.4/modules/libphp7.so
[root@zyshanlinux-001 php-7.1.6]# du -sh !$
du -sh /usr/local/apache2.4/modules/libphp7.so
37M	/usr/local/apache2.4/modules/libphp7.so
[root@zyshanlinux-001 php-7.1.6]# /usr/local/php7/bin/php -m  ##查看模块,和5基本一致
[root@zyshanlinux-001 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -M  ##apache加载2个PHP
...
 php5_module (shared)
 php7_module (shared)

可以运行2个php(5和7),但apache必须指定好。

选择用哪个PHP,在配置文件上修改

[root@zyshanlinux-001 php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf
##不想用哪个就在那行前面加#注释掉哪个##
LoadModule php5_module        modules/libphp5.so
LoadModule php7_module        modules/libphp7.so

Apache和PHP结合

httpd主配置文件/usr/local/apache2.4/conf/httpd.conf

vim /usr/local/apache2.4/conf/httpd.conf //修改以下4个地方

1、ServerName,去掉#号

##告警,没报错##
[root@zyshanlinux-001 ~]# /usr/local/apache2.4/bin/apachectl restart
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::8fc3:bbdf:ba89:22a7. Set the 'ServerName' directive globally to suppress this message
##更改配置文件可以去掉这段告警##
[root@zyshanlinux-001 ~]# vim /usr/local/apache2.4/conf/httpd.conf
——————————————————————————
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName www.example.com:80  ##把#号去掉##
——————————————————————————————————

##虽然没告警了,但出现了一个错误,是由于配置文件中用了2个PHP(5和7)产生冲突导致的##
[root@zyshanlinux-001 ~]# /usr/local/apache2.4/bin/apachectl restart
httpd not running, trying to start
/usr/local/apache2.4/bin/apachectl: 行 79: 51484 段错误               $HTTPD -k $ARGV
[root@zyshanlinux-001 ~]# vim /usr/local/apache2.4/conf/httpd.conf ##继续修改配置文件
LoadModule php5_module        modules/libphp5.so
#LoadModule php7_module        modules/libphp7.so  ##注释掉PHP7##
##最后没有出现告警和报错了##

2、Require all denied改为Require all granted,为了防止打开虚拟机配置的时候出现403或在Forbidden,正常的状态都是200

首先连一下服务器

无法访问,用CMD连接看网络通不通:ping 192.168.106.128

如果telnet显示不是内部或外部命令,也不是可运行的程序。就需要去win系统去打开telnet功能

只打开客户端,不要打开服务端,否则它会监听23端口,比较危险。

已经打开的话,就会显示80端口连接失败,的提示。也可以在linux中用命令查看一下打开的端口,80端口也是没打开的

[root@zyshanlinux-001 ~]# iptables -nvL  ##查看打开的端口
[root@zyshanlinux-001 ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT  ##单独用一个命令打开80端口

连接浏览器,就会显示工作

连接window的cmd终端,通的状态

退出该连接状态:Ctrl+]退出,再quit退出telnet

更改配置文件

当Require all denied时,显示

[root@zyshanlinux-001 ~]# !vi
vim /usr/local/apache2.4/conf/httpd.conf
[root@zyshanlinux-001 ~]# /usr/local/apache2.4/bin/apachectl -t  ##-t检查语法是否错误,非常有用##
Syntax OK
##修改了配置文件,需要重新加载配置文件,但不会重启服务,最多就加载不成功,并不会杀死进程。##
[root@zyshanlinux-001 ~]# /usr/local/apache2.4/bin/apachectl graceful

当Require all granted,就显示

<Directory />
    AllowOverride none
    Require all granted  ##把denied改为granted##
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/usr/local/apache2.4/htdocs"
<Directory "/usr/local/apache2.4/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted  ##把denied改为granted##

3、AddType application/x-httpd-php .php要支持PHP,所以要增加一个和PHP相关的配置,不然PHP没法解析

[root@zyshanlinux-001 ~]# vim /usr/local/apache2.4/conf/httpd.conf

4、DirectoryIndex index.html 后面加上 index.php

[root@zyshanlinux-001 ~]# vim /usr/local/apache2.4/conf/httpd.conf
[root@zyshanlinux-001 ~]# /usr/local/apache2.4/bin/apachectl -t  ##改完记得检查语法##
Syntax OK
[root@zyshanlinux-001 ~]# /usr/local/apache2.4/bin/apachectl graceful  ##加载配置##

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

netstat -lntp

curl localhost

增加文件是不用加载配置的

[root@zyshanlinux-001 ~]# vi /usr/local/apache2.4/htdocs/1.php  ##在1.php中加上一下内容##
<?php
phpinfo();
?>

PHP可以解析,就会显示如下画面

故意把AddType application/x-httpd-php .php从/usr/local/apache2.4/conf/httpd.conf注释掉,就会显示原始代码。

如果显示原始代码,PHP无法解析,解决思路步骤:

1、模块是否存在

  [root@zyshanlinux-001 ~]# /usr/local/apache2.4/bin/apachectl -M
  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)  ##是否有php5这个模块

2、有模块,但没加载

  [root@zyshanlinux-001 ~]# ls /usr/local/apache2.4/modules/libphp5.so
  /usr/local/apache2.4/modules/libphp5.so  ##是否有这个文件,否则加载不了

3、有文件,没有显示,在配置有是否有这两个配置

  [root@zyshanlinux-001 ~]# vim /usr/local/apache2.4/conf/httpd.conf

4、配置文件里是否有AddType application/x-httpd-php .php,是否加了但是写错了的

      [root@zyshanlinux-001 ~]# vim /usr/local/apache2.4/conf/httpd.conf
      #
      AddType application/x-compress .Z
      AddType application/x-gzip .gz .tgz
      AddType application/x-httpd-php .php  ##加的##

写错了,可以用语法检查

  /usr/local/apache2.4/bin/apachectl -t //测试语法

5、index.php加不加不怎么影响,

  [root@zyshanlinux-001 ~]# vim /usr/local/apache2.4/conf/httpd.conf
  #
  <IfModule dir_module>
      DirectoryIndex index.html index.php

在浏览器上输入IP,实际上访问的是index.html

  [root@zyshanlinux-001 ~]# ls /usr/local/apache2.4/htdocs/
  1.php  index.html

真正的网址是www.baidu.com/index.html加了index.html就可以省略不写,因为我们提前定义了一个index.html

前面用的php5,现在不用php5用php7,在配置文件下注释掉php5,取消php7的注释,连接浏览器成功使用php7

  [root@zyshanlinux-001 ~]# vim /usr/local/apache2.4/conf/httpd.conf
  #LoadModule php5_module        modules/libphp5.so
  LoadModule php7_module        modules/libphp7.so
  ##用Ctrl+r可以轻松的把历史命令提现出来用,很方便##
  (reverse-i-search)`-t': /usr/local/apache2.4/bin/apachectl ^C
  (reverse-i-search)`gra': /usr/local/apache2.4/bin/apachectl ^Caceful
  [root@zyshanlinux-001 ~]#
  [root@zyshanlinux-001 ~]# /usr/local/apache2.4/bin/apachectl -t
  Syntax OK
  [root@zyshanlinux-001 ~]# /usr/local/apache2.4/bin/apachectl graceful

拓展练习:

Discuz建站教程:[1]本地安装discuz网站

https://jingyan.baidu.com/article/b87fe19eb57ff252183568d9.html

MySQL创建用户与授权

https://www.cnblogs.com/sos-blue/p/6852945.html

mysql5.5源码编译安装 http://www.aminglinux.com/bbs/thread-1059-1-1.htmlmysql5.7二进制包安装(变化较大) http://www.apelearn.com/bbs/thread-10105-1-1.htmlapache dso https://yq.aliyun.com/articles/6298apache apxs http://man.chinaunix.net/newsoft/ApacheMenual_CN_2.2new/programs/apxs.htmlapache工作模式 http://www.cnblogs.com/fnng/archive/2012/11/20/2779977.htmlphp中mysql,mysqli,mysqlnd,pdo到底是什么 http://blog.csdn.net/u013785951/article/details/60876816查看编译参数 http://ask.apelearn.com/question/1295


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值