LAMP架构部署详解

一、LAMP架构介绍

LAMP架构部署详解

Linux为操作系统,apache是提供web服务的中间件,mysql主要存储数据,php是一个脚本语言,和shell类似,但是相对复杂,通常用来写网站。

二、httpd、PHP、MySQL三者连接关系

针对apapche、mysql、php三个角色,它们可以部署在同一台机器上,也可以单独部署mysql,但是httpd和php要部署在同一台机器上(为什么?)

LAMP架构部署详解

apache和php视为一个整体,因为php是以一个模块(PHP module)和apapche相互进行数据交互的,也就是说apahce不能直接和mysql进行数据交互,只能通过php module模块向mysql取数据,然后再返回给apache ,最终再返回用户发出的访问请求。

注意:

PHP modle向mysql取数据的过程,我们称为动态请求,比如我们访问知乎网站时,在浏览器上输入账号密码,然后交给apache,apache拿到用户输入的账号密码后,通过PHP Module把数据传递给mysql进行一个比较验证,看看用户在浏览器上输入账号密码和mysql数据中的是否一致,mysql再通过PHP Module返回验证结果给apapche,如果用户在浏览器输入正确账号密码后就能顺利登陆。这个过程就是一个动态请求的过程

如果你是访问某个网站上图片(静态文件),也就是没有和mysql进行数据交互,这个过程就是静态请求,需要说明的是mysql里面不存图片(静态文件)

三、静态页面和动态页面知识延伸

1.概念定义

1.1静态网页

静态网页是标准的HTML文件,它的文件扩展名是.htm或.html,可以包含文本、图像、声音、FLASH动画、客户端脚本和ActiveX控件及JAVA小程序等。

这种网页不包含在服务器端运行的任何脚本,网页上的每一行代码都是由网页设计人员预先编写好后,放置到Web服务器上的,在发送到客户端的浏览器上后不再发生任何变化,因此称其为静态网页。

静态网页的处理流程:

1、当用户在浏览器的‘地址’栏中输入一个URL地址并单击‘转到’按钮或敲击键盘上的‘回车键’后、单击网页中的超链接后、在浏览器菜单栏的‘收藏’选择一个网址后,浏览器将向Web服务器发出一个页面请求。

2、当Web服务器收到这个页面请求,根据.htm或.html判断出这是一个静态的HTML文件,会从磁盘或存储器中查找获取用户请求的这个页面。

3、Web服务器找到这个请求文件后,就会把它发送到浏览器,浏览器对这个返回的HTML文件进行解释并将结果显示在浏览器中。

1.2 动态网页

动态页面是以ASP、PHP、JSP、http://ASP.net、Perl、或CGI等编程语言制作的。 我们经常会看到,在地址栏里有一些网址特别长,而且还带有“?”,这样的链接一般是动态链接,其所对应的页面就是动态页面。

动态页面具有这些特征:

动态页面是以ASP、PHP、JSP、http://ASP.net、Perl、或CGI等编程语言制作的

动态页面实际上并不是独立存在于服务器上的网页文件,只有当用户请求时服务器才返回一个完整的网页;动态页面上的内容存在于数据库中,根据用户发出的不同请求,其提供个性化的网页内容;动态页面内容不是存在于页面上,而是在数据库中,从而大大降低网站维护的工作量;

采用动态网页技术的网站可以实现更多的功能,如用户注册、用户登录、在线调查、用户管理、订单管理等等;静态页面则无法实现这些功能。

动态网页的处理流程:

1、当用户在浏览器的‘地址'栏中输入一个URL地址并单击‘转到'按钮或敲击键盘上的‘回车键'后、单击网页中的超链接后、在浏览器菜单栏的‘收藏'选择一个网址后,浏览器将向Web服务器发出一个页面请求。
2、当Web服务器收到这个页面请求,根据文件扩展名判断出它是一个动态网页,会从磁盘或存储器中查找获取用户请求的这个页面,再将这个页面传递给应用程序服务器。
3、应用程序服务器解释执行该页中的脚本代码,并将结果以静态网页的形式保存。
4、应用程序服务器将静态网页结果传递给Web服务器。

2.区别联系

动态网页和静态网页的相同之处:都是ASCII编码文件,都存在着HTML代码,都能包含脚本语言代码,都存放在Web服务器上,都把用户请求的页面发送到浏览上。

动态网页和静态网页的区别是:动态网页的文件扩展名不是.htm、.html,而是以.asp、.jsp、.php、.perl、.cgi等形式为文件后缀;动态网页中的某些脚本只能在服务器上运行,而静态网页不能包含在服务器上运行的任何脚本;当Web服务器收到用户请求的静态页面后,将把查找结果直接发送到浏览器,而当Web服务器收到用户请求的动态页面后,它将先把这个网页传递给一个称为应用服务器扩展的特殊软件进行处理,然后将处理结果传送给浏览器。

关于静态页面和动态页面的其他文档资料

https://www.cnblogs.com/bluesungz/p/5955170.html

四、MySQL数据安装

MySQL数据库介绍

1、数据库基础知识

  • MySQL是一种开放源代码的关系型数据库管理系统(RDBMS),MySQL数据库系统使用最常用的数据库管理语言–结构化查询语言(SQL)进行数据库管理。

  • MySQL在2008年被SUN公司收购,2009年SUN公司被Oracle公司收购。

  • MySQL5.6功能变化较大,MySQL5.7性能上有很大提升

  • Mariadb为MySQL的一个分支,官方网站:https://mariadb.com, MariaDB主要由SkySQL公司维护,而SkySQL公司团队是由MySQL原作者等大部分原班人马组成的。

  • MySQL版本分为Community社区版、Enterprise企业版、GA(Generally Available)通过版本(通常用于生产环境)、DMR(Development Milestone Release)开发里程碑发布版、RC(Release Candidate)发行候选版本、Beta开放测试版本、Alpha内部测试版本。

数据库(Database)是按照数据结构来组织、存储和管理数据的仓库,它产生于距今六十多年前,随着信息技术和市场的发展,特别是二十世纪九十年代以后,数据管理不再仅仅是存储和管理数据,而转变成用户所需要的各种数据管理的方式。数据库有很多种类型,从最简单的存储有各种数据的表格到能够进行海量数据存储的大型数据库系统都在各个方面得到了广泛的应用。

主流的数据库有:sqlserver,mysql,Oracle、SQLite、Access、MS SQL Server等,本文主要讲述的是mysql

2、数据库管理的功能

a. 将数据保存到文件或内存

b. 接收特定的命令,然后对文件进行相应的操作

说明:对于数据库管理系统,无须自己再去创建文件和文件夹,而是直接传递 命令给相应软件,让其来进行文件操作,他们统称为数据库管理系统(DBMS,Database Management System)

MySQL安装配置

1. MySQL的几个常用安装包方法

a.rpm安装 ##不能定义安装路径,默认就是安装/usr/目录下面
b.源码安装
c.二进制免编译安装 ####不用编译,可以指定安装目录

说明:一般在工作中推荐使用二进制免编译安装

2.安装操作步骤

cd /usr/local/src/   ####指定mysql的安装目录,其他目录也行
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz

解压安装包

tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz  

移动重命名

mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql
cd /usr/local/mysql/
ls
bin  COPYING  data  docs  include  lib  man  mysql-test  README  scripts  share  sql-bench  support-files

创建mysql用户

useradd mysql

创建存放mysql数据的目录

[root@localhost mysql]# mkdir /data 
[root@localhost mysql]# ls /data/
[root@localhost mysql]#
[root@localhost mysql]#  ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql

说明:在执行这条命令后,怎么验证这条初始化命令是否成功,可以从两点来确认

1)执行命令后,最后会出现两个OK

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MySQL system tables...2017-11-29 06:16:59 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-29 06:16:59 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-11-29 06:16:59 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 6626 ...
2017-11-29 06:16:59 6626 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-11-29 06:16:59 6626 [Note] InnoDB: The InnoDB memory heap is disabled
2017-11-29 06:16:59 6626 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-11-29 06:16:59 6626 [Note] InnoDB: Memory barrier is not used
2017-11-29 06:16:59 6626 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-11-29 06:16:59 6626 [Note] InnoDB: Using Linux native AIO
2017-11-29 06:16:59 6626 [Note] InnoDB: Using CPU crc32 instructions
2017-11-29 06:16:59 6626 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-11-29 06:16:59 6626 [Note] InnoDB: Completed initialization of buffer pool
2017-11-29 06:16:59 6626 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2017-11-29 06:16:59 6626 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2017-11-29 06:16:59 6626 [Note] InnoDB: Database physically writes the file full: wait...
2017-11-29 06:16:59 6626 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2017-11-29 06:17:00 6626 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2017-11-29 06:17:00 6626 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2017-11-29 06:17:00 6626 [Warning] InnoDB: New log files created, LSN=45781
2017-11-29 06:17:00 6626 [Note] InnoDB: Doublewrite buffer not found: creating new
2017-11-29 06:17:00 6626 [Note] InnoDB: Doublewrite buffer created
2017-11-29 06:17:00 6626 [Note] InnoDB: 128 rollback segment(s) are active.
2017-11-29 06:17:00 6626 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-29 06:17:00 6626 [Note] InnoDB: Foreign key constraint system tables created
2017-11-29 06:17:00 6626 [Note] InnoDB: Creating tablespace and datafile system tables.
2017-11-29 06:17:00 6626 [Note] InnoDB: Tablespace and datafile system tables created.
2017-11-29 06:17:00 6626 [Note] InnoDB: Waiting for purge to start
2017-11-29 06:17:00 6626 [Note] InnoDB: 5.6.36 started; log sequence number 0
2017-11-29 06:17:00 6626 [Note] Binlog end
2017-11-29 06:17:00 6626 [Note] InnoDB: FTS optimize thread exiting.
2017-11-29 06:17:00 6626 [Note] InnoDB: Starting shutdown...
2017-11-29 06:17:02 6626 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2017-11-29 06:17:02 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-29 06:17:02 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-11-29 06:17:02 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 6652 ...
2017-11-29 06:17:02 6652 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-11-29 06:17:02 6652 [Note] InnoDB: The InnoDB memory heap is disabled
2017-11-29 06:17:02 6652 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-11-29 06:17:02 6652 [Note] InnoDB: Memory barrier is not used
2017-11-29 06:17:02 6652 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-11-29 06:17:02 6652 [Note] InnoDB: Using Linux native AIO
2017-11-29 06:17:02 6652 [Note] InnoDB: Using CPU crc32 instructions
2017-11-29 06:17:02 6652 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-11-29 06:17:02 6652 [Note] InnoDB: Completed initialization of buffer pool
2017-11-29 06:17:02 6652 [Note] InnoDB: Highest supported file format is Barracuda.
2017-11-29 06:17:02 6652 [Note] InnoDB: 128 rollback segment(s) are active.
2017-11-29 06:17:02 6652 [Note] InnoDB: Waiting for purge to start
2017-11-29 06:17:02 6652 [Note] InnoDB: 5.6.36 started; log sequence number 1625977
2017-11-29 06:17:02 6652 [Note] Binlog end
2017-11-29 06:17:02 6652 [Note] InnoDB: FTS optimize thread exiting.
2017-11-29 06:17:02 6652 [Note] InnoDB: Starting shutdown...
2017-11-29 06:17:04 6652 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
  ./bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
  cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
  cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as ./my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

2) 确认命令是否执行成功的方法

[root@localhost mysql]#  echo $?
0
说明命令初始化成功

3.拷贝mysql配置文件和启动脚本

[root@localhost mysql]# ls
bin      data  include  man     mysql-test  scripts  sql-bench COPYING  docs  lib      my.cnf  README      share support-files

拷贝mysql启动配置文件

[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf 

查看/etc/my.cnf 是由哪个rpm安装的

[root@docker mysql-5.6.36-linux-glibc2.5-x86_64]# rpm -qf /etc/my.cnf
mariadb-libs-5.5.52-1.el7.x86_64

编辑/etc/my.cnf配置文件,修改datadir、socket参数为

[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock

MySQL数据库默认启动脚本为mysql.server

[root@localhost mysql]# ls support-files/
binary-configure  magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server

[root@localhost mysql]#cp support-files/mysql.server /etc/rc.d/init.d/mysqld

说明:需要把mysql数据库的启动脚本mysql.server 配置centos7系统的脚本启动目录/etc/rc.d/init.d/mysqld

配置MySQL数据库启动脚本参数,编辑support-files/mysql.server,把basedir、datadir参数修改为

basedir=/usr/local/mysql
datadir=/data/mysql

启动MySQL数据库,并验证进程是否存在

[root@centos7 mysql]# systemctl start mysql
[root@centos7 mysql]# systemctl status mysql
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (running) since Mon 2018-03-19 07:25:05 CST; 9s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 20142 ExecStop=/etc/rc.d/init.d/mysqld stop (code=exited, status=0/SUCCESS)
  Process: 21328 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
   Memory: 436.5M
   CGroup: /system.slice/mysqld.service
           ├─21336 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/centos7.pid
           └─21474 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=...
Mar 19 07:25:03 centos7 systemd[1]: Starting LSB: start and stop MySQL...
Mar 19 07:25:03 centos7 mysqld[21328]: Starting MySQL.Logging to '/data/mysql/centos7.err'.
Mar 19 07:25:05 centos7 mysqld[21328]: . SUCCESS!
Mar 19 07:25:05 centos7 systemd[1]: Started LSB: start and stop MySQL.

查看MySQL进程是否存在

[root@centos7 mysql]# ps aux |grep mysql
root     21336  0.0  0.0 115392  1700 ?        S    07:25   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/centos7.pid
mysql    21474  7.5  0.3 1302864 452224 ?      Sl   07:25   0:01 /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/centos7.err --pid-file=/data/mysql/centos7.pid --socket=/tmp/mysql.sock
root     21511  0.0  0.0 112664   968 pts/7    S+   07:25   0:00 grep --color=auto mysql

数据库3306端口是否被监听

[root@centos7 mysql]# netstat -nlp |grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      21474/mysqld        
[root@centos7 mysql]#

4、技巧经验总结

killall和kill命令在日常运维工作中的使用

killall是杀掉所有正在运行的进程,对于正在向MySQL写数据的时候,如果无法使用kill命令杀掉某个进程,说明此时数据量较大,那么这样的情况下,不能使用kill -9 来杀进程,因为这样会导致正在写入磁盘或者缓存(内存)中的数据没有同步到磁盘,这样可能会丢掉一些数据,这时候只能用killall。

如果无法kill掉某个服务的进程,说明这个服务的数据量的非常大,只有等服务数据同步完才能杀死进程。

五、Apache安装、配置

1.下载安装包

cd /usr/local/src/
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.29.tar.gz
[root@server-1 src]# ll httpd-2.4.29.tar.gz
-rw-r--r--. 1 root root 8638793 Oct 21 03:39 httpd-2.4.29.tar.gz
wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.3.tar.gz
wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.6.1.tar.gz

apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便的移植

2.解压安装包

tar zxvf  httpd-2.4.9.tar.gz
tar zxvf apr-1.6.3.tar.gz
tar zxvf  apr-util-1.6.1.tar.gz

3.编译安装apr

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

编译报错

[root@server-1 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/apr-1.6.3':
configure: error: no acceptable C compiler found in $PATH**
See `config.log' for more details
[root@server-1 apr-1.6.3]# echo $?
1

解决办法:
安装gcc

[root@server-1 apr-1.6.3]# yum install gcc -y

  [root@server-1 apr-1.6.3]#make && make install

[root@server-1 apr-1.6.3]# echo $?
0

apr编译安装完成

4.编译安装apr-util

cd /usr/local/src/apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

编译报错截图
LAMP架构部署详解
LAMP架构部署详解

解决办法:
安装expat库

yum install expat-devel

安装完再次

make && make install

报错解决

5.编译安装apache

编译Apache

cd /usr/local/src/httpd-2.4.29
./configure \
--prefix=/usr/local/apache2.4 \
--with-apr=/usr/local/apr\
--with-apr-util=/usr/local/apr-util \
--enable-so \   ##支持而动态扩展模块,apache支持以一个动态模块存在,Apache本身就是一个进程服务
--enable-mods-shared=most

说明:如果在编译过程中出现,缺少某个依赖包,解决思路
yum list |grep 包
然后安装devel关键字的软件包
yum install -y 软件包

编译安装

make && make install

编译安装报错

./configure --prefix=/usr/local/apache2.4  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util  --enable-modules=most --enable-so  --enable-rewrite  --with-pcre=/usr/local/pcre --libdir=/usr/lib64
make && make install

报错截图
LAMP架构部署详解

解决办法:
缺少了xml相关的库,需要安装libxml2-devel包。直接安装并不能解决问题,因为httpd调用的apr-util已经安装好了,但是apr-util并没有libxml2-devel包支持

重新安装libxml2-devel

yum install -y libxml2-devel

删除apr-util软件包

rm -rf /usr/local/src/apr-util-1.6.1
cd /usr/local/src/

重新编译安装apr-util

tar zxvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1/
 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config
cd ..
cd httpd-2.4.29/
./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@server-1 httpd-2.4.29]# echo $?
0

报错解决

root@server-1 httpd-2.4.29]# cd /usr/local/apache2.4/
[root@server-1 apache2.4]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules

说明:
bin目录:命令执行
conf目录:配置文件所在目录
htdocs目录:默认网站访问的内容就存在这个目录下
logs日志目录:访问日志,服务报错日志
modules目录:存放apache需要的模块

root@server-1 apache2.4]# ls ./modules/
httpd.exp             mod_authz_dbd.so        mod_deflate.so              mod_log_config.so      mod_proxy_scgi.so      mod_socache_memcache.so
mod_access_compat.so  mod_authz_dbm.so        mod_dir.so                  mod_log_debug.so       mod_proxy.so           mod_socache_shmcb.so
mod_actions.so        mod_authz_groupfile.so  mod_dumpio.so               mod_logio.so           mod_proxy_wstunnel.so  mod_speling.so
mod_alias.so          mod_authz_host.so       mod_env.so                  mod_macro.so           mod_ratelimit.so       mod_ssl.so
mod_allowmethods.so   mod_authz_owner.so      mod_expires.so              mod_mime.so            mod_remoteip.so        mod_status.so
mod_auth_basic.so     mod_authz_user.so       mod_ext_filter.so           mod_negotiation.so     mod_reqtimeout.so      mod_substitute.so
mod_auth_digest.so    mod_autoindex.so        mod_file_cache.so           mod_proxy_ajp.so       mod_request.so         mod_unique_id.so
mod_auth_form.so      mod_buffer.so           mod_filter.so               mod_proxy_balancer.so  mod_rewrite.so         mod_unixd.so
mod_authn_anon.so     mod_cache_disk.so       mod_headers.so              mod_proxy_connect.so   mod_sed.so             mod_userdir.so
mod_authn_core.so     mod_cache.so            mod_include.so              mod_proxy_express.so   mod_session_cookie.so  mod_version.so
mod_authn_dbd.so      mod_cache_socache.so    mod_info.so                 mod_proxy_fcgi.so      mod_session_dbd.so     mod_vhost_alias.so
mod_authn_dbm.so      mod_cgid.so             mod_lbmethod_bybusyness.so  mod_proxy_fdpass.so    mod_session.so         mod_watchdog.so
mod_authn_file.so     mod_dav_fs.so           mod_lbmethod_byrequests.so  mod_proxy_ftp.so       mod_setenvif.so
mod_authn_socache.so  mod_dav.so              mod_lbmethod_bytraffic.so   mod_proxy_hcheck.so    mod_slotmem_shm.so
mod_authz_core.so     mod_dbd.so              mod_lbmethod_heartbeat.so   mod_proxy_http.so      mod_socache_dbm.so
[root@server-1 apache2.4]# ls ./htdocs/
index.html
[root@server-1 apache2.4]# ls ./bin/
ab         apxs      dbmmanage  envvars-std  htcacheclean  htdigest  httpd      logresolve
apachectl  checkgid  envvars    fcgistarter  htdbm         htpasswd  httxt2dbm  rotatelogs
[root@server-1 apache2.4]# ls ./logs/
[root@server-1 apache2.4]# ls ./conf/
extra  httpd.conf  magic  mime.types  original

6.查看apache加载的模块

/usr/local/apache2.4/bin/apachectl

执行上面的命令,实际上是调用

/usr/local/apache2.4/bin/httpd -M
[root@server-1 apache2.4]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.71.11.1. 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)

该命令返回的模块分为
static:静态模块
shared:动态模块

两者的区别在于,static模块是已经编译安装到/usr/local/apache2.4/bin/httpd配置文件中,而shared表示apache动态加载的模块

7.启动apache服务

[root@server-1 apache2.4]# /usr/local/apache2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.71.11.1. Set the 'ServerName' directive globally to suppress this message
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs

从报错信息得知80端口被tomcat占用,解决办法如下

[root@server-1 apache2.4]# netstat -nlp |grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      13427/java          
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      13427/java          
tcp6       0      0 :::8009                 :::*                    LISTEN      13427/java          
unix  2      [ ACC ]     STREAM     LISTENING     3801384  19113/qemu-kvm       /var/lib/libvirt/qemu/domain-25-BasicComServer/monitor.sock
unix  2      [ ACC ]     STREAM     LISTENING     34880    1/systemd            @ISCSID_UIP_ABSTRACT_NAMESPACE
unix  2      [ ACC ]     STREAM     LISTENING     29808    971/gssproxy         /run/gssproxy.sock
unix  2      [ ACC ]     STREAM     LISTENING     3801273  18365/ssh-agent      /tmp/ssh-3zLIq2SWNOcy/agent.18364
unix  2      [ ACC ]     STREAM     LISTENING     28096    1/systemd            /var/run/cups/cups.sock
[root@server-1 apache2.4]# ps aux |grep java
root      2007  0.0  0.0 112664   968 pts/0    S+   06:57   0:00 grep --color=auto java
root     13427  0.0  0.4 38957724 566844 ?     Sl   Feb10  58:26 //bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start

[root@server-1 apache2.4]# kill -9 13427
[root@server-1 apache2.4]# ps aux |grep java
root      2026  0.0  0.0 112664   968 pts/0    S+   06:57   0:00 grep --color=auto java

[root@server-1 apache2.4]# /usr/local/apache2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.71.11.1. Set the 'ServerName' directive globally to suppress this message
执行命令后,返回系列信息,不影响, 

8.查看apahce服务进程

[root@server-1 apache2.4]# ps aux |grep httpd
root      2031  0.0  0.0  70900  2192 ?        Ss   06:57   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    2032  0.0  0.0 361948  4260 ?        Sl   06:57   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    2033  0.0  0.0 361948  4260 ?        Sl   06:57   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    2034  0.0  0.0 361948  4256 ?        Sl   06:57   0:00 /usr/local/apache2.4/bin/httpd -k start
root      2120  0.0  0.0 112664   968 pts/0    S+   06:58   0:00 grep --color=auto httpd
[root@server-1 apache2.4]#

服务启动成功

六、PHP编译安装

1.下载安装包

[root@server-1 src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
--2018-03-26 13:26:44--  http://cn2.php.net/distributions/php-5.6.30.tar.gz
Resolving cn2.php.net (cn2.php.net)... 123.125.23.168, 123.125.23.171, 123.125.23.172, ...
Connecting to cn2.php.net (cn2.php.net)|123.125.23.168|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19274631 (18M) [application/x-gzip]
Saving to: ‘php-5.6.30.tar.gz’

100%[===================================================================================================================>] 19,274,631  1.46MB/s   in 16s    

2018-03-26 13:27:01 (1.16 MB/s) - ‘php-5.6.30.tar.gz’ saved [19274631/19274631]

2.解压安装包

[root@server-1 src]# tar zxvf php-5.6.30.tar.gz 

解压成功

[root@server-1 src]# echo $?
0

3.configure编译

[root@server-1 src]# tar zxvf php-5.6.30.tar.gz 
[root@server-1 src]# cd php-5.6.30/
[root@server-1 php-5.6.30]#  ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/loca/php/etc --with-mysql=/usr/local/mysql --with-dpo-mysql=/usr/local/mysql --with-mysql=/usr/local/mysql/bin/mysqlc_config  --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir  --with-freetype-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

编译报错1

checking whether to enable the SQLite3 extension... yes
checking bundled sqlite3 library... yes
checking for ZLIB support... no
checking if the location of ZLIB install directory is defined... yes
checking for zlib version >= 1.2.0.4... 1.2.7
checking for gzgets in -lz... yes
checking whether to enable bc style precision math functions... no
checking for BZip2 support... yes
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution

解决办法:

[root@server-1 php-5.6.30]# yum install -y bzip2-devel

编译报错2

checking for GD support... yes
checking for the location of libvpx... no
checking for the location of libjpeg... yes
checking for the location of libpng... yes
checking for the location of libXpm... no
checking for FreeType 2... yes
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@server-1 php-5.6.30]# yum install -y libjpeg-devel

编译报错3

hecking pcre install prefix... no
checking whether to enable FTP support... no
checking OpenSSL dir for FTP... no
checking for GD support... yes
checking for the location of libvpx... no
checking for the location of libjpeg... yes
checking for the location of libpng... yes
checking for the location of libXpm... no
checking for FreeType 2... yes
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>
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.

解决办法:

[root@server-1 php-5.6.30]# yum install -y libpng-devel

编译报错4

checking for GD support... yes
checking for the location of libvpx... no
checking for the location of libjpeg... yes
checking for the location of libpng... yes
checking for the location of libXpm... no
checking for FreeType 2... yes
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>
checking for jpeg_read_header in -ljpeg... yes
checking for png_write_image in -lpng... yes
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.
[root@server-1 php-5.6.30]# 

解决办法:

[root@server-1 php-5.6.30]# yum install -y freetype-devel

编译报错5

checking size of long... (cached) 8
checking for an ANSI C-conforming const... yes
checking whether time.h and sys/time.h may both be included... yes
checking for working alloca.h... (cached) yes
checking for alloca... (cached) yes
checking for working memcmp... yes
checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

[root@server-1 php-5.6.30]# yum install -y libmcrypt*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.sohu.com
* updates: mirrors.sohu.com
No package libmcrypt* available.
Error: Nothing to do

解决办法:
把epel-release卸载掉,重新安装epel-release
[root@server-1 php-5.6.30]# yum install libmcrypt libmcrypt-devel mcrypt mhash

编译报错6

checking for mcrypt_module_open in -lmcrypt... no
checking for mcrypt_module_open in -lmcrypt... yes
checking for MSSQL support via FreeTDS... no
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... no
configure: error: Cannot find MySQL header files under /usr/local/mysql/bin/mysqlc_config.
Note that the MySQL client library is not bundled anymore!

解决办法:
编译安装的配置文件参数写错,正确的如下

 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/loca/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-icony-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

编译成功的返回

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
configure: WARNING: unrecognized options: --with-icony-dir

4.安装

make && make install 

LAMP架构部署详解

5.查看PHP加载的模块

[root@server-1 php-5.6.30]# ls /usr/local/apache2.4/modules/libphp5.so 
/usr/local/apache2.4/modules/libphp5.so
[root@server-1 php-5.6.30]# /usr/local/php/bin/p
pear        peardev     pecl        phar        phar.phar   php         php-cgi     php-config  phpize      
[root@server-1 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加载的模块全部是静态的

关键参数说明

[root@server-1 php-5.6.30]# cp php
php5.spec            php5.spec.in         php.gif              php.ini-development  php.ini-production   

php.ini-development 和php.ini-production都是PHP的主配置文件,开发环境用php.ini-development ,生产环境用php.ini-production

6.配置php启动

[root@server-1 php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini

7.查看PHP的版本关键信息

[root@server-1 php-5.6.30]# /usr/local/php/bin/php -i |less
phpinfo()
PHP Version => 5.6.30

System => Linux server-1 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64
Build Date => Mar 26 2018 14:35:31
Configure Command =>  './configure'  '--prefix=/usr/local/php' '--with-apxs2=/usr/local/apache2.4/bin/apxs' '--with-config-file-path=/usr/loca/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-icony-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/loca/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
:

PHP5配置完成

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章