LAMP是什么?
LAMP,也就是Linux-Apache-MySQL-PHP的简称。
这里我们需要了解两个概念,静态资源和动态资源。
静态资源一般是用HTML编写的网页,实际上是一个文本文件。
静态内容通过浏览器的辅助而展示出我们所看到的网站的内容。如网站布局等。
动态资源则是需要特定的解释器翻译之后,通过服务器运行,最后返回给用户的结果。
在访问一个PHP网站时,假如我们需要登录账号,这部分则是由PHP完成,而账号密码则保存在MySQL里面。
假如用户在php网站请求登录,请求顺序是这样的:
Apache-PHP-MySQL是这样协作的
Apache有什么特色?
其实我们可以从他的名字中来理解他的一个最经典的特性。
Apache,原意为A Patchy Server。
意思是,一个打补丁、拼凑而成的服务器。
他主要的特点,就是支持DSO。Dynamic Shared Object
意思就是动态加载模块的意思。
配置文件中通过加入LoadModule <模块名字> <模块路径>来调用模块。
因为这样调用模块真的很方便,当时有许多人为Apache服务器编写模块文件。
这一点跟Nginx就有很大的不同,Nginx如果需要添加第三方模块,是要重新编译的。
另外,Apache支持MPM。Multipath Processing Modules
一般可以叫作:多路处理模块。
他有两种较为常用的模式:
Prefork模式:
我们可以拆开这个词来理解他的特性,Pre-Fork。
Fork在英文里面其实就是产生子进程的意思。
Pre在英文中常有预先的意思,例如Preview的意思则是预演。
Prefork模式的特点:
在空闲时通过预先产生多个子进程,通过进程来接受用户的请求。
一般认为此种模式的好处有两个:
a.假如平时流量少,但有突如其来的并发请求,Prefork模式可以更好地应对。
因为避免了在响应请求时,为了加大响应量再产生大量进程,而对资源产生额外的开销。
b.而在进程因为某些原因崩溃的时候,不会影响到其他的进程。
注意:PHP一般都需要运行在Prefork模式下。
Worker模式的特点:
相对于Prefork模式,Worker模式也有使用子进程的概念。
但是Worker的特色在于他在进程内部产生多个线程,使用线程来处理请求。
一般认为worker模式的好处在于:
a.使用线程来响应,能够接受更多的请求。
所以在并发的性能上,Worker模式的性能比Prefork模式更好。
b.使用线程,开销比使用进程要小。
但是相比较于Prefork模型,由于使用了线程,稳定性不如Prefork。
因为当线程出现问题的时候,所在进程也会受到影响。
由于Apache的网络IO模型的原因,Prefork模式和Worker模式最多同时响应1024个请求。
使用LAMP架设一个WordPress个人博客
这一次由于在单机上面操作,并没有拓扑图。
本文的实验中,系统使用CentOS7.1,数据库:MariaDB-5.5.50
注意:实验中关闭了selinux,以及iptables。
(1)安装LAMP具体的包
[root@node3 ~]yum install httpd mariadb-server mariadb php php-mysql
httpd是Apache的程序名字。MariaDB-server负责MySQL的数据存储
php组件用于解析php请求,php-mysql组件用于php于mariadb交互。
(2)启动Apache和MySQL服务并设置为开机启动。
[root@node3 ~]# systemctl start mariadb.service [root@node3 ~]# systemctl start httpd.service [root@node3 ~]# systemctl enable mariadb.service [root@node3 ~]# systemctl enable httpd.service
(3)查看httpd是否正常运行
![](https://i-blog.csdnimg.cn/blog_migrate/282fce1c4201e1a49ff28a00d4809d70.jpeg)
Apache-test-page.jpg
当什么网站都没有的时候,在浏览器中输入IP地址就会出现一个测试页.
证明Apache运行正常
(4)到官方网站下载WordPress,并解压到特定目录。
官方网站的下载地址很明显,可以直接在机器上使用wget命令。
a.下载[root@node3 ~]# wget https://wordpress.org/latest.tar.gz--2016-12-1115:56:17-- https://wordpress.org/latest.tar.gzResolving wordpress.org (wordpress.org)...66.155.40.249,66.155.40.250Connecting to wordpress.org (wordpress.org)|66.155.40.249|:443... connected.HTTP request sent, awaiting response...200OKLength:7993186(7.6M) [application/octet-stream]Saving to: ‘latest.tar.gz’100%[======================================================>]7,993,18636.1KB/sin2m36s b.解压[root@node3 ~]# tar xvf /root/latest.tar.gz -C /var/www/html/
(5)修改文件属主
[root@node3 ~]# chown -R apache.apache /var/www/html/wordpress/[root@node3 ~]# ll !$ll /var/www/html/wordpress/total184-rw-r--r--.1apache apache418Sep252013index.php-rw-r--r--.1apache apache19935Mar62016license.txt-rw-r--r--.1apache apache7433Dec215:04readme.html-rw-r--r--.1apache apache5447Sep2805:36wp-activate.phpdrwxr-xr-x.9apache apache4096Dec702:40wp-admin-rw-r--r--.1apache apache364Dec192015wp-blog-header.php-rw-r--r--.1apache apache1627Aug2920:00wp-comments-post.php-rw-r--r--.1apache apache2853Dec162015wp-config-sample.phpdrwxr-xr-x.4apache apache49Dec702:40wp-content-rw-r--r--.1apache apache3286May252015wp-cron.phpdrwxr-xr-x.18apache apache8192Dec702:40wp-includes-rw-r--r--.1apache apache2422Nov2110:46wp-links-opml.php-rw-r--r--.1apache apache3301Oct2511:15wp-load.php-rw-r--r--.1apache apache33939Nov2110:46wp-login.php-rw-r--r--.1apache apache7841Nov2110:46wp-mail.php-rw-r--r--.1apache apache16250Nov2913:39wp-settings.php-rw-r--r--.1apache apache29896Oct1912:47wp-signup.php-rw-r--r--.1apache apache4513Oct1503:39wp-trackback.php-rw-r--r--.1apache apache3065Sep100:31xmlrpc.php
因为httpd.conf中定义了用户和组,所以需要将网站文件的属主属组都改为对应用户``默认都是apache
(6)数据库创建一个数据库,并授权一个用户。
[root@node3 ~]# mysql Welcome to the MariaDB monitor. Commands endwith; or \g.Your MariaDB connection id is2Server version:5.5.50-MariaDB MariaDB ServerCopyright (c)2000,2016,Oracle, MariaDB Corporation Ab and others.Type'help;'or'\h'forhelp. Type'\c'to clear the current input statement.MariaDB [(none)]> create database wordpress;Query OK,1row affected (0.00sec)MariaDB [(none)]> grant all on wordpress.* to'wordpress'@'%'identified by'wordpress';Query OK,0rows affected (0.00sec)MariaDB [(none)]> flush privileges;Query OK,0rows affected (0.00sec)MariaDB [(none)]>
(7)修改httpd的配置文件,将网站设置为虚拟主机。
<VirtualHost *:80> DocumentRoot /var/www/html/wordpress/ ServerName node3.bc.com ErrorLog"/var/log/httpd/node3-err_log"CustomLog"/var/log/httpd/node3-access_log"common</VirtualHost>
(8)图形化界面,设置mysql地址,主机地址和密码。
有两种方式,任选其一。
a.直接配置安装wordpress。
配置文件在网站根目录下,此处为/var/www/html/wordpress/wp-config.php
vim /var/www/html/wordpress/wp-config.php/** The name of the database for WordPress */define('DB_NAME','wordpress');/** MySQL database username */define('DB_USER','wordpress');/** MySQL database password */define('DB_PASSWORD','wordpress');/** MySQL hostname */define('DB_HOST','192.168.2.203');/** Database Charset to use in creating database tables. */define('DB_CHARSET','utf8mb4');/** The Database Collate type. Don't change this if in doubt. */define('DB_COLLATE','');
b.也可以直接在浏览器上面访问主机地址
![](https://i-blog.csdnimg.cn/blog_migrate/c54b6042a40ec11b544fa08adb5973a5.jpeg)
选择语言
![](https://i-blog.csdnimg.cn/blog_migrate/a33bc9dc6ebee0841cc109978abc3975.jpeg)
准备开始!
![](https://i-blog.csdnimg.cn/blog_migrate/e9c80520ad67f14b1bd915a015abca59.jpeg)
设置刚才设置的数据库和用户
![](https://i-blog.csdnimg.cn/blog_migrate/1ae95cc9c53858b2832b16789582db96.jpeg)
正常使用!
至此,我们已经成功地安装LAMP并架设了一个十分常用的个人博客。
下一篇文章,我们将会比较Apache和Nginx,并用Nginx搭建一个phpMyAdmin。见http://www.linuxidc.com/Linux/2017-10/147556.htm
下面关于LAMP相关的内容你可能也喜欢:
LAMP平台安装Xcache和Memcached加速网站运行http://www.linuxidc.com/Linux/2015-06/118835.htm
CentOS 7下搭建LAMP平台环境http://www.linuxidc.com/Linux/2015-06/118818.htm
CentOS 7.3下配置LAMP实现WordPresshttp://www.linuxidc.com/Linux/2017-07/145947.htm
Ubuntu14.04 配置 LAMP+phpMyAdmin PHP(5.5.9)开发环境http://www.linuxidc.com/Linux/2014-10/107924.htm
LAMP结合NFS构建小型博客站点http://www.linuxidc.com/Linux/2015-08/121029.htm
CentOS7下安装部署LAMP环境http://www.linuxidc.com/Linux/2016-04/130653.htm
CentOS 7 上安装(LAMP)服务 Linux,Apache,MySQL,PHPhttp://www.linuxidc.com/Linux/2017-05/143868.htm
Ubuntu Server 14.04 LTS下搭建LAMP环境图文详解http://www.linuxidc.com/Linux/2016-12/138758.htm
Ubuntu Server 16.04下配置LAMP环境http://www.linuxidc.com/Linux/2016-12/138757.htm
在Ubuntu 17.04 上安装搭建 LAMP 组件环境http://www.linuxidc.com/Linux/2017-07/145644.htm
CentOS 6.7编译安装LAMP 详解http://www.linuxidc.com/Linux/2017-03/141244.htm
Ubuntu 16.04搭建LAMP开发环境http://www.linuxidc.com/Linux/2016-10/136327.htm