搭建LAMP环境示例

作者: 计算机操作系统  发布:2019-12-26

apache httpd种类随笔:http://www.cnblogs.com/f-ck-need-u/p/7576137.html**

本文目录
1. 编译apache httpd
2. 编译php
 2.1 php编写翻译选项表明
 2.2 php编写翻译进程
 2.3 配置httpd使其转会动态央求给php-fpm
3. 为php安装xcache
 3.1 基本安装
 3.2 设置管理员后台
4 安装MySQL(MariaDB)
 4.1 起头化实例
 4.2 安装后的标准化操作
5 测试LAMP——搭建discuz论坛


本文给出搭建LAMP的步调,个中php使用的是php-fpm管理方法,php和MySQL(MariaDB卡塔尔国交互作用使用的是mysqlnd方式(另生机勃勃种是libmysql卡塔尔。最后交给二个php+mysql的论坛程序discuz的布阵进程。

正文给出搭建LAMP的步调,此中php使用的是php-fpm管理议程,php和MySQL(MariaDB卡塔尔(قطر‎交互作用使用的是mysqlnd形式(另一种是libmysql卡塔尔(قطر‎。最终交给叁个php+mysql的论坛程序discuz的摆放进度。

1. 编译apache httpd

这边只简单给出编写翻译httpd的步调,具体的编写翻译细节知识点见编译httpd细节。

httpd相关能源下载地址:http://archive.apache.org/dist/

安装依赖包。

yum -y install pcre pcre-devel expat-devel

编译apr和apr-util。

tar xf apr-1.6.2.tar.gz
tar xf arp-1.6.0.tar.gz
cd apr-1.6.0
./configure --prefix=/usr/local/apr 
make
make install
cd ../apr-util-1.6.2
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install

编译httpd。

tar xf httpd-2.4.27.tar.gz
cd httpd-2.4.27
./configure --prefix=/usr/local/apache --sysconfdir=/etc/apache --with-z --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-mpm=event --enable-mpms-shared=all

1. 编译apache httpd

此处只轻松给出编译httpd的步调,具体的编写翻译细节知识点见编译httpd细节。

httpd相关财富下载地址:http://archive.apache.org/dist/

设置信任包。

yum -y install pcre pcre-devel expat-devel

编译apr和apr-util。

tar xf apr-1.6.2.tar.gz
tar xf arp-1.6.0.tar.gz
cd apr-1.6.0
./configure --prefix=/usr/local/apr 
make
make install
cd ../apr-util-1.6.2
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install

编译httpd。

tar xf httpd-2.4.27.tar.gz
cd httpd-2.4.27
./configure --prefix=/usr/local/apache --sysconfdir=/etc/apache --with-z --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-mpm=event --enable-mpms-shared=all

编写翻译后的规范化操作:

# 设置man路径。
echo "MANPATH /usr/local/apache/man" >>/etc/man.config

# 设置PATH环境变量。
echo 'PATH=/usr/local/apache/bin:$PATH' >/etc/profile.d/apache.sh
source /etc/profile.d/apache.sh

# 输出头文件。
ln -s /usr/include /usr/local/apache/include

编写翻译后的标准化操作:

# 设置man路径。
echo "MANPATH /usr/local/apache/man" >>/etc/man.config

# 设置PATH环境变量。
echo 'PATH=/usr/local/apache/bin:$PATH' >/etc/profile.d/apache.sh
source /etc/profile.d/apache.sh

# 输出头文件。
ln -s /usr/include /usr/local/apache/include

提供劳动运维脚本:

提供不提供没多大所谓,因为apachectl或httpd命令本人能够管理进度的启动与停止,但自身管理启动和停止时不提供lock文件。

假使要提供的话,从yum安装的httpd提供的/usr/lib/systemd/system/httpd.service(systemd卡塔尔(قطر‎或/etc/init.d/httpd(sysV卡塔尔国拷贝后稍作改革就足以了。以下是依照自个儿上面编写翻译的情况做了改良后的systemd和sysV服务管理脚本。

以下是httpd的systemd服务管理脚本/usr/lib/systemd/system/httpd.service。

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/local/apache/bin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/local/apache/bin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

以下是httpd的sysV服务处理脚本/etc/rc.d/init.d/httpd。

#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible  
#           server implementing the current HTTP standards.
#
######################################################################
#  若httpd配置文件中指定了PidFile,则修改此脚本中的pidfile变量           #
######################################################################

. /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=/usr/local/apache/bin/apachectl
prog=httpd
pidfile=/usr/local/apache/logs/httpd.pid
lockfile=/var/lock/subsys/httpd
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
config=/etc/apache/httpd.conf

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd -f $config $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
    status -p ${pidfile} $httpd > /dev/null
    if [[ $? = 0 ]]; then
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
    else
        echo -n $"Stopping $prog: "
        success
    fi
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
        LSB=1 killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
        if [ $RETVAL -eq 7 ]; then
            failure $"httpd shutdown"
        fi
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
        status -p ${pidfile} $httpd
    RETVAL=$?
    ;;
  restart)
    stop
    start
    ;;
  condrestart|try-restart)
    if status -p ${pidfile} $httpd >&/dev/null; then
        stop
        start
    fi
    ;;
  force-reload|reload)
        reload
    ;;
  graceful|help|configtest|fullstatus)
    $apachectl $@
    RETVAL=$?
    ;;
  *)
    echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
    RETVAL=2
esac

exit $RETVAL

终极运维httpd。

service httpd start

提供服务运维脚本:

提供不提供没多大所谓,因为apachectl或httpd命令自个儿能够管理进度的启动和停止,但本人管理启动和停止时不提供lock文件。

蓬蓬勃勃旦要提供的话,从yum安装的httpd提供的/usr/lib/systemd/system/httpd.service(systemd卡塔尔(قطر‎或/etc/init.d/httpd(sysV卡塔尔拷贝后稍作修正就足以了。以下是坚守自个儿上边编写翻译的蒙受做了改变后的systemd和sysV服务管理脚本。

以下是httpd的systemd服务管理脚本/usr/lib/systemd/system/httpd.service。

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/local/apache/bin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/local/apache/bin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

以下是httpd的sysV服务管理脚本/etc/rc.d/init.d/httpd。

#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible  
#           server implementing the current HTTP standards.
#
######################################################################
#  若httpd配置文件中指定了PidFile,则修改此脚本中的pidfile变量           #
######################################################################

. /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=/usr/local/apache/bin/apachectl
prog=httpd
pidfile=/usr/local/apache/logs/httpd.pid
lockfile=/var/lock/subsys/httpd
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
config=/etc/apache/httpd.conf

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd -f $config $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
    status -p ${pidfile} $httpd > /dev/null
    if [[ $? = 0 ]]; then
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
    else
        echo -n $"Stopping $prog: "
        success
    fi
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
        LSB=1 killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
        if [ $RETVAL -eq 7 ]; then
            failure $"httpd shutdown"
        fi
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
        status -p ${pidfile} $httpd
    RETVAL=$?
    ;;
  restart)
    stop
    start
    ;;
  condrestart|try-restart)
    if status -p ${pidfile} $httpd >&/dev/null; then
        stop
        start
    fi
    ;;
  force-reload|reload)
        reload
    ;;
  graceful|help|configtest|fullstatus)
    $apachectl $@
    RETVAL=$?
    ;;
  *)
    echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
    RETVAL=2
esac

exit $RETVAL

末尾运维httpd。

service httpd start

2. 编译php

二种职业情势:CGI、作为模块参加到apache、fastcgi。最简便易行的是以模块方式步入到apache,此处演示的是php-fpm管理php-cgi格局。别的三种方法见php-cgi和httpd交互作用的秘技。

fastcgi模式的php-cgi,由php-fpm提供服务处理,它会依附布置文件运转一定数额的cgi进度,其私下认可监听的端口为9000,该服务符合规律办事亟待配备文件。约等于说fastcgi格局的php有七个结构文件,八个是php的安排文件,一个是php-fpm的配置文件。

虽说这里演示的是php-fpm管理方法,但有供给表明下,在Linux中假诺模块化安装php,不引入在选用Apache 2.x中使用线程化MPM(worker和event卡塔尔国,而是使用prefork方式的mpm,因为Linux系统的线程设计并不那么完美。所以,即使php和apache在平等台主机上(cgi可能模块化形式安装php的时候卡塔尔国,提出httpd使用prefork模型,而不在同生龙活虎台主机中,提议将php设计为fastcgi的做事情势。而在windows平高雄则无需思量那么些难题,因为windows系统是当真含义上的十二线程系统。

下载相关文书:
php下载地址:http://php.net/downloads
php手册地址:http://php.net/manual/zh/
手册下载地址:http://php.net/download-docs.php

2. 编译php

二种职业格局:CGI、作为模块参预到apache、fastcgi。最简便易行的是以模块方式出席到apache,此处演示的是php-fpm管理php-cgi格局。其余二种方法见php-cgi和httpd人机联作的不二秘诀。

fastcgi情势的php-cgi,由php-fpm提供服务管理,它会依赖布置文件运行一定数额的cgi进程,其私下认可监听的端口为9000,该服务平日办事亟待配备文件。也正是说fastcgi情势的php有四个构造文件,一个是php的陈设文件,二个是php-fpm的配置文件。

虽说这里演示的是php-fpm管理方法,但有供给表达下,在Linux中只要模块化安装php,不推荐在运用Apache 2.x中使用线程化MPM(worker和event卡塔尔(英语:State of Qatar),而是利用prefork格局的mpm,因为Linux系统的线程设计并不那么完美。所以,倘若php和apache在长期以来台主机上(cgi或然模块化情势安装php的时候卡塔尔(英语:State of Qatar),提出httpd使用prefork模型,而不在同生机勃勃台主机中,建议将php设计为fastcgi的行事格局。而在windows平新北则没有必要构思这么些主题素材,因为windows系统是当真含义上的三十二线程系统。

下载相关文书:
php下载地址:http://php.net/downloads
php手册地址:http://php.net/manual/zh/
手册下载地址:http://php.net/download-docs.php

2.1 php编写翻译选项表明

编写翻译安装php有极其可怜多的选项,比httpd还多。能够在解压php后的目录下利用./configure --help查看。以下是有些精选,在那之中付出"--enable-XXXX"的选项表示暗许是disable的,若要开启,须要在此边手动enable,如果给出的是"--disable-XXXX"表示暗许是enable的。

--prefix=PREFIX
【SAPI modules:】
--with-apxs2=FILE       Build shared Apache 2.0 Handler module. FILE is the optional
                          pathname to the Apache apxs tool apxs
--enable-fpm            Enable building of the fpm SAPI executable

【General settings:】
--with-config-file-path=PATH      Set the path in which to look for php.ini [PREFIX/lib]
--with-config-file-scan-dir=PATH  Set the path where to scan for configuration files

【Extensions:】
      #######################################################
      # --with-EXTENSION=shared[,PATH]                      #
      # NOTE: Not all extensions can be build as 'shared'.  #
      # Example: --with-foobar=shared,/usr/local/foobar/    #
      #######################################################
--with-openssl=DIR      Include OpenSSL support (requires OpenSSL >= 0.9.6)
--enable-mbstring       Enable multibyte string support
--with-zlib=DIR         Include ZLIB support
--with-bz2=DIR          Include BZip2 support
--with-mhash=DIR        Include mhash support
--with-mcrypt=DIR       Include mcrypt support
--with-freetype-dir=DIR  GD: Set the path to FreeType 2 install prefix
--with-jpeg-dir=DIR     GD: Set the path to libjpeg install prefix
--with-png-dir=DIR      GD: Set the path to libpng install prefix
--with-libxml-dir=DIR   SimpleXML: libxml2 install prefix
--enable-sockets        Enable sockets support
--disable-xml           Disable XML support (不写时默认--enable-xml)

【连接数据库:】
--with-mysql=DIR        Include MySQL support.  DIR is the MySQL base
                          directory, if no DIR is passed or the value is
                          mysqlnd the MySQL native driver will be used
--with-mysqli=FILE      Include MySQLi support.  FILE is the path
                          to mysql_config.  If no value or mysqlnd is passed
                          as FILE, the MySQL native driver will be used
--with-pdo-mysql=DIR    PDO: MySQL support. DIR is the MySQL base directory
                          If no value or mysqlnd is passed as DIR, the
                          MySQL native driver will be used
--enable-mysqlnd        Enable mysqlnd explicitly, will be done implicitly
                          when required by other extensions
【Zend:】
--enable-maintainer-zts    Enable thread safety - for code maintainers only!!

部分增选表明:

  1. 在【zend】扩大部分的选项"--enable-maintainer-zts"是为着让php援助八线程MPM的,即php以模块化情势或cgi形式安装时且httpd配置为worker或event时须要启用该项。而只要php以fastcgi方式安装时,由于php有独立的劳动和进度,所以该项是剩下的。
  2. "--with-apxs2"是让php以模块化的办法安装到别的程序中,"--enable-fpm"是让php以fastcgi方式职业的选项。所以那边接受前者,而以模块情势和httpd交互作用时采纳前面一个。
  3. "--with-config-file-path"和"--with-config-file-scan-dir"分别是php配置文件php.ini的寄存地点以致其它加载的陈设文件路线,scan-dir类的目录就如/etc/profile.d、/etc/httpd/conf.d那样的目录路线。
  4. "--with-openssl"选项让php帮衬ssl;"--enable-mbstring"选项是让php帮助多字节字符的,比如中文七个字符四个字节,也正是说让php帮衬国际化的;"--with-zlib"、"--with-bz2"、"--with-mhash"和"--with-mcrypt"选项让php接济这么些压缩和加密机制。
  5. "--with-freetype-dir"、"--with-jpeg-dir"和"--with-png-dir"分别是让php协理多种文字样式、补助jpeg、辅助png的选项。
  6. php连接mysql有三种艺术,意气风发种是以libmysql的驱动方式连接mysql,生龙活虎种是以mysqlnd情势驱动连接mysql。以下列出了libmysql和mysqlnd那三种驱动形式的编写翻译格局。

    • (1卡塔尔.以libmysql驱动情势连接mysql(Mariadb卡塔尔,须求超前设置mysql(Mariadb卡塔尔国和mysql-devel(mariadb-devel卡塔尔(قطر‎,并运用"--with-mysql"选项钦命mysql安装路径,"--with-mysqli"选项钦定mysql_config脚本的门路,"--with-pdo-mysql"选项也钦命mysql安装路线。假若mysql安装在/usr/local/mysql下。

      ./configure --prefix=/usr/local/php 
      --with-mysql=/usr/local/mysql 
      --with-mysqli=/usr/local/mysql/bin/mysql_config
      
    • (2卡塔尔国.以mysqlnd驱动格局连接mysql,无需提前设置mysql和mysql-devel,--with-mysql、--with-mysqli和--with-pdo-mysql选项都不要求钦定具体门路,只需使用mysqlnd作为那一个选用的值就可以。

      ./configure --prefix=/usr/local/php 
      --with-mysql=mysqlnd 
      --with-mysqli=mysqlnd 
      --with-pdo-mysql=mysqlnd
      

      在php 5.3的时候曾经支撑mysqlnd驱动格局了,在php 5.4的时候mysqlnd已是默许的布局选项了。提出选择mysqlnd的驱动形式。

2.1 php编写翻译选项表达

编译安装php有特别非常多的选项,比httpd还多。能够在解压php后的目录下行使./configure --help翻开。以下是有个别抉择,当中付出"--enable-XXXX"的选项表示暗中同意是disable的,若要开启,须要在那手动enable,借使给出的是"--disable-XXXX"表示私下认可是enable的。

--prefix=PREFIX
【SAPI modules:】
--with-apxs2=FILE       Build shared Apache 2.0 Handler module. FILE is the optional
                          pathname to the Apache apxs tool apxs
--enable-fpm            Enable building of the fpm SAPI executable

【General settings:】
--with-config-file-path=PATH      Set the path in which to look for php.ini [PREFIX/lib]
--with-config-file-scan-dir=PATH  Set the path where to scan for configuration files

【Extensions:】
      #######################################################
      # --with-EXTENSION=shared[,PATH]                      #
      # NOTE: Not all extensions can be build as 'shared'.  #
      # Example: --with-foobar=shared,/usr/local/foobar/    #
      #######################################################
--with-openssl=DIR      Include OpenSSL support (requires OpenSSL >= 0.9.6)
--enable-mbstring       Enable multibyte string support
--with-zlib=DIR         Include ZLIB support
--with-bz2=DIR          Include BZip2 support
--with-mhash=DIR        Include mhash support
--with-mcrypt=DIR       Include mcrypt support
--with-freetype-dir=DIR  GD: Set the path to FreeType 2 install prefix
--with-jpeg-dir=DIR     GD: Set the path to libjpeg install prefix
--with-png-dir=DIR      GD: Set the path to libpng install prefix
--with-libxml-dir=DIR   SimpleXML: libxml2 install prefix
--enable-sockets        Enable sockets support
--disable-xml           Disable XML support (不写时默认--enable-xml)

【连接数据库:】
--with-mysql=DIR        Include MySQL support.  DIR is the MySQL base
                          directory, if no DIR is passed or the value is
                          mysqlnd the MySQL native driver will be used
--with-mysqli=FILE      Include MySQLi support.  FILE is the path
                          to mysql_config.  If no value or mysqlnd is passed
                          as FILE, the MySQL native driver will be used
--with-pdo-mysql=DIR    PDO: MySQL support. DIR is the MySQL base directory
                          If no value or mysqlnd is passed as DIR, the
                          MySQL native driver will be used
--enable-mysqlnd        Enable mysqlnd explicitly, will be done implicitly
                          when required by other extensions
【Zend:】
--enable-maintainer-zts    Enable thread safety - for code maintainers only!!

一些筛选表明:

  1. 在【zend】扩充部分的选项"--enable-maintainer-zts"是为着让php协理多线程MPM的,即php以模块化格局或cgi格局安装时且httpd配置为worker或event时须求启用该项。而只要php以fastcgi格局安装时,由于php有独立的劳动和进度,所以该项是剩下的。
  2. "--with-apxs2"是让php以模块化的主意安装到任何程序中,"--enable-fpm"是让php以fastcgi格局工作的选项。所以那边采取后面一个,而以模块方式和httpd交互作用时采取后面一个。
  3. "--with-config-file-path"和"--with-config-file-scan-dir"分别是php配置文件php.ini的存放地方以致别的加载的安插文件路径,scan-dir类的目录有如/etc/profile.d、/etc/httpd/conf.d那样的目录路径。
  4. "--with-openssl"选项让php辅助ssl;"--enable-mbstring"选项是让php协助多字节字符的,比如汉语二个字符五个字节,也便是说让php帮助国际化的;"--with-zlib"、"--with-bz2"、"--with-mhash"和"--with-mcrypt"选项让php补助这几个压缩和加密机制。
  5. "--with-freetype-dir"、"--with-jpeg-dir"和"--with-png-dir"分别是让php匡助三种文字样式、协理jpeg、支持png的选项。
  6. php连接mysql有二种办法,后生可畏种是以libmysql的驱动格局连接mysql,大器晚成种是以mysqlnd格局驱动连接mysql。以下列出了libmysql和mysqlnd那二种驱动格局的编译情势。

    • (1卡塔尔.以libmysql驱动模式连接mysql(Mariadb卡塔尔国,需求超前设置mysql(Mariadb卡塔尔(英语:State of Qatar)和mysql-devel(mariadb-devel卡塔尔,并动用"--with-mysql"选项钦点mysql安装路线,"--with-mysqli"选项钦命mysql_config脚本的门径,"--with-pdo-mysql"选项也钦定mysql安装路线。要是mysql安装在/usr/local/mysql下。

      ./configure --prefix=/usr/local/php 
      --with-mysql=/usr/local/mysql 
      --with-mysqli=/usr/local/mysql/bin/mysql_config
      
    • (2卡塔尔(قطر‎.以mysqlnd驱动格局连接mysql,不需求提前设置mysql和mysql-devel,--with-mysql、--with-mysqli和--with-pdo-mysql选项都没有必要钦定具体门路,只需选取mysqlnd作为那么些采纳的值就可以。

      ./configure --prefix=/usr/local/php 
      --with-mysql=mysqlnd 
      --with-mysqli=mysqlnd 
      --with-pdo-mysql=mysqlnd
      

      在php 5.3的时候曾经支撑mysqlnd驱动方式了,在php 5.4的时候mysqlnd已是默许的结构选项了。提议利用mysqlnd的驱动格局。

2.2 php编写翻译进程

出于是布署fastcgi的情势,所以在./configure的时候将apxs2功力换为"--enable-fpm",况且鉴于此形式下的php由友好独自的劳动来支配进度的变通,所以对于为了援助httpd线程的选项"--enable-maintainer-zts"也去掉。以下是编写翻译安装进度:

yum install -y bzip2-level libmcrypt-devel openssl-devel libxml2-devel

tar xf php-5.5.38.tar.bz2 -C /tmp
cd /tmp/php-5.5.38
./configure --prefix=/usr/local/php --with-openssl --enable-mbstring --enable-sockets --with-freetype-dir --with-jpeg-dir --with-png-dir --with-libxml-dir=/usr --enable-xml --with-zlib --with-mcrypt --with-bz2 --with-mhash --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm

make
make install

# 提供php配置文件
cp php.ini-production /etc/php.ini

# 提供php-fpm服务管理脚本
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmd
chmod +x /etc/init.d/phpfpmd

# 提供php-fpm配置文件
cd /usr/local/php/
cp etc/php-fpm.conf.default etc/php-fpm.conf

# 修改php-fpm配置文件(做实验的话改不改随意)
vim etc/php-fpm.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8

# 启动php-fpm
service php-fpmd start

2.2 php编译进程

是因为是安插fastcgi的格局,所以在./configure的时候将apxs2效应换为"--enable-fpm",况且由于此情势下的php由自个儿单独的服务来决定进程的更改,所以对于为了扶助httpd线程的选项"--enable-maintainer-zts"也去掉。以下是编写翻译安装进度:

yum install -y bzip2-level libmcrypt-devel openssl-devel libxml2-devel

tar xf php-5.5.38.tar.bz2 -C /tmp
cd /tmp/php-5.5.38
./configure --prefix=/usr/local/php --with-openssl --enable-mbstring --enable-sockets --with-freetype-dir --with-jpeg-dir --with-png-dir --with-libxml-dir=/usr --enable-xml --with-zlib --with-mcrypt --with-bz2 --with-mhash --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm

make
make install

# 提供php配置文件
cp php.ini-production /etc/php.ini

# 提供php-fpm服务管理脚本
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmd
chmod +x /etc/init.d/php-fpmd

# 提供php-fpm配置文件
cd /usr/local/php/
cp etc/php-fpm.conf.default etc/php-fpm.conf

# 修改php-fpm配置文件(做实验的话改不改随意)
vim etc/php-fpm.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8

# 启动php-fpm
service php-fpmd start

2.3 配置httpd使其转会动态央浼给php-fpm

# 启用fcgi的支持模块。
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

# 添加php后缀格式文件的识别功能。
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

# 添加php后缀的主页
DirectoryIndex index.php index.html

# 启用虚拟主机模块,Include虚拟主机配置文件,并注释中心主机DocumentRoot。
#DocumentRoot "/usr/local/apache/htdocs"
Include /etc/apache/extra/httpd-vhosts.conf

# 配置虚拟主机。注意主机中需要添加下面两行,第一行表示关闭正向代理功能,第二行表示反向代理时进行正则匹配。
# 对主机的.php(不区分大小写)文件的访问都通过fcgi协议交给php,由于此处测试,php正好和httpd在同一服务器上,# 且php-fpm默认监听的端口为9000,所以为fcgi://127.0.0.1:9000,在此之后还需要写上/DocumentRoot/$1,
# "$1"是正则的反向引用
ProxyRequests off
ProxyPassMatch "(?i)^/(.*.php)$" fcgi://127.0.0.1:9000/var/www/a.com/$1

提供主页测量试验文件index.php。

mkdir -p /var/www/a.com

vim /var/www/a.com/index.php
<h1>a.com</h1>
<?php
    phpinfo();
?>

重启httpd,浏览器中举办站点访问测量试验。

2.3 配置httpd使其转会动态须求给php-fpm

# 启用fcgi的支持模块。
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

# 添加php后缀格式文件的识别功能。
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

# 添加php后缀的主页
DirectoryIndex index.php index.html

# 启用虚拟主机模块,Include虚拟主机配置文件,并注释中心主机DocumentRoot。
#DocumentRoot "/usr/local/apache/htdocs"
Include /etc/apache/extra/httpd-vhosts.conf

# 配置虚拟主机。注意主机中需要添加下面两行,第一行表示关闭正向代理功能,第二行表示反向代理时进行正则匹配。
# 对主机的.php(不区分大小写)文件的访问都通过fcgi协议交给php,由于此处测试,php正好和httpd在同一服务器上,# 且php-fpm默认监听的端口为9000,所以为fcgi://127.0.0.1:9000,在此之后还需要写上/DocumentRoot/$1,
# "$1"是正则的反向引用
ProxyRequests off
ProxyPassMatch "(?i)^/(.*.php)$" fcgi://127.0.0.1:9000/var/www/a.com/$1

提供主页测验文件index.php。

mkdir -p /var/www/a.com

vim /var/www/a.com/index.php
<h1>a.com</h1>
<?php
    phpinfo();
?>

重启httpd,浏览器中张开站点访问测量检验。

3. 为php安装xcache

php是风姿罗曼蒂克种解释型语言,意味着php脚本在施行时无需事情未发生前编写翻译,而是像shell脚本同样直接实践。但实际上它依旧会编写翻译的,只不过是实行时"偷偷地"编写翻译,它会将代码编写翻译成字节码(opcode卡塔尔然后运营。编写翻译是一个很耗时的操作,由此须求为编写翻译好的opcode提供缓存以增长质量,缩小负荷。方今最流行的opcode缓存工具是XCache,它是一个开源的工具。

下载路线:http://xcache.lighttpd.net/pub/Releases/

3. 为php安装xcache

php是风流倜傥种解释型语言,意味着php脚本在试行时无需事前编写翻译,而是像shell脚本形似直接实施。但骨子里它还是会编写翻译的,只可是是奉行时"偷偷地"编写翻译,它会将代码编写翻译成字节码(opcode卡塔尔国然后运营。编写翻译是贰个很耗时的操作,由此必要为编写翻译好的opcode提供缓存以加强质量,减少负荷。如今最流行的opcode缓存工具是XCache,它是多少个开源的工具。

下载路线:http://xcache.lighttpd.net/pub/Releases/

3.1 基本安装

安装xcache。

tar xf xcache-3.2.0.tar.bz2 -C /tmp
cd /tmp/xcache-3.2.0/

# 添加扩展前,先运行phpize
/usr/local/php/bin/phpize
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-cofig
make && make install

在安装到位之后有生机勃勃行,那生机勃勃行很要紧,因为那些渠道要增多到配置文件中。

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

在解压xcache的目录下,有xcache的布局文件xcache.ini,将其增加到php的布署文件中,或许将其复制到php的配置文件扫描目录/etc/php.d下(该目录是事前编译php时./configure安顿选项"--with-config-file-scan-dir"钦点的项卡塔尔。

mkdir /etc/php.d
cp xcache.ini /etc/php.d/
vim /etc/php.d/xcache.ini

在该公文中增进意气风发行,该行必得在该文件中的全体extension指令的最前面。

zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20121212/xcache.so

实则对于xcache 3.0本子和之后版本,可以毫无复制xcache模块的门径到安插文件中,因为能够自行找到php路线下的模块路径,以至增加了大概还有恐怕会出错。

本文由澳门新萄京app发布于计算机操作系统,转载请注明出处:搭建LAMP环境示例

关键词:

上一篇:没有了
下一篇:没有了