1、作甚LAMP
2、LAMP的架构以及通信过程
3、LAMP的搭建过程(rpm包)

4、基于LAMP搭建wordpress博客
一、作甚LAMP
LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际盛行的Web框架,该框架包括:Linux操作系统,Apache网络做事器,MySQL数据库,Perl、PHP或者Python编程措辞,所有组成产品均是开源软件,是国际上成熟的架构框架,很多盛行的商业运用都是采纳这个架构,LAMP具有通用、跨平台、高性能、低价格的上风,因此LAMP无论是性能、质量还是价格都是企业搭建网站的首选平台。
二、LAMP的架构以及通信过程
LAMP的架构:
LAMP是一个多C/S架构的平台,最低级为web客户端基于TCP/IP通过http协议发起传送,这个要求可能是动态的,也可能是静态的。
以是web做事器通过发起要求的后缀来判断,如果是静态的资源就由web做事器自行处理,然后将资源发给客户端。如果是动态这时web做事器会通过CGI(Common Gateway interface)协议发起给php。
这里但是如果php因此模块形式与Web做事器联系。那么他们是通过内部共享内存的办法。如果是php单独的放置与一台做事器,那么他们是通过sockets套接字监听的办法通信(这又是一个C/S架构)。
这时php会相应的实行一段程序,如果在实行程序时,须要用到数据。那么php就会通过mysql协议发送给mysql做事器(也可以看作是一个C/S架构)。由mysql做事器处理,将数据供给php程序。
lamp流程:
1. 用户发送http要求到达httpd做事器
2. httpd解析url获取须要的资源的路径,通过内核空间读取硬盘资源,如是静态资源,则构建相应报文,发回给用户
3. 如果是动态资源,将资源地址发给php解析器,解析php程序文件,解析完毕将内容发回给httpd,httpd构建相应报文,发回给用户
4. 如果涉及到数据库操作,则利用php-mysql驱动,获取数据库数据,返回给PHP解析器。
A,M,P是怎么联动起来事情的呢:
1、apache + php结合的办法大概几种:
第一种:把php编译时直接编译成apache的模块、module模块化的办法进行事情(apahce默认的这种办法)。
第二种:CGI、通用网关接口、apache基于CGI跟hph通信
第三种:fastcgi、他也是一种协议、在这种模块下他们两个是这样结合的:
本来php是做为一个模块或都是php解析器运行的,不是监听在某个套接字上吸收别人的要求的,而是让别人调用为一个进程利用的,可能是做为别人的子进程在运行,但是事情在fastcgi这种模块下的hph自行启用为一个做事进程,
他监听在某个套接字上,随时可以接管来自客户真个要求的,他也是有一个主进程的,为了可以相应多个用户的要求,他会启用多个子进程,这些子进程我们也可以称为事情进程,
他也是有空闲进程的,一但有客户要求他立时利用空闲的进程相应客户真个要求,将结果返回给前真个调用者,在php5.3.3版本之前他是没有这个能力了,只能事情在模块和CGI的办法下,而在5.3.3之后这个模块直接被收进php模块中,这种模块就叫php-fpm。
以是在往后编译php时,要想跟apache结合,就要编译成php-fpm,这是基于fastcgi事情的模式,并启动这做事进程,也就意味着他是通过套接字跟前真个调用者通信,既然基于套按字通信了,那么前真个web做事器和后面的php做事器完备可以事情在不同的主机上,实现了所谓的分层机制。
apache不会跟数据库打交道,他是个静态web做事器,跟数据库打交道的是运用程序,作为运用程序的源驱动能够基于某个API跟做事器之间建立会话,而后他会通过我们的mysql语句发送给数据库,数据库再将结果返回给运用程序,不是php进程,而是php进程中所实行的代码。
2、php + mysql的通信:
PHP跟mysql怎么整合起来呢,php又怎么被httpd所调用呢
首先httpd并不具备解析代码的能力,他要依赖于php的解析器,接着php本身不依赖于mysql,他只是一个解析器,能实行代码就OK了,那他什么时候用到mysql呢,如果要在mysql中存数据时才用到mysql,只是当php中有运行mysql语句时才用到mysql。
php措辞要想联系mysql,常日用到php的驱动,rpm包的叫php_mysql,php跟mysql没有一点关系,只有程序员在php中编写mysql语句时才连接mysql来实行sql语句的。
基于php-mysql去连接mysql只利用一个函数mysql_connect();而mysql_connect()正是php-mysql供应的一个API,只要指明要连接的做事器即可。
三、LAMP搭建过程(基于rpm包):
(1)安装配置apache,基于虚拟主机模式的https协议
(2)安装配置mysql
(3)安装配置php,以及php-mysql模块
(4)基于LAMP搭建wordpress测试
设置虚拟主机配置:
[14:09 root@centos6.8/etc/httpd/ssl]# cat /etc/httpd/conf.d/www.hillpress.com.conf namevirtualhost :80<virtualhost :80>documentroot \"大众/var/www/html/www.hillpress.com\公众servername www.hillpress.comerrorlog logs/error_log_www.hillpress.comloglevel warncustomlog logs/access_log_www.hillpress.com combined</virtualhost>
申请签署证书(我的CA做事和web做事在同一主机):
[14:06 root@centos6.8/etc/httpd/ssl]# openssl req -new -days 365 -key private/hillpress.key -out /etc/httpd/ssl/hillpresscsrYou are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) [XX]:CNState or Province Name (full name) []:BEIJINGLocality Name (eg, city) [Default City]:BEIJINGOrganization Name (eg, company) [Default Company Ltd]:nihaoOrganizational Unit Name (eg, section) []:www.hillpress.comCommon Name (eg, your name or your server's hostname) []:www.hillpress.comEmail Address []:hill@hill.comPlease enter the following 'extra' attributesto be sent with your certificate requestA challenge password []:An optional company name []:[14:07 root@centos6.8/etc/httpd/ssl]# openssl ca -in hillpress.csr -out hillpress.crtUsing configuration from /etc/pki/tls/openssl.cnfCheck that the request matches the signatureSignature okCertificate Details: Serial Number: 3 (0x3) Validity Not Before: Sep 30 06:07:43 2016 GMT Not After : Sep 30 06:07:43 2017 GMT Subject: countryName = CN stateOrProvinceName = BEIJING organizationName = nihao organizationalUnitName = www.hillpress.com commonName = www.hillpress.com emailAddress = hill@hill.com X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 88:05:22:19:70:36:13:D6:6B:43:A4:51:C3:8D:02:66:00:6A:D8:C0 X509v3 Authority Key Identifier: keyid:5B:E9:DA:5B:0B:3F:76:99:E6:96:FA:C0:E4:41:CD:7B:C4:21:7A:4ACertificate is to be certified until Sep 30 06:07:43 2017 GMT (365 days)Sign the certificate? [y/n]:y1 out of 1 certificate requests certified, commit? [y/n]yWrite out database with 1 new entriesData Base Updated
安装mod_ssl模块支持ssl协议:
[14:11 root@centos6.8/etc/httpd/ssl]#rpm -ql mod_ssl/etc/httpd/conf.d/ssl.conf/usr/lib64/httpd/modules/mod_ssl.so/var/cache/mod_ssl/var/cache/mod_ssl/scache.dir/var/cache/mod_ssl/scache.pag/var/cache/mod_ssl/scache.sem
配置https的ssl:/etc/httpd/conf.d/ssl.conf,紧张是配置根目录、证书的位置
[14:15 root@centos6.8/etc/httpd/ssl]# grep \"大众^[^#]\"大众 /etc/httpd/conf.d/ssl.conf LoadModule ssl_module modules/mod_ssl.soListen 443SSLPassPhraseDialog builtinSSLSessionCache shmcb:/var/cache/mod_ssl/scache(512000)SSLSessionCacheTimeout 300SSLMutex defaultSSLRandomSeed startup file:/dev/urandom 256SSLRandomSeed connect builtinSSLCryptoDevice builtin<VirtualHost _default_:443>DocumentRoot \"大众/var/www/html/www.hillpress.com\"大众ServerName www.mypress.comErrorLog logs/ssl_error_logTransferLog logs/ssl_access_logLogLevel warnSSLEngine onSSLProtocol all -SSLv2SSLCipherSuite DEFAULT:!EXP:!SSLv2:!DES:!IDEA:!SEED:+3DESSSLCertificateFile /etc/httpd/ssl/hillpress.crtSSLCertificateKeyFile /etc/httpd/ssl/private/hillpress.key<Files ~ \"大众\.(cgi|shtml|phtml|php3?)$\公众> SSLOptions +StdEnvVars</Files><Directory \"大众/var/www/cgi-bin\公众> SSLOptions +StdEnvVars</Directory>SetEnvIf User-Agent \"大众.MSIE.\"大众 \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0CustomLog logs/ssl_request_log \ \"大众%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \\公众%r\\"大众 %b\"大众</VirtualHost>
检讨语法,重载做事:
[14:15 root@centos6.8/etc/httpd/ssl]# httpd -tSyntax OK[14:16 root@centos6.8/etc/httpd/ssl]# service httpd reloadReloading httpd: [14:16 root@centos6.8/etc/httpd/ssl]#
(2)安装mysql:
[16:37 root@centos6.8/misc/cd]# yum install -y mysql-serverLoaded plugins: fastestmirror, refresh-packagekit, securitySetting up Install ProcessRepository 'base' is missing name in configuration, using idLoading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package mysql-server.x86_64 0:5.1.73-7.el6 will be installed--> Processing Dependency: mysql = 5.1.73-7.el6 for package: mysql-server-5.1.73-7.el6.x86_64--> Processing Dependency: perl-DBI for package: mysql-server-5.1.73-7.el6.x86_64--> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.73-7.el6.x86_64--> Processing Dependency: perl(DBI) for package: mysql-server-5.1.73-7.el6.x86_64--> Running transaction check---> Package mysql.x86_64 0:5.1.73-7.el6 will be installed---> Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be installed---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved========================================================================================================================= Package Arch Version Repository Size=========================================================================================================================Installing: mysql-server x86_64 5.1.73-7.el6 base 8.6 MInstalling for dependencies: mysql x86_64 5.1.73-7.el6 base 894 k perl-DBD-MySQL x86_64 4.013-3.el6 base 134 k perl-DBI x86_64 1.609-4.el6 base 705 kTransaction Summary=========================================================================================================================Install 4 Package(s)Total download size: 10 MInstalled size: 29 MDownloading Packages:-------------------------------------------------------------------------------------------------------------------------Total 12 MB/s | 10 MB 00:00 Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction Installing : perl-DBI-1.609-4.el6.x86_64 1/4 Installing : perl-DBD-MySQL-4.013-3.el6.x86_64 2/4 Installing : mysql-5.1.73-7.el6.x86_64 3/4 Installing : mysql-server-5.1.73-7.el6.x86_64 4/4 Verifying : mysql-server-5.1.73-7.el6.x86_64 1/4 Verifying : mysql-5.1.73-7.el6.x86_64 2/4 Verifying : perl-DBD-MySQL-4.013-3.el6.x86_64 3/4 Verifying : perl-DBI-1.609-4.el6.x86_64 4/4 Installed: mysql-server.x86_64 0:5.1.73-7.el6 Dependency Installed: mysql.x86_64 0:5.1.73-7.el6 perl-DBD-MySQL.x86_64 0:4.013-3.el6 perl-DBI.x86_64 0:1.609-4.el6 Complete![16:38 root@centos6.8/misc/cd]# service mysqld startInitializing MySQL database: Installing MySQL system tables...OKFilling help tables...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/usr/bin/mysqladmin -u root password 'new-password'/usr/bin/mysqladmin -u root -h centos6.8 password 'new-password'Alternatively you can run:/usr/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /usr ; /usr/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd /usr/mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr/bin/mysqlbug script! [ OK ]Starting mysqld: [ OK ]
(3)安装php,以及php-mysql模块:
[16:40 root@centos6.8/misc/cd]# yum -y install php php_mysqlLoaded plugins: fastestmirror, refresh-packagekit, securitySetting up Install ProcessRepository 'base' is missing name in configuration, using idLoading mirror speeds from cached hostfileNo package php_mysql available.Resolving Dependencies--> Running transaction check---> Package php.x86_64 0:5.3.3-47.el6 will be installed--> Processing Dependency: php-common(x86-64) = 5.3.3-47.el6 for package: php-5.3.3-47.el6.x86_64--> Processing Dependency: php-cli(x86-64) = 5.3.3-47.el6 for package: php-5.3.3-47.el6.x86_64--> Running transaction check---> Package php-cli.x86_64 0:5.3.3-47.el6 will be installed---> Package php-common.x86_64 0:5.3.3-47.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved========================================================================================================================= Package Arch Version Repository Size=========================================================================================================================Installing: php x86_64 5.3.3-47.el6 base 1.1 MInstalling for dependencies: php-cli x86_64 5.3.3-47.el6 base 2.2 M php-common x86_64 5.3.3-47.el6 base 530 kTransaction Summary=========================================================================================================================Install 3 Package(s)Total download size: 3.8 MInstalled size: 13 MDownloading Packages:-------------------------------------------------------------------------------------------------------------------------Total 8.8 MB/s | 3.8 MB 00:00 Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction Installing : php-common-5.3.3-47.el6.x86_64 1/3 Installing : php-cli-5.3.3-47.el6.x86_64 2/3 Installing : php-5.3.3-47.el6.x86_64 3/3 Verifying : php-common-5.3.3-47.el6.x86_64 1/3 Verifying : php-cli-5.3.3-47.el6.x86_64 2/3 Verifying : php-5.3.3-47.el6.x86_64 3/3 Installed: php.x86_64 0:5.3.3-47.el6 Dependency Installed: php-cli.x86_64 0:5.3.3-47.el6 php-common.x86_64 0:5.3.3-47.el6 Complete![20:44 root@centos6.8~]# yum install -y php-mysqlLoaded plugins: fastestmirror, refresh-packagekit, securitySetting up Install ProcessRepository 'base' is missing name in configuration, using idLoading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package php-mysql.x86_64 0:5.3.3-47.el6 will be installed--> Processing Dependency: php-pdo(x86-64) for package: php-mysql-5.3.3-47.el6.x86_64--> Running transaction check---> Package php-pdo.x86_64 0:5.3.3-47.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved========================================================================================================================= Package Arch Version Repository Size=========================================================================================================================Installing: php-mysql x86_64 5.3.3-47.el6 base 86 kInstalling for dependencies: php-pdo x86_64 5.3.3-47.el6 base 80 kTransaction Summary=========================================================================================================================Install 2 Package(s)Total download size: 166 kInstalled size: 384 kDownloading Packages:-------------------------------------------------------------------------------------------------------------------------Total 261 kB/s | 166 kB 00:00 Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction Installing : php-pdo-5.3.3-47.el6.x86_64 1/2 Installing : php-mysql-5.3.3-47.el6.x86_64 2/2 Verifying : php-mysql-5.3.3-47.el6.x86_64 1/2 Verifying : php-pdo-5.3.3-47.el6.x86_64 2/2 Installed: php-mysql.x86_64 0:5.3.3-47.el6 Dependency Installed: php-pdo.x86_64 0:5.3.3-47.el6 Complete!
php配置文件不须要额外修正,但要修正httpd配置文件,添加支持php的MIME类型:
# vim /etc/httpd22/httpd.conf //找到AddType application/x不才面添加 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps DirectoryIndex index.php index.html/找到 DirectoryIndex index.html 添加index.php
测试apache与php的连通性:
将首页index.html改成index.php,并且编辑首页内容,添加php的测试语句
[17:18 root@centos6.8/var/www/html/www.hillpress.com]# cat !$cat index.phpwelcome to mypage<?phpphpinfo();?>
测试php与mysql的连通性:
[17:45 root@centos6.8/var/www/html/www.hilldiscuz.com]# cat nihao.php <?php $link = mysql_connect('localhost','root','nihao'); if ($link) echo \"大众Success...\"大众; else echo \"大众Failure...\"大众; mysql_close();?>
(4)基于LAMP搭建wordpress测试:
1)讲SElinux关闭,或者添加SElinux安全高下文策略
2)把下载的wordprss源码包解压到web的做事根目录,并且修正文件的属组属主
3)修正wordprss的配置文件:wp-config-sample.php,并将名字改为wp-config.php,修正数据库的位置以及登录的帐号密码
[22:26 root@centos6.8/var/www/html/www.hillpress.com]# cat wp-config.php <?php/ WordPress根本配置文件。 这个文件被安装程序用于自动天生wp-config.php配置文件, 您可以不该用网站,您须要手动复制这个文件, 并重命名为“wp-config.php”,然后填入干系信息。 本文件包含以下配置选项: MySQL设置 密钥 数据库表名前缀 ABSPATH @link https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php @package WordPress /// MySQL 设置 - 详细信息来自您正在利用的主机 /// WordPress数据库的名称 /define('DB_NAME', 'myDB');/ MySQL数据库用户名 /define('DB_USER', 'wpuser');/ MySQL数据库密码 /define('DB_PASSWORD', 'wppasswd');/ MySQL主机 /define('DB_HOST', 'localhost');/ 创建数据表时默认的笔墨编码 /define('DB_CHARSET', 'utf8');/ 数据库整理类型。如不愿定请勿变动 /define('DB_COLLATE', '');/#@+ 身份认证密钥与盐。 修正为任意独一无二的字串!
或者直接访问{@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org密钥天生做事} 任何修正都会导致所有cookies失落效,所有用户将必须重新登录。 @since 2.6.0 /define('AUTH_KEY', 'put your unique phrase here');define('SECURE_AUTH_KEY', 'put your unique phrase here');define('LOGGED_IN_KEY', 'put your unique phrase here');define('NONCE_KEY', 'put your unique phrase here');define('AUTH_SALT', 'put your unique phrase here');define('SECURE_AUTH_SALT', 'put your unique phrase here');define('LOGGED_IN_SALT', 'put your unique phrase here');define('NONCE_SALT', 'put your unique phrase here');/#@-// WordPress数据表前缀。 如果您有在同一数据库内安装多个WordPress的需求,请为每个WordPress设置 不同的数据表前缀。前缀名只能为数字、字母加下划线。 /$table_prefix = 'wp_';/ 开拓者专用:WordPress调试模式。 将这个值改为true,WordPress将显示所有用于开拓的提示。 强烈建议插件开拓者在开拓环境中启用WP_DEBUG。 要获取其他能用于调试的信息,请访问Codex。 @link https://codex.wordpress.org/Debugging_in_WordPress /define('WP_DEBUG', false);/ zh_CN本地化设置:启用ICP备案号显示 可在设置→常规中修正。 如需禁用,请移除或注释掉本行。 /define('WP_ZH_CN_ICP_NUM', true);/ 好了!
请不要再连续编辑。请保存本文件。利用愉快!
// WordPress目录的绝对路径。 /if ( !defined('ABSPATH') )define('ABSPATH', dirname(__FILE__) . '/');/ 设置WordPress变量和包含文件。 /require_once(ABSPATH . 'wp-settings.php');
4)为wordpress创建专门的数据库用户,并测试成功
MariaDB [(none)]> create database myDB;Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> GRANT ALL ON myDB. TO 'wpuser'@'%' IDENTIFIED BY 'wppasswd';Query OK, 0 rows affected (0.00 sec)