天天看点

LAMP编译实现

一、简述LAMP:

二、HTTP2.4编译安装

三、源码安装MySQL5.6

四、源码安装php-5.6

五、配置http访问PHP

六、配置php访问mysql

实验环境为:

    php-fpm和msyql编译为同一台主机(CentOS6.9)

    httpd单独一台主机(CentOS6.9)

client http(请求index.php或者index.html)

    --->apache(httpd web服务器响应,如果是静态文件,则直接响应,如果是动态请求则转向下一步) 

        --->php 接受请求(php解释器通过fastcgi响应,如果需要查询数据则转向一下) 

            --->透过mysql客户端查询数据库(mysql驱动)  

                --->mysql服务器响应数据库查询(返回查询结果)

LAMP:其中apache、http、php都可以分别安装到不同机器上

http与php结合的方式:

    module

    fcgi

    php-fpm

httpd依赖于反向代理模块以及专用于fastcgi反向代理模块

    httpd-2.2默认没有附带专用fastcgi反向代理模块,所以需要独立安装;

    httpd-2.4已自带fastcgi反向模块,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩充       

    httpd-2.4以前的版本中,要么把PHP作为Apache的模块运行,要么添加一个第三方模块支持PHP-FPM实现。 

由于php有相关依赖性因此建议:

    安装次序为httpd或mysql,再装php。

实验环境:CenOS6.9 kernel-2.6

源码编译步骤:

    配置(configure),通常依赖gcc编译器,binutils,glibc。配置软件特性,检查编译环境,生成 Makefile文件

    编译(make)

    安装(make install)

--prefix配置安装路径,如果不配置该选项,安装后可执行文件默认放在/usr/local/bin,

    库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc,其它的资源文件放在/usr /local/share

    如果配置--prefix,如: ./configure --prefix=/usr/local/test

    用了—prefix选项的另一个好处是卸载软件或移植软件。

    当某个安装的软件不再需要时,只须简单的删除该安装目录,就可以把软件卸载得干干净净;

    移植软件只需拷贝整个目录到另外一个机器即可(相同的操作系统)。

    卸载程序,也可以在原来的make目录下用一次make uninstall,但前提是make文件指定过uninstall。

1.依赖关系解决

依赖到的:apr、apr-util、pcre-devel、openssl-devel

http://archive.apache.org/dist/apr/  下载apr-1.5.0.tar.gz  apr-util-1.5.1.tar.gz  

httpd-2.4 依賴于1.4+及以上版本的apr

yum install pcre-devel openssl-devel gcc //这两个依赖手动安装

编译步骤:

tar xvf apr-1.5.0.tar.gz

cd apr-1.5.0

./config --prefix=/usr/local/apr

make && make install 

tar xvf apr-util-1.5.1.tar.gz

cd apr-util-1.5.1

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

//编译出问题。make clean清理重新编译

2.编译http2.4

tar xvf httpd-2.4.29.tar.gz

cd httpd-2.4.29

<code>.</code><code>/configure</code> <code>--with-apr=</code><code>/usr/local/apr</code> <code>--with-apr-util=</code><code>/usr/local/apr-util/</code> <code>--prefix=</code><code>/usr/local/http24</code> <code>--sysconfdir=</code><code>/etc/http24/</code> <code>--</code><code>enable</code><code>-so --</code><code>enable</code><code>-ssl --</code><code>enable</code><code>-rewrite --</code><code>enable</code><code>-zlib --</code><code>enable</code><code>-cgi --with-pcre --with-mpm=prefork --</code><code>enable</code><code>-modules=most --</code><code>enable</code><code>-mpms-shared=all</code>

    --sysconfdir=/etc/httpd24  指定配置文件路径

    --enable-so  启动模块动态装卸载

    --enable-ssl 编译ssl模块

    --enable-cgi 支持cgi机制(能够让静态web服务器能够解析动态请求的一个协议)

    --enable-rewrite  支持url重写     --Author : Leshami

    --with-zlib  支持数据包压缩       --Blog   : http://blog.csdn.net/leshami

    --with-pcre  支持正则表达式

    --with-apr=/usr/local/apr  指明依赖的apr所在目录

    --with-apr-util=/usr/local/apr-util/  指明依赖的apr-util所在的目录

    --enable-modules=most      启用的模块

    --enable-mpms-shared=all   以共享方式编译的模块

    --with-mpm=prefork         指明httpd的工作方式为prefork

执行make的是否发现错误:

<code>exports.c:1250: note: previous definition of </code><code>'ap_hack_apr_xml_insert_uri'</code> <code>was here</code>

<code>exports.c:1675: error: redefinition of </code><code>'ap_hack_apu_version'</code>

<code>exports.c:1259: note: previous definition of </code><code>'ap_hack_apu_version'</code> <code>was here</code>

<code>exports.c:1676: error: redefinition of </code><code>'ap_hack_apu_version_string'</code>

<code>exports.c:1260: note: previous definition of </code><code>'ap_hack_apu_version_string'</code> <code>was here</code>

<code>........</code>

[root@localhost httpd-2.4.29]# cat /tmp/http.bianyi |grep -v note  //http.bianyi是所有编译提示"previos definition"的

[root@localhost httpd-2.4.29]# a=$(cat /tmp/http.bianyi |grep -v note  |sort -nr -k2 |cut -d':' -f2 )

[root@localhost httpd-2.4.29]# for i in $a; do sed -i "${i}d" ./server/exports.c ;done  //sed替换变量的时候用"${}"

[root@localhost httpd-2.4.29]# cat ./server/exports.c  |grep ap_hack_apu_version_string

const void *ap_hack_apu_version_string = (const void *)apu_version_string;

//发现重复定义了,注释或者删除其中一个。

make clean &amp;&amp; make install 

3.后续步骤:

vim /etc/man.config  //配置man手册

MANPATH /usr/local/httpd24/man

[root@localhost httpd-2.4.29]# echo "export PATH=$PATH:/usr/local/http24/bin" &gt; /etc/profile.d/httpd24.sh //命令手册

[root@localhost httpd-2.4.29]# source /etc/profile

[root@localhost http24]# cd /usr/local/http24/

注:启动文件pid文件位置要配置成与/usr/local/apache/bin/apachectl -V看到的pid位置一致

[root@localhost http24]# ./bin/apachectl -V

<code>Server version: Apache</code><code>/2</code><code>.4.29 (Unix)</code>

<code>Server built:   Feb  4 2018 03:14:13</code>

<code>Server's Module Magic Number: 20120211:68</code>

<code>Server loaded:  APR 1.5.0, APR-UTIL 1.5.1</code>

<code>Compiled using: APR 1.5.0, APR-UTIL 1.5.1</code>

<code>Architecture:   64-bit</code>

<code>Server MPM:     prefork</code>

<code>  </code><code>threaded:     no</code>

<code>    </code><code>forked:     </code><code>yes</code> <code>(variable process count)</code>

<code>Server compiled with....</code>

<code> </code><code>-D APR_HAS_SENDFILE</code>

<code> </code><code>-D APR_HAS_MMAP</code>

<code> </code><code>-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)</code>

<code> </code><code>-D APR_USE_SYSVSEM_SERIALIZE</code>

<code> </code><code>-D APR_USE_PTHREAD_SERIALIZE</code>

<code> </code><code>-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT</code>

<code> </code><code>-D APR_HAS_OTHER_CHILD</code>

<code> </code><code>-D AP_HAVE_RELIABLE_PIPED_LOGS</code>

<code> </code><code>-D DYNAMIC_MODULE_LIMIT=256</code>

<code> </code><code>-D HTTPD_ROOT=</code><code>"/usr/local/http24"</code>

<code> </code><code>-D SUEXEC_BIN=</code><code>"/usr/local/http24/bin/suexec"</code>

<code> </code><code>-D DEFAULT_PIDLOG=</code><code>"logs/httpd.pid"</code>

<code> </code><code>-D DEFAULT_SCOREBOARD=</code><code>"logs/apache_runtime_status"</code>

<code> </code><code>-D DEFAULT_ERRORLOG=</code><code>"logs/error_log"</code>

<code> </code><code>-D AP_TYPES_CONFIG_FILE=</code><code>"/etc/http24//mime.types"</code>

<code> </code><code>-D SERVER_CONFIG_FILE=</code><code>"/etc/http24//httpd.conf"</code>

[root@localhost http24]# ./bin/apachectl -V |grep -i pid

 -D DEFAULT_PIDLOG="logs/httpd.pid"

启动脚本:/etc/init.d/httpd24 

<code>[root@localhost init.d]</code><code># cat /etc/init.d/httpd |grep -v "^#"</code>

<code>. </code><code>/etc/rc</code><code>.d</code><code>/init</code><code>.d</code><code>/functions</code>

<code>if</code> <code>[ -f </code><code>/etc/http24</code> <code>]; </code><code>then</code>

<code>        </code><code>. </code><code>/etc/http24</code>

<code>fi</code>

<code>HTTPD_LANG=${HTTPD_LANG-</code><code>"C"</code><code>}</code>

<code>INITLOG_ARGS=</code><code>""</code>

<code>apachectl=</code><code>/usr/local/http24/bin/apachectl</code>

<code>httpd=${HTTPD-</code><code>/usr/local/http24/bin/httpd</code><code>}</code>

<code>prog=httpd</code>

<code>pidfile=${PIDFILE-</code><code>/usr/local/http24/logs/httpd</code><code>.pid}</code>

<code>lockfile=${LOCKFILE-</code><code>/var/lock/subsys/httpd24</code><code>}</code>

<code>RETVAL=0</code>

<code>STOP_TIMEOUT=${STOP_TIMEOUT-10}</code>

<code>start() {</code>

<code>        </code><code>echo</code> <code>-n $</code><code>"Starting $prog: "</code>

<code>        </code><code>LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS</code>

<code>        </code><code>RETVAL=$?</code>

<code>        </code><code>echo</code>

<code>        </code><code>[ $RETVAL = 0 ] &amp;&amp; </code><code>touch</code> <code>${lockfile}</code>

<code>        </code><code>return</code> <code>$RETVAL</code>

<code>}</code>

<code>stop() {</code>

<code>        </code><code>status -p ${pidfile} $httpd &gt; </code><code>/dev/null</code>

<code>        </code><code>if</code> <code>[[ $? = 0 ]]; </code><code>then</code>

<code>                </code><code>echo</code> <code>-n $</code><code>"Stopping $prog: "</code>

<code>                </code><code>killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd</code>

<code>        </code><code>else</code>

<code>                </code><code>success</code>

<code>        </code><code>fi</code>

<code>        </code><code>[ $RETVAL = 0 ] &amp;&amp; </code><code>rm</code> <code>-f ${lockfile} ${pidfile}</code>

<code>reload() {</code>

<code>    </code><code>echo</code> <code>-n $</code><code>"Reloading $prog: "</code>

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

<code>        </code><code>RETVAL=6</code>

<code>        </code><code>echo</code> <code>$</code><code>"not reloading due to configuration syntax error"</code>

<code>        </code><code>failure $</code><code>"not reloading $httpd due to configuration syntax error"</code>

<code>    </code><code>else</code>

<code>        </code><code># Force LSB behaviour from killproc</code>

<code>        </code><code>LSB=1 killproc -p ${pidfile} $httpd -HUP</code>

<code>        </code><code>if</code> <code>[ $RETVAL -</code><code>eq</code> <code>7 ]; </code><code>then</code>

<code>            </code><code>failure $</code><code>"httpd shutdown"</code>

<code>    </code><code>fi</code>

<code>    </code><code>echo</code>

<code>case</code> <code>"$1"</code> <code>in</code>

<code>  </code><code>start)</code>

<code>        </code><code>start</code>

<code>        </code><code>;;</code>

<code>  </code><code>stop)</code>

<code>        </code><code>stop</code>

<code>  </code><code>status)</code>

<code>        </code><code>status -p ${pidfile} $httpd</code>

<code>  </code><code>restart)</code>

<code>  </code><code>condrestart|try-restart)</code>

<code>        </code><code>if</code> <code>status -p ${pidfile} $httpd &gt;&amp;</code><code>/dev/null</code><code>; </code><code>then</code>

<code>                </code><code>stop</code>

<code>                </code><code>start</code>

<code>  </code><code>force-reload|reload)</code>

<code>        </code><code>reload</code>

<code>  </code><code>graceful|help|configtest|fullstatus)</code>

<code>        </code><code>$apachectl $@</code>

<code>  </code><code>*)</code>

<code>        </code><code>echo</code> <code>$</code><code>"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"</code>

<code>        </code><code>RETVAL=2</code>

<code>esac</code>

<code>exit</code> <code>$RETVAL</code>

[root@localhost init.d]# cat /etc/init.d/httpd |grep -v "^#"

[root@localhost init.d]# chkconfig --add httpd

[root@localhost init.d]# service httpd status

4.测试访问

vim /etc/http24/httpd.conf //尾部追加几行

<code>&lt;Location </code><code>/server-status</code><code>&gt;</code>

<code>    </code><code>SetHandler server-status</code>

<code>    </code><code>Allow from 192.168.2.0</code>

<code>&lt;</code><code>/Location</code><code>&gt;</code>

[root@localhost http24]# cat ./htdocs/index.html &lt;&lt; EOF

<code>&gt; &lt;html&gt;</code>

<code>&gt;   &lt;body&gt; &lt;h1&gt; It works &lt;</code><code>/h1</code><code>&gt; &lt;</code><code>/body</code><code>&gt;</code>

<code>&gt; &lt;</code><code>/html</code><code>&gt;</code>

<code>&gt; EOF</code>

https://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html //参数说明

1.依赖关系

有关MySQL编译参数

<code>  </code><code>CMAKE_BUILD_TYPE            编译的版本类型:RelWithDebInfo和Debug,不同之处是RelWithDebInfo会进行优化。</code>

<code>  </code><code>CMAKE_INSTALL_PREFIX        指定</code><code>make</code> <code>install</code><code>安装的目标路径。</code>

<code>  </code><code>SYSCONFDIR                  指定配置文件的默认路径。</code>

<code>  </code><code>MYSQL_DATADIR               指定data目录的默认路径。</code>

<code>  </code><code>WITH_DEBUG                  指定是否有debugging信息,一般用于源码调试时,打开WITH_DEBUG,生产环境关闭。</code>

<code>  </code><code>ENABLED_PROFILING           指定是否可以使用show profile显示操作执行的详细信息。</code>

<code>  </code><code>DEFAULT_CHARSET             指定默认字符集,可以在启动的配置文件中指定。</code>

<code>  </code><code>DEFAULT_COLLATION           指定默认字符比较、排序的规则。</code>

<code>  </code><code>WITH_EXTRA_CHARSETS         指定其他可能使用的字符集。</code>

<code>  </code><code>WITH_SSL                    指定SSL的类型,从5.6.6开始默认bundled类型,此外也可以指定SSL库的路径地址。</code>

<code>  </code><code>WITH_ZLIB                   指定zlib的类型,用于压缩功能。</code>

<code>  </code><code>ENABLED_LOCAL_INFILE        指定是否允许使用load data infile功能。</code>

<code>  </code><code>WITH_EMBEDDED_SERVER        指定是否编译libmysqld嵌入式库。</code>

<code>  </code><code>INSTALL_LAYOUT              指定安装的布局类型。</code>

<code>  </code><code>WITH_storage_STORAGE_ENGINE 指定编译支持的存储引擎,默认支持MyISAM,MERGE,MEMORY,CSV存储引擎。</code>

详细参数可参考 http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html    

yum install gcc gcc+c++  cmake bison m4 ncurses-devel perl per-devel bison-devel autoconf -y  //MySQL5.5之后要用cmake编译

==========================================//源码安装和下载方式(可选)

# wget http://www.cmake.org/files/v2.8/cmake-2.8.11.1.tar.gz

# wget http://ftp.gnu.org/gnu/bison/bison-2.7.tar.gz

# wget http://ftp.gnu.org/gnu/m4/m4-1.4.16.tar.gz

========================================================

源码包下载方法:https://www.mysql.com/-&gt;DOWNLOADS-&gt;Archives-&gt;MySQL Community Server-&gt;Operating System:[Source Code]-&gt;OS Version:[Generic Linux]

https://downloads.mysql.com/archives/get/file/mysql-5.6.12.tar.gz

2.编译安装

[root@www mysql-5.6.12]# groupadd mysql

[root@www mysql-5.6.12]# useradd -g mysql mysql

[root@www mysql-5.6.12]# mkdir /usr/local/mysql

[root@www mysql-5.6.12]# chown mysql:mysql /data /usr/local/mysql

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock  \

-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=utf8,gbk  \

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/ -DSYSCONFDIR=/etc/mysql/ \

-DWITH_SSL=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1

预编译出错,删除下面文件,重新编译安装。

#rm -f CMakeCache.txt     

make clean 清空make

make报错:

初始化操作:

cd /usr/local/mysql

chmod +x scripts/mysql_install_db

scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

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

chmod +x /usr/init.d/mysqld

chkconfig mysqld on

echo "export PATH=$PATH:/usr/local/mysql/bin" &gt;&gt; /etc/profile

source /etc/profile

[root@localhost mysql]# mysql -uroot

mysql&gt; SET PASSWORD = PASSWORD('mysql5635');

注意:实验环境是php和mysql一台机器,http独立一台

1.依赖处理

[root@localhost yum.repos.d]# yum install libmcrypt libmcrypt-devel mhash mhash-devel libevent libevent-devel libxml2 libxml2-devel bzip2-devel libcurl-devel openssl-devel -y

mcrypt扩展库可以实现加密解密功能,就是既能将明文加密,也可以密文还原。

mhash是基于离散数学原理的不可逆向的php加密方式扩展库,其在默认情况下不开启。

mhash的可以用于创建校验数值,消息摘要,消息认证码,以及无需原文的关键信息保存(如密码)等。

libevent是一个异步事件通知库文件,其API提供了在某文件描述上发生某事件时或其超时时执行回调函数的机制

    它主要用来替换事件驱动的网络服务器上的event loop机制。

    目前来说, libevent支持/dev/poll、kqueue、select、poll、epoll及Solaris的event ports。

bzip2 是一个基于Burrows-Wheeler 变换的无损压缩软件能够高效的完成文件数据的压缩

libcurl主要功能就是用不同的协议连接和沟通不同的服务器,也就是相当封装了的sockPHP,允许你用不同的协议连接和沟通不同的服务器

图形相关的rpm包 //对应的错误提示:JIS-mapped Japanese font support in GD

    # yum install libjpeg-devel libpng-devel freetype-devel

2.编译安装    

<code>.</code><code>/configure</code> <code>\ </code>

<code>--prefix=</code><code>/usr/local/php</code> <code>\</code>

<code>--with-config-</code><code>file</code><code>-path=</code><code>/etc/php</code> <code>\</code>

<code>--</code><code>enable</code><code>-inline-optimization \</code>

<code>--disable-debug \</code>

<code>--disable-rpath \</code>

<code>--</code><code>enable</code><code>-shared \</code>

<code>--</code><code>enable</code><code>-opcache \</code>

<code>--</code><code>enable</code><code>-fpm \</code>

<code>--with-mysql=</code><code>/usr/local/mysql</code> <code>\</code>

<code>--with-mysqli=</code><code>/usr/local/mysql/bin/mysql_config</code> <code>\</code>

<code>--with-pdo-mysql=</code><code>/usr/local/mysql</code> <code>\</code>

<code>--with-gettext \</code>

<code>--</code><code>enable</code><code>-mbstring \</code>

<code>--with-iconv \</code>

<code>--with-mcrypt \</code>

<code>--with-mhash \</code>

<code>--with-openssl \</code>

<code>--</code><code>enable</code><code>-bcmath \</code>

<code>--</code><code>enable</code><code>-soap \</code>

<code>--with-libxml-</code><code>dir</code> <code>\</code>

<code>--</code><code>enable</code><code>-pcntl \</code>

<code>--</code><code>enable</code><code>-shmop \</code>

<code>--</code><code>enable</code><code>-sysvmsg \</code>

<code>--</code><code>enable</code><code>-sysvsem \</code>

<code>--</code><code>enable</code><code>-sysvshm \</code>

<code>--</code><code>enable</code><code>-sockets \</code>

<code>--with-curl \</code>

<code>--with-zlib \</code>

<code>--</code><code>enable</code><code>-zip \</code>

<code>--with-bz2 \</code>

<code>--with-gd \</code>

<code>--with-freetype-</code><code>dir</code> <code>\</code>

<code>--with-jpeg-</code><code>dir</code> <code>\</code>

<code>--with-png-</code><code>dir</code>

报错信息:checking for known struct flock definition... configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no

[root@wolf php-5.6.33]# echo "/usr/local/mysql/lib" &gt;&gt; /etc/ld.so.conf.d/local.conf    //mysql的库文件路径

注意:

<code>--with-mysql=</code><code>/usr/local/mysql</code> <code>//mysql</code><code>的安装目录</code>

<code>--with-mysqli=</code><code>/usr/local/mysql/bin/mysql_config</code> <code>\  </code><code>//mysqli</code><code>扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定。</code>

<code>--with-apxs2=</code><code>/usr/local/apache/bin/apxs</code> <code>//</code><code>整合 apache,apxs功能是使用mod_so中的LoadModule指令,加载指定模块到 apache,要求 apache 要打开SO模块</code>

<code>--prefix=</code><code>/usr/local/php</code> <code>//</code><code># 指定 php 安装目录</code>

<code>--with-config-</code><code>file</code><code>-path=</code><code>/usr/local/php/etc</code> <code>//</code><code># 指定php.ini位置</code>

<code># 选项指令 --with-iconv-dir 用于 PHP 编译时指定 iconv 在系统里的路径,否则会扫描默认路径。</code>

<code>--with-iconv-</code><code>dir</code><code>=</code><code>/usr/local</code> 

<code>--with-freetype-</code><code>dir</code>   <code>打开对freetype字体库的支持 </code>

<code>--with-jpeg-</code><code>dir</code>   <code>打开对jpeg图片的支持 </code>

<code>--with-png-</code><code>dir</code>   <code>打开对png图片的支持 </code>

<code>--with-zlib-</code><code>dir</code>   <code>打开zlib库的支持,用于http压缩传输</code>

<code>--with-libxml-</code><code>dir</code>   <code>打开libxml2库的支持</code>

<code>--disable-rpath    关闭额外的运行库文件 </code>

<code>--</code><code>enable</code><code>-bcmath    打开图片大小调整,用到zabbix监控的时候用到了这个模块</code>

<code>--</code><code>enable</code><code>-shmop --</code><code>enable</code><code>-sysvsem  这样就使得你的PHP系统可以处理相关的IPC函数了。</code>

<code>--</code><code>enable</code><code>-inline-optimization  优化线程</code>

<code>--with-curl    打开curl浏览工具的支持 </code>

<code>--with-curlwrappers    运用curl工具打开url流 </code>

<code>--</code><code>enable</code><code>-mbregex</code>

<code>--</code><code>enable</code><code>-fpm 打上PHP-fpm 补丁后才有这个参数,CGI方式安装的启动程序</code>

<code>--</code><code>enable</code><code>-mbstring    多字节,字符串的支持 </code>

<code>--with-mcrypt                    mcrypt算法扩展</code>

<code>--with-mhash                     mhash算法扩展</code>

<code>--with-gd    打开gd库的支持 </code>

<code>--</code><code>enable</code><code>-gd-native-ttf   支持TrueType字符串函数库</code>

<code>--with-openssl      openssl的支持,加密传输https时用到的</code>

<code>--</code><code>enable</code><code>-pcntl   freeTDS需要用到的,可能是链接mssql 才用到</code>

<code>--</code><code>enable</code><code>-sockets     打开 sockets 支持</code>

<code>--with-xmlrpc    打开xml-rpc的c语言 </code>

<code>--</code><code>enable</code><code>-zip   打开对zip的支持 </code>

<code>--</code><code>enable</code><code>-</code><code>ftp</code>   <code>打开</code><code>ftp</code><code>的支持 </code>

<code>--with-bz2    打开对bz2文件的支持        </code>

<code>--without-iconv   关闭iconv函数,字符集间的转换 </code>

<code>--with-ttf     打开freetype1.*的支持,可以不加了 </code>

<code>--with-xsl     打开XSLT 文件支持,扩展了libXML2库 ,需要libxslt软件 </code>

<code>--with-gettext     打开gnu 的gettext 支持,编码库用到 </code>

<code>--with-pear    打开pear命令的支持,PHP扩展用的 </code>

<code>--</code><code>enable</code><code>-calendar    打开日历扩展功能</code>

<code>--</code><code>enable</code><code>-exif    图片的元数据支持 </code>

<code>--</code><code>enable</code><code>-magic-quotes    魔术引用的支持 </code>

<code>--disable-debug    关闭调试模式 </code>

<code>--with-mime-magic=</code><code>/usr/share/file/magic</code><code>.mime      魔术头文件位置</code>

<code>CGI方式安装才用的参数</code>

<code>--</code><code>enable</code><code>-fastCGI            支持fastcgi方式启动PHP</code>

<code>--</code><code>enable</code><code>-force-CGI-redirect        重定向方式启动PHP</code>

<code>--with-ncurses         支持ncurses 屏幕绘制以及基于文本终端的图形互动功能的动态库</code>

<code>--with-gmp  应该是支持一种规范</code>

<code>--</code><code>enable</code><code>-dbase                     建立DBA 作为共享模块</code>

<code>--with-pcre-</code><code>dir</code><code>=</code><code>/usr/local/bin/pcre-config</code>      <code>perl的正则库案安装位置</code>

<code>--</code><code>enable</code><code>-zend-multibyte         支持zend的多字节</code>

3.后续处理

[root@wolf php]# echo "export PATH=$PATH:/usr/local/php/bin:/usr/loca/php/sin" &gt; /etc/profile.d/php.sh

[root@wolf php]# source /etc/profile

[root@wolf php-5.6.33]# cp php.ini-production /usr/local/php/etc/php.ini

[root@wolf php-5.6.33]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@wolf php-5.6.33]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@wolf php-5.6.33]# chmod +x /etc/init.d/php-fpm

[root@wolf php-5.6.33]# chkconfig --add php-fpm

[root@wolf php-5.6.33]# vim /etc/man.config //添加MANPATH /usr/local/php/php

[root@wolf php]# chkconfig mysqld on

[root@wolf php]# chkconfig php-fpm on

[root@wolf php]# service php-fpm start

[root@wolf php]# php-fpm -t  //测试语法

4.修改php-fpm监听地址为非127.0.0.1

修改 /usr/local/php/etc/php-fpm.conf 

listen = 192.168.2.110:9000

原理:

1)、动态模块方式:

  prefork模式使用libphp5模块 

   worker和event模式则使用libphp5-zts模块

2)、CGI方式:

CGI(Common Gateway Interface 简称通用网关接口)。

CGI是外部应用程序(CGI程序)与Web服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的过程。

CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,

    CGI将Web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体。

其工作流程如下:

a、浏览器通过HTML表单或超链接请求指向一个CGI应用程序的URL。

b、服务器收发到请求。

c、服务器执行指定CGI应用程序(开启进程)

d、CGI应用程序执行所需要的操作,通常是基于浏览者输入的内容。

e、CGI应用程序把结果格式化为网络服务器和浏览器能够理解的文档(通常是HTML网页)。

f、网络服务器把结果返回到浏览器中(销毁进程)

3)、FastCGI方式:

    FastCGI像是一个常驻(long-live)型的CGI,它可以一直执行着,只要激活后,不会每次都要花费时间去fork一次。

    (这是CGI最为人诟病的fork-and-execute 模式)。

    它还支持分布式的运算, 即 FastCGI 程序可以在网站服务器以外的主机上执行并且接受来自其它网站服务器来的请求。

a、Web Server启动时载入FastCGI进程管理器(IIS ISAPI或Apache Module)

b、FastCGI进程管理器自身初始化,启动多个CGI解释器进程(可见多个php-cgi)并等待来自Web Server的连接。

c、当客户端请求到达Web Server时,FastCGI进程管理器选择并连接到一个CGI解释器。

    Web server将CGI环境变量和标准输入发送到FastCGI子进程php-cgi。

e、FastCGI子进程完成处理后将标准输出和错误信息从同一连接返回Web Server。

    当FastCGI子进程关闭连接时,请求便告处理完成。

   FastCGI子进程接着等待并处理来自FastCGI进程管理器(运行在Web Server中)的下一个连接。

   在CGI模式中,php-cgi在此便退出了。

4)、CGI与FastCGI两者差异主要在于:

    CGI在处理任何一个请求需要开启进程,销毁进程,开销较大

    FastCGI会在初始化的时候启动多个cgi进程,监听来自网络的请求;

    当处理完毕任务后则由FastCGI进程管理器回收管理,省去反复创建回收的开销。

1.单台机器上设置

# vim  /etc/httpd24/httpd.conf     ###注意此处,我这里是单独编译安装的httpd2.4版本,所以路径有所不同

<code>    </code><code>LoadModule proxy_module  modeles</code><code>/mod_proxy</code><code>.so</code>

<code>    </code><code>LoadModule proxy_fcgi_module modules</code><code>/mod_proxy_fcgi</code><code>.so</code>

<code>    </code><code>AddType  application</code><code>/x-httpd-php</code>  <code>.php   </code>

<code>    </code><code>AddType  application</code><code>/x-httpd-php-source</code>  <code>.phps</code>

<code>    </code><code>ProxyRequests Off     </code><code>###关闭正向代理,开启下行的反向代理</code>

<code>    </code><code>ProxyPassMatch ^/(.*\.php)$  fcgi:</code><code>//127</code><code>.0.0.1:9000</code><code>/usr/local/http24/htdocs/</code><code>$1</code>

# service httpd24 restart

    Stopping httpd24:             [  OK  ]

    Starting httpd24:             [  OK  ]

[root@localhost htdocs]# echo "

&lt;html&gt;

&lt;h1&gt; Test php page &lt;/h1&gt;

&lt;?php

phpinfo()

?&gt;

&lt;/html&gt;" &gt;&gt; /usr/local/http24/htdocs/test.php

2.分离式设置

# vim  /etc/httpd24/httpd.conf    

    LoadModule proxy_module  modeles/mod_proxy.so

    LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

    AddType  application/x-httpd-php  .php   

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

    ProxyRequests Off     

    ProxyPassMatch ^/(.*\.php)$  fcgi://192.168.2.110:9000/usr/local/http24/htdocs/$1

Aapache 在配置反向代理时,应指定PHP服务器的IP地址及相应端口号,前后端路径可以不一致,后端应指定绝对路径

    如前端为/var/www/html,后端为/website/www,则fcgi://127.0.0.1:9000/website/www/$1

php-fpm所在机器上创建测试页:

[root@wolf htdocs]#

[root@wolf htdocs]# echo "

&lt;/html&gt;" &gt;&gt; /htdocs/index.php

3.假如不能看到info界面

iptables -F 

setenforce 0

检查php-fpm.conf 地址和端口是否正确等

PHP与MySQL的连接有三种API接口分别是:

    PHP的MySQL扩展 

    PHP的mysqli扩展 

    PHP数据对象(PDO) 

这里直接少mysql扩展的用法,其他用法请自行参考博客:https://www.jianshu.com/p/0a79847c8151

1.PHP与Mysql扩展(本扩展自 PHP 5.5.0 起已废弃,并在将来会被移除),PHP原生的方式去连接数据库,是面向过程的

在php-fpm机器上

[root@wolf htdocs]# cat mysql.php

<code>&lt;?php</code>

<code>$mysql_conf = array(</code>

<code>    </code><code>'host'</code>    <code>=&gt; </code><code>'127.0.0.1:3306'</code><code>,</code>

<code>    </code><code>'db'</code>      <code>=&gt; </code><code>'mysql'</code><code>,</code>

<code>    </code><code>'db_user'</code> <code>=&gt; </code><code>'wolf'</code><code>,</code>

<code>    </code><code>'db_pwd'</code>  <code>=&gt; </code><code>'wolf'</code><code>,</code>

<code>    </code><code>);</code>

<code>$mysql_conn = @mysql_connect($mysql_conf[</code><code>'host'</code><code>], $mysql_conf[</code><code>'db_user'</code><code>], $mysql_conf[</code><code>'db_pwd'</code><code>]);</code>

<code>if</code> <code>(!$mysql_conn) {</code>

<code>    </code><code>die(</code><code>"could not connect to the database:\n"</code> <code>. mysql_error());</code><code>//</code><code>诊断连接错误</code>

<code>mysql_query(</code><code>"set names 'utf8'"</code><code>);</code><code>//</code><code>编码转化</code>

<code>$select_db = mysql_select_db($mysql_conf[</code><code>'db'</code><code>]);</code>

<code>if</code> <code>(!$select_db) {</code>

<code>    </code><code>die(</code><code>"could not connect to the db:\n"</code> <code>.  mysql_error());</code>

<code>else</code>

<code>    </code><code>echo</code> <code>"Succeed"</code><code>;</code>

<code>mysql_close($mysql_conn);</code>

<code>?&gt;</code>

不要忘了:vim /usr/local/mysql/my.cnf 在mysqld下添加skip_name_resolve=on

参考博客:

http://php.net/manual/zh/

http://blog.csdn.net/leshami/article/details/51944920

https://www.cnblogs.com/joshua317/articles/5989781.html

本文转自MT_IT51CTO博客,原文链接:http://blog.51cto.com/hmtk520/2069993,如需转载请自行联系原作者