目录
1. LAMP 架构介绍
其实就是四个大写字母的缩写,分别是 Linux + Apache + MySQL + PHP,其中PHP必须与Apache在同一台机器,而 MySQL 可以不与他们两在一起,从而实现 “站库分离”
1.1 LAMP 架构图
1.2 Apache
Apache 目前是一个基金会的名称,实际提供 http 服务的程序其实叫做 httpd,但由于其出品的第一版 http 服务程序叫做 apache,所以人们将该名称沿用至今。所以我们可以将 apache 与 httpd 当做是同一样东西,即 Web 服务器软件。
Apache 官网
1.3 MySQL
关系型数据库,由 MySQL AB 公司开发,该公司于 2008 年被 SUN 公司收购,而 SUN 公司于 2009 年被 Oracle 收购。
MySQL 官网
1.4 MariaDB
MySQL 被收购后,其创始人 Michael Widenius 协同大量的 MySQL 原班人马创建了 MariaDB,所以从使用上,MariaDB 与 MySQL 区别不大。
MariaDB 官网
1.5 PHP
超文本预处理器,用于提供 Apache 与 MySQL 之间的交互。原是由 Perl 语言编写,到目前已经吸取了 Perl、Java、C语言 的特点。但PHP应用于移动端的表现不好。当前更流行Java、Go、Python。
PHP 官网
2. LAMP 各软件的版本
2.1 Apache
- 最新版本:2.4
- 主流版本:2.4
2.2 MySQL
- 分类
版本 | 解释 |
---|---|
Community | 社区版 |
Enterprise | 企业版 |
GA | Generally Available,通用版,常用于生产环境 |
DMR | Development Milestone Release,里程碑版,有较大的变化 |
RC | Release Candidate,发型候选版,属于替补 |
Beta | 公测版 |
Alpha | 内测版 |
- 最新版本:MySQL 5.7 GA / MySQL 8.0 DMR
- 主流版本:MySQL 5.6 GA
2.3 MariaDB
分类:基本上沿用 MySQL 分类
最新版本:MariaDB 5.5 GA / MariaDB 10.3 GA
主流版本:MariaDB 10.2 GA
MariaDB 与 MySQL 的对应关系
MariaDB | MySQL |
---|---|
5.5 | 5.5 |
10.0 | 5.6 |
2.4 PHP
- 最新版本:5.6 / 7.1
- 主流版本:5.6
3. MySQL 安装
3.1 下载、解压
- 将安装包下载到 /usr/local/src/ 中(300MB)
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
- 安装包解压缩,并放于正式安装目录
[root@localhost src]# tar -xzvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
[root@localhost src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql
[root@localhost src]# cd /usr/local/mysql
3.2 建立账户与目录
- 建立使用 MySQL 的账户
[root@localhost mysql]# useradd mysql
- 建立存放数据的目录
[root@localhost mysql]# mkdir /data/
3.3 安装
- 执行安装命令:当运行完安装脚本后,若在输出中看到 两个 OK 则表示成功安装
## 纯净系统,还没装Perl,会报错
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql # 只需提前创建 /data/即可,而 /data/mysql 会由该脚本自动建立
-bash: ./scripts/mysql_install_db: /usr/bin/perl: 坏的解释器: 没有那个文件或目录
## 那就装个 Perl
[root@localhost mysql]# yum -y install perl
## 再试一次,又提示没有 Dumper
[root@localhost 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@localhost mysql]# yum list | grep -i dumper
abi-dumper.noarch 1.1-3.el7 epel
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
php-symfony-var-dumper.noarch 2.8.12-2.el7 epel
vtable-dumper.x86_64 1.1-1.el7 epel
## 其实真正缺少的是 perl-Data-Dumper.x86_64
[root@localhost mysql]# yum -y install perl-Data-Dumper
## 再试一次,又说缺 **libaio.so.1**
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
## 查查看这个文件包含在哪个安装包中
[root@localhost mysql]# yum provides */libaio.so.1
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyuncs.com
* epel: mirrors.sohu.com
* extras: mirrors.aliyuncs.com
* updates: mirrors.aliyuncs.com
libaio-0.3.109-13.el7.i686 : Linux-native asynchronous I/O access library
源 :base
匹配来源:
文件名 :/lib/libaio.so.1
libaio-0.3.109-13.el7.x86_64 : Linux-native asynchronous I/O access library
源 :base
匹配来源:
文件名 :/lib64/libaio.so.1
## 看来就是她了:libaio-0.3.109-13.el7.x86_64,缺少补啥吧!
[root@localhost mysql]# yum -y install libaio-0.3.109-13.el7.x86_64
## 最后再装一次
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
【成功】
3.4 配置
- 将安装包中带有的 MySQL 配置文件复制到 /etc/ 下(CentOS 7 初始安装时就已经有 /etc/my.cnf 了,所以其实不替换也可以,只要保证有必要的配置信息)
## 在此我采用替换的方法,所以要提前备份一下原有的 /etc/my.cnf
[root@localhost mysql]# mv /etc/my.cnf /etc/my.cnf.bak
[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf
- 修改配置文件内容
[root@localhost mysql]# vi /etc/my.cnf
1 # For advice on how to change settings please see
2 # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
3 # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
4 # *** default location during install, and will be replaced if you
5 # *** upgrade to a newer version of MySQL.
6
7 [mysqld]
8
9 # Remove leading # and set to the amount of RAM for the most important data
10 # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
11 # innodb_buffer_pool_size = 128M
12
13 # Remove leading # to turn on a very important data integrity option: logging
14 # changes to the binary log between backups.
15 # log_bin
16
17 # These are commonly set, remove the # and set as required.
18 basedir = /usr/local/mysql # 主要是这两行
19 datadir = /data/mysql
20 port = 3306
21 # server_id = .....
22 socket = /tmp/mysql.sock
23
24 # Remove leading # to set options mainly useful for reporting servers.
25 # The server defaults are faster for transactions and fast SELECTs.
26 # Adjust sizes as needed, experiment to find the optimal values.
27 # join_buffer_size = 128M
28 # sort_buffer_size = 2M
29 # read_rnd_buffer_size = 2M
30
31 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
- 将 MySQL 服务的启动程序复制到 /etc/init.d/mysqld 下
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod 755 /etc/init.d/mysqld
- 修改启动程序内容
$ vi /etc/init.d/mysqld
.
.
.
46 basedir=/usr/local/mysql
47 datadir=/data/mysql
.
.
.
259 case "$mode" in
260 'start')
261 # Start daemon
262
263 # Safeguard (relative paths, core dumps..)
264 cd $basedir
265
266 echo $echo_n "Starting MySQL"
267 if test -x $bindir/mysqld_safe
268 then
269 # Give extra arguments to mysqld with the my.cnf file. This script
270 # may be overwritten at next upgrade.
271 $bindir/mysqld_safe --datadir="$datadir" --basedir="$basedir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
## 主要是上面这一行,添加 --basedir="$basedir"
- 将 mysqld 添加至开机启动
[root@localhost mysql]# chkconfig --add mysqld
3.5 MySQL 的启动
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'.
.. SUCCESS!
## 也可以采用以下命令启动 MySQL
[root@localhost mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql
3.6 启动情况查看
## 看看是否按照我们的设置正确开启了服务,如 basedir、datadir、port、user 等
[root@localhost mysql]# ps aux | grep mysql
root 41896 0.0 0.0 113304 1648 pts/0 S 6月26 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --basedir=/usr/local/mysql --pid-file=/data/mysql/localhost.localdomain.pid
mysql 42074 3.4 11.7 1300828 455004 pts/0 Sl 6月26 0:02 /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/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root 42103 0.0 0.0 112720 972 pts/0 S+ 00:00 0:00 grep --color=auto mysql
## 看看端口情况
[root@localhost mysql]# netstat -ltnp | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 42074/mysqld
3.7 MySQL 的关闭
-
service mysqld stop
或/etc/init.d/mysqld
推荐!最温和的关闭方式,但可能比较慢
-
killall mysqld
会先停止当前读写,然后将威胁如此盘的数据写入磁盘,写完后才会杀死进程
注意:强烈不推荐使用 kill PID 的方法进行 MySQL 的关闭,有时使用上述两种方法后缺发现进程迟迟未关闭,这时很有可能是由于数据量较大,还在逐渐写入磁盘,此时如果强行 kill 的话,极有可能造成数据丢失甚至磁盘损坏
4. Mariadb 安装
与 MySQL 大同小异,这里就仅列出具体的配置命令,不再做拍错以及输出的展示
4.1 下载、解压
$ cd /usr/local/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
$ tar -xzvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
$ mv mariadb* /usr/local/mariadb
$ cd /usr/local/mariadb
4.2 增加账户、目录
$ useradd mysql
$ mkdir /data/
4.3 安装
## 这里与 MySQL 的安装有所区别,需要指定 basedir,否则可能去 /etc/my.cnf 中寻找
./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb --basedir=/usr/local/mariadb
4.4 配置
- 复制配置文件:mariadb 安装包中提供多种配置文件如:small,large,huge 等,主要是对数据库缓存设置的不同
$ cp /usr/local/mariadb/support-files/my-small.cnf /usr/local/mariadb/my.cnf
- 修改配置文件:定义 basedir 和 datadir
$ vim /usr/local/mariadb/my.cnf
- 复制启动文件
$ cp /usr/local/mariadb/support-files/mysql.server /etc/init.d/mariadb
- 修改启动文件:主要修改 basedir、datadir、conf 等内容
$ vim /etc/init.d/mariadb
basedir=/usr/local/mariadb
datadir=/root/mariadb
conf=/usr/local/mariadb/my.cnf
在 case "$mode" in
'start') 中的 $bindir /mysqld_safe 后添加 --defaults-file="$conf"
5. Apache 安装
安装 Apache 前需要安装 apr 以及 apr-util ,他们是可移植运行库,能够帮助 Apache 在不同平台间移植
5.1 安装 apr
- 养成良好习惯,将 apr 安装包下载至 /usr/local/src/ 中
[root@VMware01 src]# cd /usr/local/src/
[root@VMware01 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
- 解压缩
[root@VMware01 src]# tar xzvf apr-1.6.3.tar.gz
- 编译、安装
[root@VMware01 src]# cd apr-1.6.3
[root@VMware01 apr-1.6.3]# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
Platform: x86_64-pc-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.6.3
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/apr-1.6.3':
configure: error: no acceptable C compiler found in $PATH # 没有编译器。。。
See `config.log' for more details
## 那就装个 gcc
[root@VMware01 apr-1.6.3]# yum -y install gcc
## 在执行一次 ./configure
[root@VMware01 apr-1.6.3]# ./configure --prefix=/usr/local/apr
.
.
.
config.status: executing libtool commands
rm: cannot remove 'libtoolT': No such file or directory # 报错 libtoolT
config.status: executing default commands
## 查一下啥是 libtool
[root@VMware01 apr-1.6.3]# yum list | grep libtool
libtool-ltdl.x86_64 2.4.2-22.el7_3 @anaconda
libtool.x86_64 2.4.2-22.el7_3 base
libtool-ltdl.i686 2.4.2-22.el7_3 base
libtool-ltdl-devel.i686 2.4.2-22.el7_3 base
libtool-ltdl-devel.x86_64 2.4.2-22.el7_3 base
## 估计又是库的问题,那就专找 *-devel 这种包来安装
[root@VMware01 apr-1.6.3]# yum -y install libtool-ltdl-devel
## 再试一次,还是报错,那只能Google了,得出结果是修改 configure 文件的某些内容
[root@VMware01 apr-1.6.3]# vim configure
.
.
.
30433 case $ac_file$ac_mode in
30434 "libtool":C)
30435
30436 # See if we are running on zsh, and set the options which allow our
30437 # commands through without removal of \ escapes.
30438 if test -n "${ZSH_VERSION+set}" ; then
30439 setopt NO_GLOB_SUBST
30440 fi
30441
30442 cfgfile="${ofile}T"
30443 trap "$RM \"$cfgfile\"; exit 1" 1 2 15
30444 # $RM "$cfgfile" #注释掉该行即可
.
.
.
## 在运行一次
[root@VMware01 apr-1.6.3]# ./configure --prefix=/usr/local/apr
【成功】
[root@VMware01 apr-1.6.3]# make && make install
5.2 安装 apr-util
- 养成良好习惯,将 apr 安装包下载至 /usr/local/src/ 中
##
[root@VMware01 apr-1.6.3]# cd /usr/local/src/
[root@VMware01 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2
- 解压缩
[root@VMware01 src]# tar -xjvf apr-util-1.6.1.tar.bz2
- 编译、安装
[root@VMware01 src]# cd apr-util-1.6.1
[root@VMware01 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
【成功】
[root@VMware01 apr-util-1.6.1]# make && make install
.
.
.
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
#include <expat.h> #报错,缺少 expat.h
## 查一下哪些rpm包含有 expat.h 文件
[root@VMware01 apr-util-1.6.1]# yum provides */expat.h
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
expat-devel-2.1.0-10.el7_3.i686 : Libraries and header files to develop applications using expat
源 :base
匹配来源:
文件名 :/usr/include/expat.h
expat-devel-2.1.0-10.el7_3.x86_64 : Libraries and header files to develop applications using expat
源 :base
匹配来源:
文件名 :/usr/include/expat.h
xulrunner-devel-31.6.0-2.el7.centos.i686 : Development files for Gecko
源 :base
匹配来源:
文件名 :/usr/include/xulrunner-31.6.0/expat.h
xulrunner-devel-31.6.0-2.el7.centos.x86_64 : Development files for Gecko
源 :base
匹配来源:
文件名 :/usr/include/xulrunner-31.6.0/expat.h
## 找名字最像的那个
[root@VMware01 apr-util-1.6.1]# yum -y install expat-devel
## 再试一次
[root@VMware01 apr-util-1.6.1]# make && make install
【成功】
5.3 安装工 apache
- 下载
[root@VMware01 apr-util-1.6.1]# cd /usr/local/src/
[root@VMware01 src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz
- 解压缩
[root@VMware01 src]# tar xzvf httpd-2.4.33.tar.gz
- 编译、安装
[root@VMware01 src]# cd httpd-2.4.33
[root@VMware01 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 # 指定要支持哪些模块,most代表最多
.
.
.
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ #报错,缺 pcre-config
## 找 pcre-config 文件,并安装相应 rpm
[root@VMware01 httpd-2.4.33]# yum provides */pcre-config
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
pcre-devel-8.32-17.el7.i686 : Development files for pcre
源 :base
匹配来源:
文件名 :/usr/bin/pcre-config
pcre-devel-8.32-17.el7.x86_64 : Development files for pcre
源 :base
匹配来源:
文件名 :/usr/bin/pcre-config
## 就是他了
[root@VMware01 httpd-2.4.33]# yum -y install pcre-devel
## 再次执行,成功
[root@VMware01 src]# cd httpd-2.4.33
[root@VMware01 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
【成功】
- make && make install
[root@VMware01 httpd-2.4.33]# make
/usr/local/apr/build-1/libtool --silent --mode=link gcc -std=gnu99 -g -O2 -pthread -o htpasswd htpasswd.lo passwd_common.lo /usr/local/apr-util/lib/libaprutil-1.la /usr/local/apr/lib/libapr-1.la -lrt -lcrypt -lpthread -ldl -lcrypt
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserCreate'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserFree'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetUserData'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'
collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] 错误 1
make[2]: 离开目录“/usr/local/src/httpd-2.4.33/support”
make[1]: *** [all-recursive] 错误 1
make[1]: 离开目录“/usr/local/src/httpd-2.4.33/support”
make: *** [all-recursive] 错误 1
## 网上教的方法是重新安装一遍 apr-util,那只能试试了:删掉 /usr/local/apr-util 目录,重新编译apr-util,重新编译 apache, 竟然真的成功了
- 开启 apache
[root@VMware01 httpd-2.4.33]# cd /usr/local/apache2.4
[root@VMware01 apache2.4]# ./bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::8434:c43d:f653:7150. Set the 'ServerName' directive globally to suppress this message
- 查看启动情况
[root@VMware01 httpd-2.4.33]# 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 946/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1254/master
tcp6 0 0 :::3306 :::* LISTEN 31979/mysqld
tcp6 0 0 :::80 :::* LISTEN 104448/httpd
tcp6 0 0 :::22 :::* LISTEN 946/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1254/master
[root@VMware01 httpd-2.4.33]# ps aux | grep httpd
root 104448 0.0 0.1 97628 2548 ? Ss 10:15 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 104449 0.0 0.2 384456 4420 ? Sl 10:15 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 104450 0.0 0.1 384456 2388 ? Sl 10:15 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 104451 0.0 0.1 384456 2384 ? Sl 10:15 0:00 /usr/local/apache2.4/bin/httpd -k start
root 104537 0.0 0.0 112720 972 pts/0 S+ 10:17 0:00 grep --color=auto httpd
- 查看当前 apache 支持哪些模块
static:静态,直接编译进主脚本中的模块
shared:共享的,扩展模块,在 /usr/local/apache2.4/modules/ 中的模块
[root@VMware01 ~]# /usr/local/apache2.4/bin/httpd -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)
6. PHP 安装
6.1 下载、解压
[root@VMware01 src]# cd /usr/local/src/
[root@VMware01 src]# wget http://cn2.php.net/distributions/php-5.6.32.tar.bz2
[root@VMware01 src]# tar -xjvf php-5.6.32.tar.bz2
[root@VMware01 src]# cd php-5.6.32
6.2 编译、安装(拍错的方式不再讲述,前面的例子已经有大体的方法)
[root@VMware01 php-5.6.32]# ./configure \
> --prefix=/usr/local/php \
> --with-apxs2=/usr/local/apache2.4/bin/apxs \ #Apache 的工具,自动把扩展模块放到 modules 目录中
> --with-config-file-path=/usr/local/php/etc \
> --with-mysql=/usr/local/mysql \ # 三种不同的 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
[root@VMware01 php-5.6.32]# make && make install
6.3 查看php带有的模块
[root@VMware01 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
6.4 查看 /usr/local/apache2.4/conf/httpd.conf 是否已连接 php 模块
[root@VMware01 php-5.6.32]# vim /usr/local/apache2.4/conf/httpd.conf
.
.
.
151 LoadModule php5_module modules/libphp5.so # php 已经将该模块写进了 httpd 的配置文件
.
.
.
6.5 复制 php 配置文件
[root@VMware01 php-5.6.32]# cp php.ini-production /usr/local/php/etc
7. PHP 与 Apache 的连接
7.1 放通 iptables 访问 http
[root@VMware01 local]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
7.2 新建 php 页面
[root@VMware01 local]# vim /usr/local/apache2.4/htdocs/index.php
1 <?php
2 phpinfo();
3 ?>
7.3 访问网站地址
7.4 访问 php 页面(并未将php语句解释出来)
7.5 修改 httpd.conf 文件
[root@VMware01 php-5.6.32]# vi /usr/local/apache2.4/conf/httpd.conf
.
.
.
193 ServerName www.example.com:80
.
.
.
200 <Directory />
201 AllowOverride none
202 Require all granted
203
204 </Directory>
.
.
.
387 #
388 AddType application/x-compress .Z
389 AddType application/x-gzip .gz .tgz
390 AddType application/x-httpd-php .php
.
.
.
251 <IfModule dir_module>
252 DirectoryIndex index.html index.php
253 </IfModule>
7.6 检查 httpd.conf 语法
[root@VMware01 local]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
7.7 重新载入配置文档
[root@VMware01 local]# /usr/local/apache2.4/bin/apachectl graceful
7.8 再次访问 php 页面
7.9 无法解析 PHP 时的基本排错思路
- 查看是否按照上文进行 httpd.conf 的配置
- 查看 apache 是否加载 PHP:
/usr/local/apache2.4/bin/apachectl -M
- 查看 apache 的 modules 目录中是否有 PHP 模块:
ls /usr/local/apache2.4/modules/
- 查看 httpd.conf 中是否设定加载了 PHP:
LoadModule php5_module modules/libphp5.so