lamp平台 php解析器基于模块和php-fpm

   2016-08-30 0
核心提示:首先,我先介绍一下实验环境:http服务器:192.168.236.128(php解析器基于modules)mysql服务器:192.168.236.129编译和配置http服务器,http版本是2.4以上的。由于http依赖于apr apr-util这两个包,但是我们系统上的rpm包版本比较低,我们也需要下载这两个

首先,我先介绍一下实验环境:

http服务器:192.168.236.128(php解析器基于modules)

mysql服务器:192.168.236.129

编译和配置http服务器,http版本是2.4以上的。

由于http依赖于apr apr-util这两个包,但是我们系统上的rpm包版本比较低,我们也需要下载这两个源码包来编译,解决依赖关系。

还要一些开发包组,所以,这一些都要在编译时做好!!

yum groupinstall Desktop Platform Development  Server Platform Development -y(这个步骤要两个机子上都做好!)

编译apr:

tar xf apr-1.4.6.tar.bz2

cd apr-1.4.6

./configure –prefix=/usr/local/apr

make && make install

编译apr-util:

tar xf apr-util-1.4.1.tar.bz2

cd apr-util-1.4.1

./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr

make && make install

编译httpd:

tar xf httpd-2.4.6.tar.bz2

cd httpd-2.4.6

./configure –prefix=/usr/local/apache –sysconfdir=/etc/http24 –enable-so –enable-modules=most –enable-mods-shared=most –enable-proxy –enable-proxy-fcgi –enable-mpms-shared=all –enable-cgi –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util –with-z –with-ssl –with-mpm=event –enable-rewrite

编译时,出现了错误,缺少了pcre的库文件,这时,需要安装这些库文件。

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

yum install pcre-devel -y

安装后,再来一次上面的命令,好了之后:

make && make install

编译完成后,我们进行配置http的配置文件:

vim /etc/http24/httpd.conf

在配置文件中增加一下参数:

DirectoryIndex index.php index.html

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

然后为http提供服务脚本:

#!/bin/bash

#

# httpd        Startup script for the Apache HTTP Server

#

# chkconfig: – 85 15

# description: Apache is a World Wide Web server.  It is used to serve \

#        HTML files and CGI.

# processname: httpd

# config: /etc/httpd/conf/httpd.conf

# config: /etc/sysconfig/httpd

# pidfile: /var/run/httpd.pid

# Source function library.

. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then

. /etc/sysconfig/httpd

fi

# Start httpd in the C locale by default.

HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if

# mod_ssl needs a pass-phrase from the user.

INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server

# with the thread-based "worker" MPM; BE WARNED that some modules may not

# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.

apachectl=/usr/local/apache/bin/apachectl

httpd=${HTTPD-/usr/local/apache/bin/httpd}

prog=httpd

pidfile=${PIDFILE-/var/run/httpd.pid}

lockfile=${LOCKFILE-/var/lock/subsys/httpd}

RETVAL=0

start() {

echo -n $"Starting $prog: "

LANG=$HTTPD_LANG daemon –pidfile=${pidfile} $httpd $OPTIONS

RETVAL=$?

echo

[ $RETVAL = 0 ] && touch ${lockfile}

return $RETVAL

}

stop() {

echo -n $"Stopping $prog: "

killproc -p ${pidfile} -d 10 $httpd

RETVAL=$?

echo

[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}

}

reload() {

echo -n $"Reloading $prog: "

if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then

RETVAL=$?

echo $"not reloading due to configuration syntax error"

failure $"not reloading $httpd due to configuration syntax error"

else

killproc -p ${pidfile} $httpd -HUP

RETVAL=$?

fi

echo

}

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

status)

status -p ${pidfile} $httpd

RETVAL=$?

;;

restart)

stop

start

;;

condrestart)

if [ -f ${pidfile} ] ; then

stop

start

fi

;;

reload)

reload

;;

graceful|help|configtest|fullstatus)

$apachectl $@

RETVAL=$?

;;

*)

echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"

exit 1

esac

exit $RETVAL

然后,把脚本加到服务脚本中:

chmod +x /etc/init.d/httpd24

chkconfig –add httpd24

service httpd24 start

查看一下监听端口,检测http服务是否开启了:

[root@www httpd-2.4.6]# ss -tnlp

State       Recv-Q Send-Q                                          Local Address:Port                                            Peer Address:Port

LISTEN      0      128                                                        :::111                                                       :::*      users:(("rpcbind",1172,11))

LISTEN      0      128                                                         *:111                                                        *:*      users:(("rpcbind",1172,8))

LISTEN      0      128                                                        :::80                                                        :::*      users:(("httpd",32097,4))

好了,我们切换到192.168.236.129的主机上安装mariadb,mariadb是基于二进制包安装的:

tar zxvf mariadb-5.5.36-linux-x86_64.tar.gz

mv mariadb-5.5.36-linux-x86_64 /usr/local/

[root@www ~]# ln -sv /usr/local/mariadb-5.5.36-linux-x86_64 /usr/local/mysql

`/usr/local/mysql' -> `/usr/local/mariadb-5.5.36-linux-x86_64'

mkdir /etc/mysql

cp /usr/local/mysql/support-files/my-large.cnf /etc/mysql/my.cnf

编译这个配置文件,加入 datadir=/data

然后,我们需要创建这个数据库的数据目录:

mkdir /data

groupadd -r mysql

useradd -r -g mysql mysql

chown mysql:mysql /data

cd /usr/local/mysql

chown -R mysql:mysql ./

然后,我们就要进行数据库的初始化:

./scripts/mysql_install_db –user=mysql –datadir=/data –basedir=/usr/local/mysql

我们要为数据库提供服务脚本:

cp support-files/mysql.server /etc/init.d/mysqld

把这个脚本放到服务脚本中去:

chmod +x /etc/init.d/mysqld

chkconfig –add mysqld

service mysqld start

检查服务是否开启了:

[root@www mysql]# ss -tnlp

LISTEN      0      50                                                                               *:3306                                                                            *:*      users:(("mysqld",29215,14))

我们还需要需要修改一下mysql的PATH环境变量:

vim /etc/profile.d/mysql.sh

export PATH=/usr/local/mysql/bin:$PATH

然后,我们重新login进来

[root@www ~]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

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)]>

表明我们已经可以用mysql客户端登进服务器端了,我们为了等一下的测试先创建一个用户:

MariaDB [(none)]> grant all on *.* to 'bwei'@192.168.236.128 identified by 'bwei';

Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

然后,我们可以退出了!

ok了,我们切换为http服务的主机编译php:

开始之前,也是需要安装一些开发包:

yum -y install bzip2-devel libmcrypt-devel

tar xf php-5.4.19.tar.bz2

cd php-5.4.19

./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache/bin/apxs –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-libxml-dir=/usr –with-zlib –with-bz2 –enable-xml –with-jpeg-dir –with-png-dir –with-freetype-dir –enable-mbstring –with-mcrypt –enable-sockets –with-mysql=mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –enable-maintainer-zts

出现了问题,解决方法也是一样,安装libxml2-devel就可以了:

configure: error: xml2-config not found. Please check your libxml2 installation.

yum install -y libxml2-devel

然后,就按上面的方法再来一次,最后,make && make install

为php解析器提供配置文件:

cp php.ini-production /etc/php.ini

我们可以对php解析器进行测试:

vim /usr/local/apache/htdocs/index.php

<?php

phpinfo();

?>

对是否正常连接mysql测试:

<?php

$con=mysql_connect('192.168.236.129','bwei','bwei');

if($con)

echo "ok!!";

else

echo "false!!";

mysql_close();

?>

测试的时候要把iptables关闭!!

好了,我们给php解析器加上组件xcache,先编译xcache:

tar xf xcache-3.1.0.tar.bz2

cd xcache-3.1.0

[root@www 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

这是为了xcache提供configure文件。

./configure –enable-xcache –with-php-config=/usr/local/php/bin/php-config –sysconfdir=/etc/php.d

make && make install

安装后,会出现这个 Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20100525/

我们把这个路径复制一下,然后,把这个路径下的模块写到xcacahe的配置文件下:

mkdir /etc/php.d

cp xcache.ini /etc/php.d/

vim /etc/php.d/xcache.ini

修改下面项:

extension =/usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

重启一下服务器:service httpd24 restart

然后,我们在上面安装一个phpadmin:

unzip phpMyAdmin-4.0.5-all-languages.zip

mv phpMyAdmin-4.0.5-all-languages /usr/local/apache/htdocs/phpadmin

cd /usr/local/apache/htdocs/phpadmin/

提供phpadmin的配置文件:

cp config.sample.inc.php config.inc.php

编辑这个配置文件,修改这一项:

$cfg['Servers'][$i]['host'] = '192.168.236.129';

lamp平台 php解析器基于模块和php-fpm

我们打开浏览器,测试一下,说明我们的配置没有问题的!!

下一部分,我要做php解析器是基于fpm的,我会把上面的php解析器基于http模块的功能去除,然后,我们再到mysql的主机上编译php。

http服务器:192.168.236.128

php解析器 mysql服务器:192.168.236.129

下面我们开始切换到192.168.236.129主机上编译php:

tar xf php-5.4.19.tar.bz2

cd php-5.4.19

./configure –prefix=/usr/local/php –enable-fpm –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-openssl –with-zlib –with-bz2 –with-libxml-dir=/usr –enable-xml –with-jpeg-dir –with-png-dir –with-freetype-dir –enable-mbstring –with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –enable-sockets –enable-zip

make && make install

给fpm提供服务脚本:

cp sapi/fpm/init.d.php-fpm /etc/init.d/fpm

chmod +x /etc/init.d/fpm

chkconfig –add fpm

给php解析器提供配置文件:

cp php.ini-production /etc/php.ini

为fpm提供服务配置文件:

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

编辑这个配置文件,修改以下几项:

listen = 192.168.236.129:9000

pm.max_children = 30

pm.start_servers = 5

pm.min_spare_servers = 5

pm.max_spare_servers = 8

启动服务:service fpm start

ss -tnlp 查看服务是否开启:

users:(("master",1947,12))

LISTEN      0      128                                                                192.168.236.129:9000                                                                            *:*      users:(("php-fpm",122099,7),("php-fpm",122100,0),("php-fpm",122101,0),("php-fpm",122102,0),("php-fpm",122103,0),("php-fpm",122104,0))

好了,我们再为php解析器提供xcache:

tar xf xcache-3.1.0.tar.bz2

cd xcache-3.1.0

[root@www 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

这是为了xcache提供configure文件。

./configure –enable-xcache –with-php-config=/usr/local/php/bin/php-config –sysconfdir=/etc/php.d

make && make install

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

我们把这个路径复制一下,然后,把这个路径下的模块写到xcacahe的配置文件下:

mkdir /etc/php.d

cp xcache.ini /etc/php.d/

vim /etc/php.d/xcache.ini

修改下面项:

extension =/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so

重启一下服务:

service fpm restartservice fpm restart

配置http主机(192.168.236.128)

vim /etc/http24/httpd.conf

把这项注释(表示不启用php解析器作为http功能里):

#LoadModule php5_module        modules/libphp5.so

把下面的功能启动:

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

然后在后面的配置文件中增加以下配置:

ProxyRequests Off

ProxyPassMatch  ^/(.*\.php)$ fcgi://192.168.236.129:9000/php/$1

切换到php解析器的主机,为这个主机提供phpadmin作为测试:

mkdir /php

mv phpMyAdmin-4.0.5-all-languages /php/phpadmin

cd /php/phpadmin/

提供phpadmin的配置文件:

cp config.sample.inc.php config.inc.php

好了!我们去数据库创建一个本地用户,然后,我们打开浏览器测试一下:

lamp平台 php解析器基于模块和php-fpm

实验完毕!!

 
标签: 数据库 PHP-FPM
反对 0举报 0 评论 0
 

免责声明:本文仅代表作者个人观点,与乐学笔记(本网)无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
    本网站有部分内容均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,若因作品内容、知识产权、版权和其他问题,请及时提供相关证明等材料并与我们留言联系,本网站将在规定时间内给予删除等相关处理.

  • 【Rust】标准库-Result rust数据库
    环境Rust 1.56.1VSCode 1.61.2概念参考:https://doc.rust-lang.org/stable/rust-by-example/std/result.html示例main.rsmod checked {#[derive(Debug)]pub enum MathError {DivisionByZero,NonPositiveLogarithm,NegativeSquareRoot,}pub type MathResult =
    02-09
  • 【Rust】标准库-引用 rust 数据库框架
    环境Rust 1.56.1VSCode 1.61.2概念参考:https://doc.rust-lang.org/stable/rust-by-example/std/rc.html示例rust 使用 Rc 来实现引用计数。main.rsuse std::rc::Rc;fn main() {let rc_examples = "Rc examples".to_string();{println!("--- rc_a is created
    02-09
  • DELPHI中使用UNIDAC连接ORACLE数据库
    


		
DELPHI中使用UNIDAC连接ORACLE数据库
    DELPHI中使用UNIDAC连接ORACLE数据库
      最近在DELPHI中使用到UNIDAC连接到oracle数据库,这样可以不要安装oracle客户端,比较方便使用;所以简单学习了一下,主要是用到查询和执行存储过程,其中存储过程我测试了没有返回参数、有返回参数、有多高返回参数、有返回游标等存储过程,没有深入研究
    02-09
  • Perl操作Mysql数据库 perl操作excel
    一. 安装DBI模块步骤1:从TOOLS栏目中下载DBI.zip,下载完后用winzip解开到一个temp目录,共有三个文件:ReadmeDBI.ppdDBI.tar.gz步骤2: 在DOS窗口下,temp目录中运行下面的DOS命令:ppm install DBI.ppd 如果提示无效命令,可在perl/bin目录下运行 二. 安装DBD
    02-09
  • 在OS X系统中配置Ruby on Rails使其可以访问Sql
    经过大半天的折腾,终于可以让RoR在OS X系统里访问Sql Server数据库了。这里记录一下操作的过程,免得以后忘了。第一步,安装FreeTDS从FreeTDS的官网上下载最新的稳定版的压缩包,然后,遵照这里的说明进行手工编译(好怀念微软的Setup.exe和*.msi啊),其中
    02-09
  • 小程序-列表页跳详情页(不在数据库)
    1.缓存localstorage,可以长期保存数据2.绑定到view层id='',只要显示历史记录,就能携带id到详情页e.currentTarget.id访问点击当前的view的id
    02-09
  • Mysql数据库一个小程序实现自动创建分表。
    每当跨月的时候也是系统出问题最多的时候,没有表和字段缺失是两个最常见的错误。为了解决这个问题,研究了一下mysql的 information_schema 表:information_schema这张数据表保存了MySQL服务器所有数据库的信息。如数据库名,数据库的表,表栏的数据类型与访
    02-09
  • C#连接本地Access数据库及简单操作的winform小程序
    C#连接本地Access数据库及简单操作的winform小
    连接本地Access数据库及简单操作的winform小程序一、准备工作用Access创建一个数据库并创建一个表格。(对于非远程数据库,Access十分简单。表格可参考三、界面设计)。二、代码using System;using System.Collections.Generic;using System.ComponentModel;u
    02-09
  • 解决小程序云函数操作数据库回调不执行
    背景最近写个微信小程序,在云函数中操作数据库时,明明操作成功了,理应回调success,却没有;而在小程序端,一样的代码,却能成功回调。 问题原因参见官方文档:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-server-api/init.html
    02-09
  • Rust 连接 SQLite 数据库
    Rust 连接 SQLite 数据库
    使用 Rust 语言连接操作 SQLite 数据库,我使用 rusqlite 这个 crate。看例子:首先,使用 cargo 创建一个 Rust 项目,然后添加依赖 rusqlite: 来到 main.rs,其余所有的代码都写在这里。首先引入 rusqlite 相关的类型,并建立一个 Person struct:Person
    02-09
点击排行