LAMP(linux+apache+mysql/mariadb+php)是当前流行的web框架,具有通用、跨平台、高性能、低价格的 优势。
一、php
1、简介
PHP是通用服务器端脚本编程语言,其主要用于web开发以实现动态web页面,它也是最早实现将脚本嵌入HTML源码文档中的服务器端脚本语言之一。
2、PHP Zend Engine
Zend Engine是开源的、PHP脚本语言的解释器。它的出现将PHP代码的处理过程分成了两个阶段:首先是分析PHP代码并将其转换为称作Zend opcode的二进制格式(类似Java的字节码),并将其存储于内存中;第二阶段是使用Zend Engine去执行这些转换后的Opcode。
3、PHP的Opcode
Opcode是一种PHP脚本编译后的中间语言。PHP执行PHP脚本代码一般会经过如下4个步骤:
①Scanning(Lexing) ―― 将PHP代码转换为语言片段(Tokens)
②Parsing ―― 将Tokens转换成简单而有意义的表达式
③Compilation ―― 将表达式编译成Opocdes
④Execution ―― 顺次执行Opcodes,每次一条,从而实现PHP脚本的功能
4、php的加速器
基于PHP的特殊扩展机制如opcode缓存扩展也可以将opcode缓存于php的共享内存中,从而可以让同一段代码的后续重复执行时跳过编译阶段以提高性能。
常见的php加速器有:APC、eAccelerator、XCache、Zend Optimizer和Zend Guard Loader、NuSphere PhpExpress
5、php的安装
rpm包
编译安装
6、开源php站点程序:
wordpress
drupal, joomlar
phpwind(阿里)
discuz(腾讯)
二、简单搭建LAMP平台
1、apache和php结合的方式:
①php作为httpd的模块
②httpd基于CGI协议与php通信
③php工作为一个服务器,httpd与php基于fastcgi协议进行通信
2、php连接mysql:php (php-mysql) --> mysql protocol --> mysqld
3、示例:以自建独立博客站点(wordpress)为例演示LAMP环境的构建
httpd和mysql的安装配置这里不作详解,详见博客http://9124573.blog.51cto.com/9114573/1727201和http://9124573.blog.51cto.com/9114573/1731896
注:这里的httpd、php、mysql都安装于同一节点实为演示方便,实际环境中为分摊压力多分布于不同节点
[root@node2 ~]# yum -y install php ... Installed: php.x86_64 0:5.3.3-46.el6_6 Dependency Installed: php-cli.x86_64 0:5.3.3-46.el6_6 php-common.x86_64 0:5.3.3-46.el6_6 Complete! [root@node2 ~]# rpm -ql php /etc/httpd/conf.d/php.conf #php的配置文件 /usr/lib64/httpd/modules/libphp5.so #php默认是以作为httpd模块的方式与httpd结合的 /var/lib/php/session /var/www/icons/php.gif [root@node2 wordpress]# vim /etc/httpd/conf.d/php.conf # # PHP is an HTML-embedded scripting language which attempts to make it # easy for developers to write dynamically generated webpages. # <IfModule prefork.c> LoadModule php5_module modules/libphp5.so #httpd使用的多道处理机制不同,装载的php模块也不同 </IfModule> <IfModule worker.c> LoadModule php5_module modules/libphp5-zts.so </IfModule> # # Cause the PHP interpreter to handle files with a .php extension. # AddHandler php5-script .php AddType text/html .php # # Add index.php to the list of files that will be served as directory # indexes. # DirectoryIndex index.php # # Uncomment the following line to allow PHP to pretty-print .phps # files as PHP source code: # #AddType application/x-httpd-php-source .phps ~ [root@node2 ~]# yum -y install php-mysql #安装php连接mysql的驱动 ... Installed: php-mysql.x86_64 0:5.3.3-46.el6_6 Dependency Installed: php-pdo.x86_64 0:5.3.3-46.el6_6 Complete! [root@node2 ~]# cd /var/www/html [root@node2 html]# ls #web站点根目录下有事先下载好的wordpress程序 admin admin.html index.html.back test.html text wordpress-3.2.1-zh_CN.zip [root@node2 html]# unzip wordpress-3.2.1-zh_CN.zip ... [root@node2 html]# ls admin admin.html index.html.back test.html text wordpress wordpress-3.2.1-zh_CN.zip [root@node2 html]# cd wordpress [root@node2 wordpress]# ls index.php wp-activate.php wp-atom.php wp-commentsrss2.php wp-cron.php wp-links-opml.php wp-mail.php wp-register.php wp-settings.php xmlrpc.php license.txt wp-admin wp-blog-header.php wp-config-sample.php wp-feed.php wp-load.php wp-pass.php wp-rss2.php wp-signup.php readme.html wp-app.php wp-comments-post.php wp-content wp-includes wp-login.php wp-rdf.php wp-rss.php wp-trackback.php [root@node2 wordpress]# mv wp-config-sample.php wp-config.php #提供配置文件 [root@node2 wordpress]# vim wp-config.php <?php /** * WordPress 基础配置文件。 * * 本文件包含以下配置选项:MySQL 设置、数据库表名前缀、密匙、 * WordPress 语言设定以及 ABSPATH。如需更多信息,请访问 * {@link http://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php * 编辑 wp-config.php} Codex 页面。MySQL 设置具体信息请咨询您的空间提供商。 * * 这个文件用在于安装程序自动生成 wp-config.php 配置文件, * 您可以手动复制这个文件,并重命名为“wp-config.php”,然后输入相关信息。 * * @package WordPress */ // ** MySQL 设置 - 具体信息来自您正在使用的主机 ** // /** WordPress 数据库的名称 */ define('DB_NAME', 'wpdb'); #要先在mysql上创建好对应的数据库 /** MySQL 数据库用户名 */ define('DB_USER', 'tuser'); /** MySQL 数据库密码 */ define('DB_PASSWORD', 'tpass'); /** MySQL 主机 */ define('DB_HOST', 'localhost'); /** 创建数据表时默认的文字编码 */ define('DB_CHARSET', 'utf8'); /** 数据库整理类型。如不确定请勿更改 */ define('DB_COLLATE', ''); ... [root@node2 ~]# mysql ... mysql> create database wpdb; #创建wordpress需要使用的数据库 Query OK, 1 row affected (0.07 sec) mysql> grant all on wpdb.* to tuser@localhost identified by 'tpass'; #授权 Query OK, 0 rows affected (0.01 sec) mysql> exit Bye root@node2 ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: httpd: apr_sockaddr_info_get() failed for node2 httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName [ OK ]
三、编译LAMP
1、编译安装httpd 2.4和二进制格式安装mariadb-5.5.36 (略)
2、编译安装php
㈠将php编译成httpd的模块
将 PHP 编译成 httpd 的模块时,需要指定使用 apxs2 来将其编译成 httpd 的模块。
①安装之前,需先安装好开发包组,并安装 libxml2-devel,bzip2-devel 和 libmcrypt-devel
yum -y groupinstall "Desktop Platform Development"
yum -y install bzip2-devel libmcrypt-devel
②下载源码包并安装
wget http://php.net/get/php-5.4.41.tar.bz2/from/a/mirror
tar xf php-5.4.41.tar.bz2
cd php-5.4.41
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
make && make install
说明:
◇freetype是字体处理工具,zlib是压缩库,xml是扩展标记语言,mcrypt是加密库(要支持此加密功能,必须先安装好libmcrypt-devel)
◇若mysql服务端程序是以rpm方式安装的,则--with-mysql和--with-mysqli后不用指明具体位置
◇这里为了支持apahce的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项
◇若使用php5.3以上版本,为了链接Mysql数据库,可指定mysqlnd,这样在本机就不需先安装mysql或mysql开发包(mysql-devel)了,从php5.4开始就默认绑定mysqlnd了。如果已安装mysql-devel,可直接--with-mysql
--with-mysql=mysqlnd --with-pdo=mysqlnd --with-mysqli=mysqlnd
③为php提供配置文件
cp php.ini-production /etc/php.d/php.ini
④编辑httpd配置文件,以支持php文件,在/etc/httpd24/httpd.conf中输入:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
⑤修改DirectoryIndex
DirectoryIndex index.php index.html
⑥测试php是否能够正常工作,在数据库中添加一个用户用于测试
MariaDB [(none)]> GRANT ALL ON *.* TO phpuser@localhost IDENTIFIED BY 'phppasswd';
MariaDB [(none)]> FLUSH PRIVILEGES;
⑦在服务器建立一个测试页面index.php
<?php
$link = mysql_connect('localhost','phpuser','phppasswd');
if ($link)
echo "success";
else
echo "fail";
mysql_close();
?>
⑧重启httpd服务并访问该页面
[root@node2 ~]# yum -y install bzip2-devel libmcrypt-devel ... Installed: bzip2-devel.x86_64 0:1.0.5-7.el6_0 libmcrypt-devel.x86_64 0:2.5.8-9.el6 Dependency Installed: libmcrypt.x86_64 0:2.5.8-9.el6 Complete! [root@node2 ~]# tar -xf php-5.4.26.tar.bz2 [root@node2 ~]# cd php-5.4.26 [root@node2 php-5.4.26]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts ... configure: error: xml2-config not found. Please check your libxml2 installation. #这里提示找不到xml2-config,发现是因为没安装libxml2-devel [root@node2 php-5.4.26]# yum -y install libxml2-devel ... [root@node2 php-5.4.26]# !./conf ... Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands [root@node2 php-5.4.26]# make && make install ... [root@node2 php-5.4.26]# ls /usr/local/php/ bin etc include lib php [root@node2 php-5.4.26]# cp php.ini-production /etc/php.d/php.ini [root@node2 php-5.4.26]# vim /etc/httpd24/httpd.conf ... LoadModule php5_module modules/libphp5.so #已自动启用php模块 ... <IfModule mime_module> AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps </IfModule> <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> [root@node2 php-5.4.26]# cd /web/htdocs/ #此例中httpd的站点根目录为/web/htdocs [root@node2 htdocs]# vim index.php <html> <body> <h1>It works!</h1> <?php $link = mysql_connect('localhost','phpuser','phppasswd'); if ($link) echo "success"; else echo "fail"; mysql_close(); ?> </body> </html> [root@node2 htdocs]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 5.5.36-MariaDB-log MariaDB Server Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> grant all on *.* to phpuser@localhost identified by 'phppasswd'; Query OK, 0 rows affected (0.25 sec) MariaDB [(none)]> flush privileges; MariaDB [(none)]> exit Bye
★安装xchache,为php加速
①下载并安装
wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.bz2
tar zxvf xcache-3.2.0.tar.gz
cd xcache-3.2.0
/usr/local/php/bin/phpize #用phpize生成configure配置文件
./configure --enable-xcache [--enable-xcache-coverager --enable-xcache-optimizer] --with-php-config=/usr/local/php/bin/php-config # 通过with-php-config指定将其编译为php的模块
make && make install
安装完成后,会出现下面一行:
/usr/local/php/lib/php/extensions/no-debug-zts-20100525/ #xcache.so所在目录
②提供配置文件
cp xcache.ini /etc/php.d/
cd /etc/php.d
vim /etc/php.d/xcache.ini
修改extension一行:
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
[root@node2 ~]# tar -xf xcache-3.1.0.tar.bz2 [root@node2 ~]# cd xcache-3.1.0 [root@node2 xcache-3.1.0]# ls AUTHORS config.w32 htdocs Makefile.frag mod_coverager mod_optimizer run-xcachetest xcache xcache.ini bin COPYING includes.c Makefile.frag.deps mod_decoder NEWS tests xcache.c xcache-test.ini ChangeLog devel INSTALL mod_assembler mod_disassembler processor THANKS xcache_globals.h xcache-zh-gb2312.ini config.m4 gen_structinfo.awk lib mod_cacher mod_encoder README util xcache.h [root@node2 xcache-3.1.0]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20100412 Zend Module Api No: 20100525 Zend Extension Api No: 220100525 Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. [root@node2 xcache-3.1.0]# rpm -q autoconf package autoconf is not installed [root@node2 xcache-3.1.0]# yum -y install autoconf ... [root@node2 xcache-3.1.0]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20100412 Zend Module Api No: 20100525 Zend Extension Api No: 220100525 [root@node2 xcache-3.1.0]# ls acinclude.m4 build config.sub devel install-sh Makefile.global mod_coverager NEWS tests xcache_globals.h aclocal.m4 ChangeLog configure gen_structinfo.awk lib missing mod_decoder processor THANKS xcache.h AUTHORS config.guess configure.in htdocs ltmain.sh mkinstalldirs mod_disassembler README util xcache.ini autom4te.cache config.h.in config.w32 includes.c Makefile.frag mod_assembler mod_encoder run-tests.php xcache xcache-test.ini bin config.m4 COPYING INSTALL Makefile.frag.deps mod_cacher mod_optimizer run-xcachetest xcache.c xcache-zh-gb2312.ini [root@node2 xcache-3.1.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config ... [root@node2 xcache-3.1.0]# make && make install ... Build complete. Don't forget to run 'make test'. Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/ [root@node2 xcache-3.1.0]# ls acinclude.m4 config.h configure.in includes.i Makefile.frag.deps mod_coverager processor.out.c xcache xcache-zh-gb2312.ini aclocal.m4 config.h.in config.w32 INSTALL Makefile.fragments mod_decoder README xcache.c xc_processor.c.h AUTHORS config.log COPYING install-sh Makefile.global mod_disassembler run-tests.php xcache_globals.h xc_processor.h autom4te.cache config.m4 devel lib Makefile.objects mod_encoder run-xcachetest xcache.h bin config.nice gen_structinfo.awk libtool missing mod_optimizer structinfo.m4 xcache.ini build config.status htdocs ltmain.sh mkinstalldirs modules tests xcache.la ChangeLog config.sub include Makefile mod_assembler NEWS THANKS xcache.lo config.guess configure includes.c Makefile.frag mod_cacher processor util xcache-test.ini [root@node2 xcache-3.1.0]# cp xcache.ini /etc/php.d/ [root@node2 xcache-3.1.0]# vim /etc/php.d/xcache.ini ;; this is an example, it won't work unless properly configured into php.ini [xcache-common] ;; non-Windows example: extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so #注明加速模块的完整路径 ;; Windows example: ; extension = php_xcache.dll [xcache.admin] xcache.admin.enable_auth = On ... [root@node2 xcache-3.1.0]# service httpd24 restart Stopping httpd: [ OK ] Starting httpd: AH00557: httpd: apr_sockaddr_info_get() failed for node2 AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message [ OK ] [root@node2 xcache-3.1.0]# cd /web/htdocs/ [root@node2 htdocs]# vim index.php <html> <body> <h1>It works!</h1> <?php $link = mysql_connect('localhost','phpuser','phppasswd'); if ($link) echo "success"; else echo "fail"; mysql_close(); phpinfo(); #显示php状态信息 ?> </body> </html>
㈡将php编译成php-fpm(此时php工作为一个服务器,php与httpd基于fastcgi协议进行通信)
①编译安装
tar xf php-5.4.41.tar.bz2
cd php-5.4.41
./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
make && make install
②为php提供配置文件
cp php.ini-production /etc/php.d/php.ini
③为php-fpm提供服务启动脚本,并将其添加至chkconfig控制
cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
④为php-fpm提供配置文件
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
⑤编辑php-fpm配置文件
vim /usr/local/php/etc/php-fpm.conf
配置fmp的相关选项为需要的值,并启用pid文件
pm.max_child = 25
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pid = /usr/local/php/var/run/php-fpm.pid
⑥启动php-fpm
service php-fpm start (centos 7上为systemctl start php-fpm.service)
php-fpm默认监听在127.0.0.1的9000端口
配置httpd
⑦在httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩充,因此,这两个模块都要加载
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
⑧编辑httpd配置文件,让apache能够识别php格式的页面,并支持php格式的主页
vim /etc/httpd24/httpd.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html
⑨配置虚拟主机支持使用fastcgi
在相应的虚拟主机中添加类似如下两行:
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://IP:9000/PATH/TO/DOCUMENT_ROOT/$1 #把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI。注意:这里的 DOCUMENT_ROOT 只是php文件的存放路径,可以不是httpd的站点根目录。实际环境中,php-fpm与httpd多位于不同的主机上,动态资源部署在php-fpm服务器上。
例如:
vim /etc/httpd24/httpd.conf
#DocumentRoot "/usr/local/apache/htdocs" #将中心主机注释掉
Include /etc/httpd24/extra/httpd-vhosts.conf #把虚拟主机配置文件包含进来
vim /etc/httpd24/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerNAME www.inception.com
DocumentRoot /web/hosta
ProxyRequests off #关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.30.20:9000/web/hosta/$1
<Directory "/web/hosta">
Options Index FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
⑩编辑测试页面测试
[root@node2 ~]# mv php-5.4.26 php-5.4.26.bac [root@node2 ~]# tar -xf php-5.4.26.tar.bz2 [root@node2 ~]# cd php-5.4.26 [root@node2 php-5.4.26]# ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 ... [root@node2 php-5.4.26]# make && make install ... [root@node2 php-5.4.26]# ls acinclude.m4 configure.in libtool missing README.EXT_SKEL README.SUBMITTING_PATCH stub.c aclocal.m4 CREDITS LICENSE mkinstalldirs README.GIT-RULES README.TESTING svnclean.bat build ext ltmain.sh modules README.input_filter README.TESTING2 tests buildconf EXTENSIONS main netware README.MAILINGLIST_RULES README.UNIX-BUILD-SYSTEM TSRM buildconf.bat footer makedist NEWS README.namespaces README.WIN32-BUILD-SYSTEM UPGRADING CODING_STANDARDS generated_lists Makefile pear README.NEW-OUTPUT-API run-tests.php UPGRADING.INTERNALS config.guess genfiles Makefile.frag php5.spec README.PARAMETER_PARSING_API sapi vcsclean config.log header Makefile.fragments php5.spec.in README.PHP4-TO-PHP5-THIN-CHANGES scripts win32 config.nice include Makefile.gcov php.gif README.REDIST.BINS server-tests-config.php Zend config.status INSTALL Makefile.global php.ini-development README.RELEASE_PROCESS server-tests.php config.sub install-sh Makefile.objects php.ini-production README.SELF-CONTAINED-EXTENSIONS snapshot configure libs makerpm README.EXTENSIONS README.STREAMS stamp-h.in [root@node2 php-5.4.26]# rm -f /etc/php.d/{php.ini,xcache.ini} [root@node2 php-5.4.26]# cp php.ini-production /etc/php.d/php.ini #给php提供配置文件 [root@node2 php-5.4.26]# ls sapi/fpm config.m4 fpm init.d.php-fpm.in Makefile.frag php-fpm.8 php-fpm.conf php-fpm.service status.html CREDITS init.d.php-fpm LICENSE php-fpm php-fpm.8.in php-fpm.conf.in php-fpm.service.in status.html.in CREDITS init.d.php-fpm LICENSE php-fpm php-fpm.8.in php-fpm.conf.in php-fpm.service.in status.html.in [root@node2 php-5.4.26]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #给php-fpm提供服务脚本 [root@node2 php-5.4.26]# chmod +x /etc/rc.d/init.d/php-fpm #给服务脚本添加执行权限 [root@node2 php-5.4.26]# chkconfig --add php-fpm [root@node2 php-5.4.26]# chkconfig php-fpm on [root@node2 php-5.4.26]# chkconfig --list php-fpm php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@node2 php-5.4.26]# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf #给php-fpm提供配置文件 [root@node2 php-5.4.26]# vim /usr/local/php5/etc/php-fpm.conf ... pid = /usr/local/php5/var/run/php-fpm.pid #指定pid文件路径 ... error_log = log/php-fpm.log #可选择启用错误日志 ... listen = 127.0.0.1:9000 #php-fpm默认只监听在本机的9000端口,实际环境中可按需修改 ... pm.max_children = 25 #php-fpm的最大并发数 ... pm.start_servers = 5 #启动的空闲进程数 ... pm.min_spare_servers = 2 #最小空闲进程数 ... pm.max_spare_servers = 6 #最大空闲进程数,不能小于pm.start_servers ... [root@node2 php-5.4.26]# service php-fpm start Starting php-fpm done [root@node2 php-5.4.26]# ss -tnl ... LISTEN 0 128 127.0.0.1:9000 *:* ... [root@node2 php-5.4.26]# cp /etc/httpd24/httpd.conf /etc/httpd24/httpd.conf.bac #将原来的httpd配置文件备份 [root@node2 php-5.4.26]# vim /etc/httpd24/httpd.conf ... LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so ... DocumentRoot "/web/htdocs" ProxyRequests off #关闭正向代理 ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/web/htdocs/$1 #将对php文件的请求传递给php-fpm进程 <Directory "/web/htdocs"> ... [root@node2 php-5.4.26]# service httpd24 reload Reloading httpd:
3、构建分离式LAMP注意事项
①动态资源部署于应用程序服务器(php-fpm),静态资源部署于web服务器;
②php以fpm方式工作时,不会被编译成httpd的模块,因此,无须在httpd的配置文件中启用LoadModule;
③编译php时,需要连接mysql或其它数据库管理系统时,需要启用其相关的驱动模块;
④php与mysql不在同一节点,连接mysql的用户账号要有远程访问权限;
四、phpadmin
phpMyAdmin是一个用PHP编写的软件工具,可以通过web方式控制和操作MySQL数据库。
[root@node2 ~]# unzip phpMyAdmin-4.0.5-all-languages.zip -d /web/htdocs/ ... [root@node2 ~]# cd /web/htdocs [root@node2 htdocs]# mv phpMyAdmin-4.0.5-all-languages pma [root@node2 htdocs]# cd pma [root@node2 pma]# ls browse_foreigners.php db_tracking.php phpmyadmin.css.php server_collations.php tbl_addfield.php tbl_tracking.php ChangeLog db_triggers.php phpunit.xml.nocoverage server_databases.php tbl_change.php tbl_triggers.php changelog.php doc pmd_display_field.php server_engines.php tbl_chart.php tbl_zoom_select.php chk_rel.php examples pmd_general.php server_export.php tbl_create.php themes composer.json export.php pmd_pdf.php server_import.php tbl_export.php themes.php config.sample.inc.php favicon.ico pmd_relation_new.php server_plugins.php tbl_get_field.php transformation_overview.php db_create.php file_echo.php pmd_relation_upd.php server_privileges.php tbl_gis_visualization.php transformation_wrapper.php db_datadict.php gis_data_editor.php pmd_save_pos.php server_replication.php tbl_import.php url.php db_events.php import.php prefs_forms.php server_sql.php tbl_indexes.php user_password.php db_export.php import_status.php prefs_manage.php server_status_advisor.php tbl_move_copy.php version_check.php db_import.php index.php print.css server_status_monitor.php tbl_operations.php view_create.php ... [root@node2 pma]# cp config.sample.inc.php config.inc.php #给phpadmin提供配置文件 [root@node2 pma]# vim config.inc.php ... /* * This is needed for cookie based authentication to encrypt password in * cookie */ $cfg['blowfish_secret'] = 'a8b7c6degierog'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */ /* * Servers configuration */ $i = 0; /* * First server */ $i++; /* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; /* Server parameters */ $cfg['Servers'][$i]['host'] = 'localhost'; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['compress'] = false; /* Select mysql if your server does not have mysqli */ $cfg['Servers'][$i]['extension'] = 'mysqli'; $cfg['Servers'][$i]['AllowNoPassword'] = false; ...