lamp平臺 php解析器基于模塊和php-fpm

首先,我先介紹一下實驗環境:

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(這個步驟要兩個機子上都做好?。?/p>

編譯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';

`T)W$56@LLN2W7HNHRW4]1C.png

我們打開瀏覽器,測試一下,說明我們的配置沒有問題的??!

下一部分,我要做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

好了!我們去數據庫創建一個本地用戶,然后,我們打開瀏覽器測試一下:

ENP3`)L[(U8R~D}W4(Q37ST.png

實驗完畢??!

原創文章,作者:13-廣州-楊過,如若轉載,請注明出處:http://www.www58058.com/7705

(0)
13-廣州-楊過13-廣州-楊過
上一篇 2015-08-31
下一篇 2015-08-31

相關推薦

  • Linux終端類型

      終端是一種字符型設備,它有多種類型,通常使用tty來簡稱各種類型的終端設備。   在Linux系統的設備特殊文件目錄/dev/下,終端特殊設備文件一般有以下幾種:   1、串行端口終端 /dev/ttySn     串行端口終端是使用計算機串行端口連接的終端設備。計算機把每個串行端口都看作是一個…

    Linux干貨 2016-10-14
  • Linux學習練習及作業&day07-正則表達式&文本處理工具

    第一部分、使用基本的文本處理工具(非grep)練習以下5題。 1、找出ifconfig命令結果中本機的所有IPv4地址     [root@localhost ~]# ifconfig |head -2 |tail -1     …

    Linux干貨 2016-08-08
  • 第七周

    1、創建一個10G分區,并格式為ext4文件系統;    (1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl; 第一步先在磁盤上創建分區:fdisk /dev/sdc n –> e –> 5 –> default &#…

    Linux干貨 2017-05-18
  • 在Centos系統上安裝EPEL擴展源以及安裝htop工具

        Htop是一個強大的進程管理前端工具,但這是一個擴展工具,一般在Centos系統源中并沒有,所有我們需要到fedora-epel源中下載。         EPEL即Extra Packages for Enterprise Lin…

    Linux干貨 2016-02-14
  • 搭建博客程序wordpress

    根據需求安裝相關軟件,搭建實驗環境: #CentOS 6:Httpd,PHP,mysql-server,php-mysql #CentOS 7:Httpd,php,php-mysql mariadb-server 下載wordpress程序,并解壓至/var/www/html/目錄下 [root@centos077 html]# pwd /var/www/h…

    2017-04-28
  • 一次簡單的內核編譯(一)

    一、編譯環境   1、準備一臺測試機,放置兩塊硬盤   2、安裝"Development Tools"和"Server Platform Development"編譯環境   3、內核下載地址:https://www.kernel.org(本人使用的是3.10版本)   4、下載…

    Linux干貨 2015-06-01

評論列表(2條)

  • stanley
    stanley 2015-08-31 10:43

    代碼段最好能格式化,樣式會有較大改觀

  • bluesli
    bluesli 2015-09-01 07:55

    最好能講下什么是php-fpm, 跟apache里的php模塊有什么區別.

欧美性久久久久