rpm实现LAMP

rpm实现LAMP部署

LAMP概述

LAMP指的Linux(操作系统)、ApacheHTTP 服务器,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web应用平台。常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。

资源类型

静态资源:原始形式与响应给客户端的结果一致; 
动态资源:原始形式通常为程序文件(为某种编程语言开发),需要运行后将生成的结果展示给客户端;

CGI

Common Gateway Interface,是外部应用程序(CGI程序)与Web服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的过程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,CGI将Web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体。

httpd+php

module:可基于模块 
    prefork:libphp 
    worker, event:libphp-zts 
FastCGI 
    php以fpm机制独立地监听在一个套接字上; 
    工作模式类似于httpd的prefork;

基于module安装LAMP

本次以CentOS 7为例进行安装,部署过程中会说明CentOS 6与CentOS 7的不同之处

安装httpd

[root@centos ~]# yum -y install httpd  #安装httpd
[root@centos ~]# systemctl start httpd.service   #CentOS 7启动服务
[root@centos ~]# service httpd start   #CentOS 6启动服务

HY8EOE9B9@QZHROX@I8G6_4.png

}_LC~SXSF7JZOF0NE()NBRD.png

安装php

[root@centos7 ~]# yum -y install php php-mysql

php配置文件:/etc/php.ini/etc/php.d/*.ini 
php:生成libphp5.so模块 支持动态解析 
php-mysql:php驱动mysql

}TMBMO)4T5L85~HDH11~0HW.png

安装mysql

[root@centos ~]# yum -y install mariadb-server  #CentOS 7
[root@centos ~]# systemctl start mariadb.service  #CentOS 7
[root@centos ~]# yum -y install mysql-server   #CentOS 6
[root@centos ~]# service mysqld start #CentOS 6

RN}%FLF7ZF{DRPUP6MG~)1S.png

M)_9FH124NC[}H@)X3ALO0T.png

初始化数据库

[root@centos7 ~]# mysql_secure_installation    #初始化配置数据库命令
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
     SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y    #是否设置root用户密码
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y   #是否删除匿名用户
... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n   #是否关闭root用户远程登录功能
... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y   #删除test库
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y   #刷新授权
... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

验证

[root@centos ~]# systemctl restart httpd.service  #重启httpd服务并验证

U{PDC)P~H[HP(KK(DKCPSMF.png

WCMDIPDJ9F_}C`G{EB(8XFI.png

基于php-fpm搭建LAMP

前面已经讲解过httpd和mysql安装,此处不再做介绍

php-fpm安装

[root@centos ~]# yum -y install php-fpm   #CentOS 7
[root@CentOS ~]# yum -y install php-fpm mod_proxy_fcgi  #CentOS 6 需要安装mod_proxy_fcgi来提供fcgi模块,由EPEL源提供

V)NT_BTE33`4{O9J]4R`OBE.png

启动php-fpm服务

[root@centos ~]# systemctl start php-fpm.service #CentOS 7
[root@centos ~]# service php-fpm start  #CentOS 6

5WH`FOJUNO_E[33X2`IOOSI.png

php-fpm配置文件

ini:配置php解释器工作环境;
   /etc/php.ini, /etc/php.d/*.ini
conf:配置fpm守护进程的工作模式;
   /etc/php-fpm.conf, /etc/php-fpm.d/*.conf

配置项:
   /etc/php-fpm.conf
       [global]
       include=/etc/php-fpm.d/*.conf   # 包含/etc/php-fpm.d/*.conf的所有配置文件
       pid = /run/php-fpm/php-fpm.pid      # 进程的pid文件路径
       error_log = /var/log/php-fpm/error.log  # 错误日志文件路径
       log_level = notice      # 定义日志文件级别
       emergency_restart_threshold = 0     # 紧急情况重启进程的条件,一般禁用
       emergency_restart_interval = 0      # 紧急情况重启进程的时间间隔,一般为禁用
       process_control_timeout = 0     # 控制进程的超时时长
       daemonize = no      # 是否运行为守护进程,在CentOS 7上可以可配置为no,因为所有进程都由systemd管理

   /etc/php-fpm.d/*.conf
       [pool-id]
       listen = 127.0.0.1:9000     # 进程所监听的端口
       listen.backlog = -1     # 超出请求时的队列长度,-1表示没有上线
       listen.allowed_clients = 127.0.0.1  # 所允许的客户端列表
       user = apache   # 运行子进程的用户
       group = apache  # 运行子进程的组
       pm = dynamic
           定义process管理机制:static, dynamic
               static:服务启动时创建出所有子进程;
               dynamic:根据用户请求量的变化来维护子进程数量;
       pm.max_children = 50    # 最大子进程数
       pm.start_servers = 5    # 服务开启时所启动的子进程数
       pm.min_spare_servers = 5    # 最少空闲子进程数
       pm.max_spare_servers = 35   # 最大空闲子进程数
       pm.max_requests = 500   # 每个子进程所响应的最大请求数

       pm.status_path = /fpm-status    # php-fpm的状态页
       ping.path = /ping   # 向服务器发送ping
       ping.response = pong # 如果服务器正常,则回复pong
       request_terminate_timeout = 0 # 定义请求超时时长,0表示无限制
       request_slowlog_timeout = 0 # 定义满请求的时间,如果达到时长,则输出至慢请求日志当中
       slowlog = /var/log/php-fpm/www-slow.log     # 慢日志文件路径
       rlimit_files = 1024     # 限制用户请求的文件数
       rlimit_core = 0     #

       php_admin_value[error_log] = /var/log/php-fpm/www-error.log # 连接池的错误日志
       php_admin_flag[log_errors] = on     # 管理功能的标志位是否打开
       php_value[session.save_handler] = files     # php基于什么方式保存session
       php_value[session.save_path] = /var/lib/php/session     # session文件的存放路径

fpm配置虚拟主机反代配置

SB}8G_1BXD%X4A9_4__(S7Y.png

4HCRKKA[VC4LKBTO(_R{B$M.png

[root@centos ~]# systemctl restart httpd.service  ##重启httpd服务

测试

]6]1W3RN@@EO$UX(P[8LHCV.png

测试状态页以及ping页面

2YQQ3{X9BFB}414X}$XJUDQ.png

状态页参数讲解

http://WEB_SERVER:PORT/pm-status
   pool:                 www    # 连接池名称
   process manager:      dynamic    # 进程管理器类型
   start time:           26/Sep/2016:15:10:26 +0800    # 启动时间
   start since:          7437    # 运行时长
   accepted conn:        6    # 连接池已经处理过的总请求数
   listen queue:         0    # 队列的长度
   max listen queue:     0     #  请求队列的最大长度
   listen queue len:     128     # socket等待队列的最大长度;
   idle processes:       4    # 空闲的进程数;
   active processes:     1    # 活跃的进程数量;
   total processes:      5     # 总进程数;
   max active processes: 1     # 连接池当中过去最大活跃进程度;
   max children reached: 0     # 进程数量达到连接池上限的次数;
   slow requests:        0 # 慢请求的数量;

其它格式的输出:
   /pm-status?json
   /pm-status?xml
   /pm-status?html
   /pm-status?full

full格式的输出:
   pid:                  33095
   state:                Idle    # 当前进程的状态,idle, running, ...
   start time:           26/Sep/2016:15:10:26 +0800    # 进程启动的日期时间
   start since:          7968  # 运行时长
   requests:             2    # 处理过的请求数量
   request duration:     112     # 请求处理过程的时长
   request method:       GET    # 请求方法
   request URI:          /pm-status?html     # 请求的URL
   content length:       0    # 请求内容的长度,POST方法才有意义
   user:                 -     # 用户
   script:               -     # php脚本;
   last request cpu:     0.00    # 最近一次请求消耗CPU
   last request memory:  262144    # 最近一次请求消耗的内存量

测试ping页面

}WZ8G32C32INO7N}V~%[`UL.png

部署应用

部署phpMyadmin

[root@centos ~]# yum -y install php-mbstring php-mcrypt php-gd  #安装php相关包
[root@centos ~]# unzip phpMyAdmin-4.0.5-all-languages.zip  #解压phpMyadmin
[root@centos ~]# mv phpMyAdmin-4.0.5-all-languages/* /var/www/html/  #将文件移动至站点根目录

测试

~D}N`{M7PYZ148V]PF@C%DL.png

Y~}Y4OTOYV59C)PT6MG1E85.png

部署wordpress

配置数据库

[root@centos7 ~]# mysql -uroot -pmageedu   #以root身份登录数据库
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 35
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> SHOW DATABASES;    #显示所有数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> CREATE DATABASE wordpress;   #创建wordpress数据库
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'%' IDENTIFIED BY 'mageedu';   #wordpress用户对wordpress数据库所有权
Query OK, 0 rows affected (0.03 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;   #刷新授权
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> quit   #退出
Bye
[root@centos7 ~]#

部署

[root@centos7 ~]# unzip wordpress-4.5.3-zh_CN.zip   #解压wordpress
[root@centos7 ~]# mv wordpress/* /var/www/html/   #mv文件至网站访问根目录
[root@centos7 ~]# cd /var/www/html/  
[root@centos7 html]# cp wp-config-sample.php wp-config.php  #生成配置文件
[root@centos7 html]# vim wp-config.php  #编辑配置文件

K6P7))_BCXAISKNTY_G8NLF.png

GTKA)P59]_@)1]H@0BVLXD1.png

部署Discuz论坛

配置数据库

[root@centos7 ~]# mysql -uroot -pmageedu
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 35
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> CREATE DATABASE bbs;  #创建bbs数据库
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON bbs.* TO 'bbs'@'%' IDENTIFIED BY 'mageedu';   #授权bbs用户对bbs数据库所有权
Query OK, 0 rows affected (0.03 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;   #刷新授权
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> quit
Bye
[root@centos7 ~]#

部署

[root@centos7 ~]# unzip Discuz_X3.2_SC_UTF8.zip  #解压
[root@centos7 ~]# mv upload/* /var/www/html/  #移至网站根目录
[root@centos7 ~]# cd /var/www/html/
[root@centos7 html]# chmod -R a+w data/ config/ uc_client/ uc_server/   #对于指定目录赋予写入权限

HHQ6LWA~M5P_2UX{U[P_VCA.png

~E`~G02J(}BMFHXKSU_F)_9.png

EG(7Y)5`8P@P%VCXTGDLB$E.png

L4A_ZPEOKHOUM9Q@@E{]V[X.png

[JDKSG$3BV]JSLJ93XJCP)7.png

原创文章,作者:zhai796898,如若转载,请注明出处:http://www.178linux.com/56969

(0)
上一篇 2016-11-02 23:02
下一篇 2016-11-02 23:27

相关推荐

  • Nginx作为web服务器的使用配置

    概述     Nginx是一款免费开源的web服务器,同时也可以作为http、imap/pop3协议进行反代服务器,本篇介绍一些nginx作为web服务器方面的相关配置,具体包含:     1、nginx基础概念介绍     2、nginx…

    Linux干货 2016-10-27
  • 文本处理工具

    分页查看文件内容 less和more命令介绍 分页查看文件内容:less和more less:一页一页地查看文件或STDIN输出   # less FILE less的快捷键:     Ctrl+u:向上翻半屏     Ctrl+d:向下翻…

    Linux干货 2016-08-07
  • sed的详细用法

    sed(Stream EDitor)是一款流编辑器,用来对文本进行过滤与替换操作。其原理是:通过文件或管道读取文件内容,但是sed默认并不直接修改源文件,而是一次仅读取文件的一行至模式空间(pattern space)根据sed指令进行编辑并输出结果后清除模式空间,即所有的操作都是在模式空间中进行的。 语法格式 sed [option]…&nb…

    Linux干货 2016-11-14
  • Linux基础学习总结(一)

    Linux 安装运行步骤: 进入\\172.16.0.1\python10          用户名:python10          密码:python10magedu 进入目录   ftp://172.16.0.1/pub/ISOs/ 下载linux系统镜像文件           CentOS-6.9-x86_64-bin-DVD1.iso     …

    Linux干货 2018-03-16
  • 硬盘分区的三种方式

    以前在初步接触linux的时候,只知道一种分区方式,现在学会了三种分区方式,所以下面就给大家简单的演示一下 ,以供参考。 第一种:fdisk /dev/sd?    具体步骤请看下图:首先有一个空的硬盘/dev/sdb, 第一步:输入命令fdisk /dev/sdb,会弹出一个帮助信息Command(m for help),意思就是m键是…

    2017-08-20