设为首页 收藏本站
查看: 1350|回复: 0

lamp 基础应用

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-10-13 08:40:58 | 显示全部楼层 |阅读模式
========================================================================
概述:




Lamp介绍
★资源类型:
  • 静态资源:
       原始形式与响应给客户端的结果一致;服务端仅仅提供一些内容展示功能,如网页内容展示,图片列表,动画播放等,服务端不需要和客户端进行互动,所有的资源可以直接去获取,但是无法进行资源上传;
  • 动态资源:
       原始形式通常为程序文件(为某种编程语言开发),需要运行后将生成的结果展示给客户端;即:服务端可以与客户端进行互动,如一些论坛等,这些web程序是由web程序来开发的,常见的如PHP程序配合MySql数据库进行信息的检索与提交写入等操作。

       客户端技术:javascript
       服务端技术:php, jsp, ...      

★CGI:Common Gateway Interface 通用网关接口协议
  • CGI是一种协议,定义了客户端(web服务器程序)与服务端(特定的应用程序服务进程)进行数据交换的一种规范;


★程序:指令+数据
  • 指令:代码
  • 数据:存储

      文件系统:单机文件,分布式文件系统;
       DBMS:数据库管理系统
          SQL:关系数据库
             Oracle,
             SQL Server:
             DB2,
             MySQL,
             PostgreSQL(PGSQL),
             MariaDB,
             Percona-Server, ...
          NoSQL:非关系型数据库
             KV:redis, ...
             Document:MongoDB, ...
             Column:HBase, ...
             Graph:
★开源领域
  • amp:httpd+php/perl/python+mysql/mongodb
  • ams:httpd+tomcat+mysql/mongodb
       jsp:tomcat, jetty, resin, jboss, websphere, weblogic

php
★PHP
  • 编程语言,嵌入式编程语言,
  • 高度模块化(extensions),
  • 配置文件(/etc/php.ini, /etc/php.d/*.ini);
  • PHP是通用服务器端脚本编程语言,主要基于web开发以实现动态web页面,它也是最早实现将脚本嵌入HTML源码文档中的服务器端脚本语言之一。同时php还提供了一个命令行接口,因此,其也可以在大多数系统上作为一个独立的shell来使用。
  • php应用程序:
      开源代表:wordpress, discuzX, phpwind, drupal...

1
2
3
4
5
6
7

    ...
          code
   ?>
    ...




★httpd+php:三种结合方式
  • CGI 不常用
  • Module 模块机制

      prefork:php模块为:libphp
      worker, event:php模块为:libphp-zts
注意:
     使用模块化的方式是httpd和php结合的最好方式;在使用之前要首先判断httpd用的是那个模块(MPM),再才能决定安装哪个程序包。
  • FastCGI

      php以fpm机制独立地监听在一个套接字上;
      工作模式类似于httpd的prefork

演示如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@centos7 ~]# yum install php -y # 安装php
[iyunv@centos7 ~]# rpm -ql php
/etc/httpd/conf.d/php.conf
/etc/httpd/conf.modules.d/10-php.conf
/usr/lib64/httpd/modules/libphp5.so
/usr/share/httpd/icons/php.gif
/var/lib/php/session

[iyunv@centos7 ~]# systemctl reload httpd # 重启httpd
[iyunv@centos7 ~]# vim /var/www/html/phpinfo.php # 编辑文件,提供一个php页面
  1   2       phpinfo()
  3 ?>



浏览器查看如下:
wKioL1f888Kzl9DEAACKQlYk1jg134.png
MysQL
1)相关介绍
★插件式存储引擎
★C/S架构的
  • Server:mysqld, mysqld_safe, mysqld_multi
  • Client:mysql

★安装Mysql
  • CentOS 6: mysql-server, mysql
  • CentOS 7: mariadb-server, mariadb

★MysQL版本:
  • Community Edtion
  • Enterprise Ddtion
  • CentOS 6使用的是Orecle收购sun之前的版本为5.1
      额外添加的配置项:
       [mysqld]
        ...
       skip_name_resolve
       innodb_file_per_table=ON

★MariaDB:
  • CentOS 7 使用的就是mariad
  • 配置文件:/etc/my.cnf, /etc/my.cnf.d/*.cnf
  • 额外添加的配置项:

       [mysql]
       skip_name_resolve = ON 跳过主机名解析
        innodb_file_per_table = ON
  • 默认连接的主机为当前主机,管理员用户为root,密码为空;
  • 首次安装后建议使用:
        mysql_secure_installation命令进行安全设定;

★客户端连接mysql server:  
  mysql --> mysql protocol --> mysql server
  语法:mysql [options] db_name
  选项:-hHOST
        -uUSERNAME
        -pPASSWORD
★mysql的用户账号:username@host
  • username:用户名
  • host:此用户可通过哪些客户端主机登录当前服务器上的mysql服务;主机名和IP地址属性于不同的主机;
  • host可使用通配符:

       _:任意单个字符;
       %:任意长度以的任意字符;
       举例:root@'10.1.%.%' 表示10.1网络段的任意主机都可登录
★mysql> 提示符下可接受输入mysql命令,分两类
  • 客户端命令

      help可获取命令列表
  • 服务端命令:SQL语句,必须使用语句结束符,默认为分号;
       DDL(数据定义语言):CREATE, ALTER, DROP
       DML:INSERT, DELETE, UPDATE, SELECT(增,删,改,查)
      GRANT/REVOKE (授权和取消授权)

授权命令:
wKioL1f-QILAPdfaAAA_lPwdZJo997.png


★数据库的基本操作:
  • CREATE DATABASE db_name; 创建数据库
  • DROP DATABASE db_name;    删除数据库


演示如下:
mysql配置启动
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[iyunv@CentOS6 ~]# vim /etc/my.cnf
  1 [mysqld]
  2 datadir=/var/lib/mysql
  3 socket=/var/lib/mysql/mysql.sock
  4 user=mysql
  5 # Disabling symbolic-links is recommended to prevent assorted sec
    urity risks
  6 symbolic-links=0
  7 skip_name_resolve  # 添加项
  8 innodb_file_per_table=ON  # 添加项
  9
10 [mysqld_safe]
11 log-error=/var/log/mysqld.log
12 pid-file=/var/run/mysqld/mysqld.pid

[iyunv@CentOS6 ~]# service mysqld  start # 启动



MariaDB配置启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  [iyunv@centos7 ~]# vim /etc/my.cnf # 编辑配置文件
  1 [mysqld]
  2 datadir=/var/lib/mysql
  3 socket=/var/lib/mysql/mysql.sock
  4 # Disabling symbolic-links is recommended to prevent assorted sec
    urity risks
  5 symbolic-links=0
  6 # Settings user and group are ignored when systemd is used.
  7 # If you need to run mysqld under a different user or group,
  8 # customize your systemd unit file for mariadb according to the
  9 # instructions in http://fedoraproject.org/wiki/Systemd
10 skip_name_resolve = ON     # 添加左边这两行
11 innodb_file_per_table = ON
12
13 [mysqld_safe]
14 log-error=/var/log/mariadb/mariadb.log
15 pid-file=/var/run/mariadb/mariadb.pid
16
17 #
18 # include all files from the config directory
19 #
20 !includedir /etc/my.cnf.d

  # 保存退出,启动mariadb
[iyunv@centos7 ~]#  systemctl start mariadb
[iyunv@centos7 ~]# ss -tnl # 查看监听端口3306
State       Recv-Q Send-Q                                      Local Address:Port                                                     Peer Address:Port              
LISTEN      0      50                                                      *:3306                                                                *:*                  
LISTEN      0      128                                                     *:22                                                                  *:*                  
LISTEN      0      128                                             127.0.0.1:631                                                                 *:*                  
LISTEN      0      100                                             127.0.0.1:25                                                                  *:*                  
LISTEN      0      128                                             127.0.0.1:6010                                                                *:*                  
LISTEN      0      128                                             127.0.0.1:6011                                                                *:*                  
LISTEN      0      128                                                    :::8080                                                               :::*                  
LISTEN      0      128                                                    :::80                                                                 :::*                  
LISTEN      0      128                                                    :::22                                                                 :::*                  
LISTEN      0      128                                                   ::1:631                                                                :::*                  
LISTEN      0      128                                                    :::8088                                                               :::*                  
LISTEN      0      100                                                   ::1:25                                                                 :::*                  
LISTEN      0      128                                                   ::1:6010                                                               :::*                  
LISTEN      0      128                                                    :::443                                                                :::*                  
LISTEN      0      128                                                   ::1:6011                                                               :::*      

[iyunv@centos7 ~]# mysql # 现在可以直接使用mysql命令即连接到mysql服务器上
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 2
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)]> Ctrl-C -- exit!
Aborted



首次安装进行安全设定:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
[iyunv@centos7 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 6
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)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> SELECT user,host,password FROM user;
+------+-----------+----------+
| user | host      | password |
+------+-----------+----------+
| root | localhost |          |  # 可以看到root用户只能基于本地登录,且密码为空
| root | centos7   |          |
| root | 127.0.0.1 |          |
| root | ::1       |          |
|      | localhost |          |
|      | centos7   |          |
+------+-----------+----------+
6 rows in set (0.00 sec)

MariaDB [mysql]> EXIT
Bye

# 安全设定如下:
[iyunv@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 # 要不要给管理员设定密码
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 #要不要禁止管理员远程登录
... 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] n # 要不要删除测试数据库
... skipping.

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!

[iyunv@centos7 ~]# mysql # 直接登录发现已经登陆不进去了
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[iyunv@centos7 ~]# mysql -p # 输入密码才可访问
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 15
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)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> SELECT user,host,password FROM user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *41EE0F8759D5340036B009143E1727DB5787A448 |
| root | centos7   | *41EE0F8759D5340036B009143E1727DB5787A448 |
| root | 127.0.0.1 | *41EE0F8759D5340036B009143E1727DB5787A448 |
| root | ::1       | *41EE0F8759D5340036B009143E1727DB5787A448 |
+------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)

MariaDB [mysql]> EXIT
Bye




1)如上,amp都有了,但是要想php连接mysql还需要安装一个专用的驱动
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[iyunv@centos7 ~]# yum info php-mysql
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
Name        : php-mysql
Arch        : x86_64
Version     : 5.4.16
Release     : 36.el7_1
Size        : 232 k
Repo        : installed
From repo   : CDROM
Summary     : A module for PHP applications that use MySQL databases
URL         : http://www.php.net/
License     : PHP
Description : The php-mysql package contains a dynamic shared object that will add
            : MySQL database support to PHP. MySQL is an object-relational database
            : management system. PHP is an HTML-embeddable scripting language. If
            : you need MySQL support for PHP applications, you will need to install
            : this package and the php package.

[iyunv@centos7 ~]# yum install  php-mysql -y
[iyunv@centos7 ~]# rpm -ql  php-mysql
/etc/php.d/mysql.ini
/etc/php.d/mysqli.ini
/etc/php.d/pdo_mysql.ini
/usr/lib64/php/modules/mysql.so
/usr/lib64/php/modules/mysqli.so
/usr/lib64/php/modules/pdo_mysql.so

# php增加模块了,所以需要重启php,因为php是装在httpd之上的,所以要重启httpd服务;
#注意:实际生产环境中服务是不能随便重新启动的,这些要在要在我们部署完成后上线之前做好
[iyunv@centos7 ~]# systemctl restart httpd



测试如下:
1
2
3
4
5
6
7
8
9
[iyunv@centos7 ~]# vim /var/www/html/php-mysql.php
  1   2         $conn = mysql_connect('127.0.0.1','root','134296');
  3         if ($conn)
  4                echo 'success';
  5         else
  6                echo 'failure';
[iyunv@centos7 ~]# ls /var/www/html
admin  lastlog.txt  messages.txt  phpinfo.php  php-mysql.php  test.html



浏览器访问如下:
wKiom1f-SV-SPc1ZAAAw2kTXgQM953.png
关闭服务器  # systemctl stop mariadb,再访问
wKiom1f-SgPR8aURAABIruBBPAs785.png
     如上,lamp整个环境部署成功

lamp环境快速部署
★CentOS 7:
  • # yum install mariadb-server httpd php php-mysql
  • # systemctl start httpd.service mariadb.service

★CentOS 6:
  • # yum install httpd php php-mysql mysql-server
  • # service httpd start
  • # service mysqld start

★php应用程序:
  开源代表:wordpress, discuzX, phpwind, drupal...

如下:应用程序部署在lamp环境中



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-285176-1-1.html 上篇帖子: LAMP架构搭建以及基于LAMP架构的主流论坛和博客搭建过程... 下篇帖子: centos LAMP环境搭建
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表