linux-LAMP

linux-LAMPlamp安装,编译安装lamp

LAMP:

l:linux

a:apache(httpd)

m:mysql,mariadb

p:php,jsp

WEB资源类型:

     静态资源:原始形式与响应结果一致;

     动态资源:原始形式通常是程序文件(某种编程语言开发的程序文件),需要运行后将运行生成的结果呈现给用户;

     客户端技术:js

     服务端技术:php, jsp, …

CGI:Common Gateway Interface

CIG是一种协议,定义了客户端(httpd)与服务端(特定的应用程序服务进程)交换数据的一种规范;

服务器端技术框架:

web server:httpd, …

application server:php, perl, python, ruby, java(jsp), …

data server:

SQL:Oracle, SQL Server, MySQL, PostgreSQL, SQLite, …

NoSQL:

K/V

Document 

Column

Graph

开源领域:

httpd+php+mysql: amp

httpd+jsp+mysql: amt

jsp:tomcat, resin, jetty, websphere, weblogic, …

php编程语言,基于此语言存在很多开源应用程序;嵌入式编程语言,可直接嵌入至html文档中,而非由php代码生成html标签;

wordpress, …

httpd:接受用户的web请求,静态资源则直接响应,动态资源为php脚本,对此类资源的请求将交由php来运行

php:运行php程序

MariaDB:数据管理系统

http与php结合的方式:

CGI

FastCGI

modules(把php编译成为httpd的模块)

MPM:

 prefork;libphp5.so

 event,worker,libphp5-zts.so

安装操作

CentOS 7:

yum install php php-mysql mariadb-server httpd

测试页:

phpinfo.php 

<?php 
phpinfo();
?>

httpd+php:

module

httpd的MPM分两类:

进程式:prefork

线程式:worker, event

CGI:

FastCGI: fcgi

httpd+fcgi(module)

php-fpm (server)

部署应用:

discuzX, phpMyAdmin

MySQL:

  C/S架构

Server: mysqld_safe, 3306/tcp

Client: mysql

mysql [OPTIONS]
    -hSERVER
    -uUSERNAME
    -pPASSWORD

mysql> 提示符下的可用命令

客户端命令:

help可获取命令列表

\?

服务端命令:通过mysql协议发往服务端运行,并收取其响应结果;

此类命令都必须有命令结束符;通常可称为SQL语句;

DDL:Data Defination language

CREATE, ALTER, DROP

DML:Data Manipulating language

INSERT, DELETE, SELECT, UPDATE

grant/revoke

授权命令:

GRANT ALL [PRIVILEGES] ON db.tbl TO 'username'@'host'  IDENTIFIED BY 'password';

db.tbl:

        db:数据名字,可用*通配;

        tbl:表名称,可用*通配;

wpdb.*:wpdb数据库的所有表;

        *.*:所有库的所有表;

        wpdb.users:wpdb库的users表;

username@host:

        username:用户名,字符串;

        host:用户可通过哪些客户端主机连接当前mysql server;可使用通配符;

        %:任意长度的任意字符;

        _:任意单个字符;

dzuser@'10.1.%.%'

配置文件:ini风格的配置文件

/etc/my.cnf, /etc/my.cnf.d/*.cnf

[mysqld]
skip_name_resolve = ON
innodb_file_per_table = ON

首次启动时,配置安全选项:

mysql_secure_installation 

php测试代码

<?php

phpinfo();

?>

php连接mysql的测试代码:

<?php
    $conn=mysql_connect('172.0.0.1','testuser','passwd');
    if($conn)
        echo "ok";
    else
        echo "fail";
?>

快速部署amp

Centos 7:

Modules: (1)程序包:httpd,php,php-mysql,mariadb-server

FastCGI: (2)程序包:httpd,php-fpm,php-mysql,mariadb-server

Centos 6:

httpd,php,php-mysql,mysql-server

php:

脚本语言解释器

配置文件: /etc/php.ini,/etc/php.d/*.ini

配置文件在php解释器启动时被读取,因此,对配置文件的修改如何生效?

Modules : 重启httpd服务

FastCGI : 重启php-fpm服务

ini:

[foo]:Section Header

directive=value

注释符:较新的版本中,已经完全使用;进行注释

# : 纯粹的注释信息

; : 用于注释可启用的directive

php.ini 的核心配置选项文档: http://php.net/manual/zh/ini.core.php 

php.ini 配置选项列表: http://php.net/manual/zh/ini.list.php

mariadb(mysql):

数据模型:层次模型,网状模型,关系模型

关系模型:

二维关系:

表:row,column

索引:index

视图:view

SQL接口:Structured Query Language

类似于OS的shell接口,也提供了编程功能;

ANSI : SQL标准,SQL-86,SQL-03

DDL : Data Defined Language

CREATE,ALTER,DROP

DML : Data Manapulating Language

INSERT,DELETE,UPDATE,SELECT

编程接口:选择,循环

SQL代码:

存储过程: procedure

存储函数: function

触发器: trigger

事件调度器: event scheduler

例程: routine

用户和权限:

用户:用户名和密码

权限:管理类,数据库,表,字段级别

DBMS : DataBase Manager System

RDBMS : Relational

MySql : 单进程,多线程

用户连接:通过线程来实现的

线程池:

MYSQL操作:

mysql -h127.0.0.1 -uroot -proot



GRANT ALL ON ultrax.* TO 'dzuser'@'127.0.0.1' IDENTIFIED BY 'dzpass';

GRANT ALL ON ultrax.* TO 'dzuser'@'localhost' IDENTIFIED BY 'dzpass';

CREATE DATABASE ultrax;

更改root密码:

use mysql

UPDATE user SET password=PASSWORD('root') WHERE user='root';

FLUSH PRIVILEGES;

练习:分别使用CentOS 7和CentOS 6实现以下任务

(1) 配置三个基于名称的虚拟主机;

(a) discuzX

(b) wordpress

(c) https: phpMyAdmin

(2) 对discuzX的主页做压测;

分别给出并发10, 100, 200, 500等每秒的响应数;

Centos 7:

linux-LAMP

在 /etc/httpd/conf.d/ 目录下创建一个虚拟主机配置文件

<VirtualHost *:80>
        ServerName dis.nineven.com
        DocumentRoot /web/apps/dis
        <Directory /web/apps/dis >
                Options None
                AllowOverride None
                Require all granted
        </Directory>
</VirtualHost>
<VirtualHost *:80>
        ServerName wp.nineven.com
        DocumentRoot /web/apps/wp
        <Directory /web/apps/wp >
                Options None
                AllowOverride None
                Require all granted
        </Directory>
</VirtualHost>

linux-LAMP

自签CA证书

linux-LAMP

在http服务器上创建key

linux-LAMP

将httpd.scr 传到CA服务器去签证

linux-LAMP

修改ssl配置文件

vim /etc/httpd/conf.d/ssl.conf

linux-LAMP

创建对应的目录

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

然后开始安装dis论坛

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

安装wp的过程和这一样,先创建数据库和用户,然后安装

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

linux-LAMP

php相关信息

php配置文件:

/etc/php.ini, /etc/php.d/*.ini 

ini:

[foo]:Section Header

directive = value

注释符:#, ;

php.ini的核心配置选项文档:PHP: php.ini 核心配置选项说明 – Manual    

php.ini配置选项列表:PHP: php.ini 配置选项列表 – Manual

php-fpm : fastcgi process manager

安装配置:

yum install php-fpm

Unit file:/usr/lib/systemd/system/php-fpm.service

配置文件:/etc/php-fpm.conf, /etc/php-fpm.d/*.conf

主程序:/usr/sbin/php-fpm

配置:

路径 : /etc/php-fpm.conf

[global]
pid = /run/php-fpm/php-fpm.pid
error_log = /var/log/php-fpm/error.log
log_level = notice
daemonize = no
[pool_id]
listen = 127.0.0.1:9000  #监听端口
listen.backlog = -1
listen.allowed_clients = 127.0.0.1  #允许访问的ip地址
user = apache
group = apache
pm = dynamic     #定义processor管理机制:static, dynamic
pm.max_children      #最大子进程数量;连接池的最大容量;
pm.start_servers         #服务启动时所启动的子进程数量;
pm.min_spare_servers
pm.max_spare_servers
rlimit_files = 1024
rlimit_core = 0
pm.status_path = /status   #状态信息
ping.path = /ping
ping.response = pong
php_value[session.save_path] = /var/lib/php/session     #session的存储位置

配置示例:

vim /etc/httpd/conf.d/fcgi.conf
<VirtualHost *:80>
        ServerName www.xixi.com
        DocumentRoot "/vhosts/www"
        <Directory "/vhosts/www">
                Options None
                AllowOverride None
                Require all granted
        </Directory>
        ProxyRequests Off
        ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/vhosts/www/$1
        ProxyPassMatch ^/(ping|status)/?$ fcgi://127.0.0.1:9000/$1
        DirectoryIndex index.php
</VirtualHost>
vim /etc/php-fpm.d/www.conf

linux-LAMP

linux-LAMP

status输出:

pool:                 www     #连接池名称
process manager:      dynamic  #进程管理器类型
start time:           14/Oct/2016:11:16:24 +0000   #启动日期时间 
start since:          147  # 运行时长
accepted conn:        9  # 连接池已经处理过的请求数
listen queue:         0  # 请求队列长度
max listen queue:     0 # 请求队列的最大长度
listen queue len:     128 # socket等待队列的长度
idle processes:       4  # 空闲进程数量
active processes:     1 # 活跃的进程数量
total processes:      5 # 连接池中的总进程数量
max active processes:  2 # 连接池中最大的活跃进程数量
max children reached:  0 # 达到连接池中最大进程数量限制的上限的次数
slow requests:        0 :启用了slow-log时,记录慢请求的数量

linux-LAMP

其它格式的输出:

  • /status?json
  • /status?xml
  • /status?html
  • /status?full

full格式的输出:

linux-LAMP

可以通过 & 符号组合输出信息

linux-LAMP

注意:部署需要用到session的应用时,其session的默认存储位置 ,确保此目录存在,且运行用户有写入权限;

fcgi协议反代:

ProxyRequests Off

ProxyPass 

ProxyPassMatch ^(URL_PATTERN)$  fcgi://fcgi_server:port/PATH/TO/DIR/$1

php配置文件:/etc/php.ini, /etc/php.d/*.ini 

fpm配置文件:/etc/php-fpm.conf, /etc/php-fpm.d/*.conf

编译安装lamp:

(1) 系统环境:CentOS 6, 7

httpd依赖于apr和apr-util

apache portable runtime 

(2) 开发环境;

Development Tools, Server Platform Development

(3) 各程序的版本:

httpd: 2.2, 2.4

php:5.x

mysql:5.1, 5.5, 5.6, 5.7, 5.8,

mariadb: 5.x, 10.x

(4) httpd+php 

modules: –with-apxs=

prefork:libphp5.so

worker, event:libphp5-zts.so

fpm:

5.3.3-, 手动打上fpm patch;

5.3.3+:自带了fpm, 编译时只需要使用–fpm选项;

过程:

安装MySQL:

预制的二进制程序包:

os vendor:mariadb-devel或mysql-devel;

项目官方:

二进制格式程序包:展包即用;

源代码:编译安装;

通用二进制格式包的安装步骤:

groupadd -r mysql
useradd -g mysql -r mysql
tar xf mariadb-VERSION-linux-x86_64.tar.gz -C /usr/local 
cd /usr/local
ln -sv mariadb-VERSION-linux-x86_64 mysql
cd mysql
chown -R root:mysql ./*



mkdir /mydata/data -pv
chown mysql:mysql /mydata/data

scripts/mysql_install_db --user=mysql --datadir=/mydata/data

cp support-files/my-large.cnf  /etc/my.cnf

修改配置:

[mysqld]

...

datadir = /mydata/data  #修改数据存储位置
cp  support-files/mysql.server  /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld


chkconfig --add mysqld
service mysqld start

安装httpd-2.4

yum groupinstall "Development Tools" "Server Platform Development" 
yum install pcre-devel openssl-devel libevent-devel  apr-devel apr-util-devel
./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork --with-pcre --with-zlib --with-apr=/usr --with-apr-util=/usr

make -j 4 # 4颗cpu编译,多cpu编译可以加快速度
make install


apachectl start

安装php5:

yum install gd-devel freetype-devel libmcrypt-devel libxml2-devel
./configure --prefix=/usr/local/php --with-mysql  --with-openssl --with-mysqli=/usr/bin/mysql_config --enable-mbstring --enable-xml --enable-sockets --with-freetype-dir --with-gd --with-libxml-dir=/usr --with-zlib --with-jpeg-dir --with-png-dir --with-mcrypt --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/etc/php.ini --with-config-file-scan-dir=/etc/php.d/

make -j 4 #如果电脑多核心,可以加快编译速度
make install
cp php.ini-production /etc/php.ini 
mkdir /etc/php.d/

注意:如果httpd使用线程模型MPM,需要额外的–enable-maintainer-zts选项;

注意:如果要以fpm方式运行php,需要编译时移除–with-apxs选项,额外添加–enable-fpm选项;

注意:如果是独立安装的mysql-server, 假设安装在/usr/local/mysql目录下,则需要使用类似如下的.configure命令:

./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql  --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --enable-xml --enable-sockets --with-freetype-dir --with-gd --with-libxml-dir=/usr --with-zlib --with-jpeg-dir --with-png-dir --with-mcrypt --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/etc/php.ini --with-config-file-scan-dir=/etc/php.d/

整合php至httpd上:

httpd.conf配置文件中:

AddType application/x-httpd-php .php 

DirectoryIndex index.php index.html 

今天的文章linux-LAMP分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:http://bianchenghao.cn/24383.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注