apache/mysql/php编译安装及支持xcache和fastcgi方式运行

一、编译安装apache

    1、安装环境:yum install gcc gcc-c++ openssl-devel libtool -y

    2、安装apr、apr-util及pcre

        tar jxf apr-1.5.1.tar.bz2

        cd apr-1.5.1

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

        make && make install

    

        tar jxf apr-util-1.5.3.tar.bz2

        cd apr-util-1.5.3

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

 

        tar jxf pcre-0.8.33.tar.bz2

        cd pcre-0.8.33

        ./configure --prefix=/usr/local/pcre

    3、解压编译安装httpd

        tar jxf httpd-2.4.9.tar.bz2

        cd httpd-2.4.9

        ./configure --prefix=/usr/local/apache \

        --enable-so \

        --enable-rewrite \

        --enable-ssl \

        --enable-mpms-shared=all \

        --sysconfdir=/etc/httpd \

        --enable-proxy \

        --enable-cgi \

        --enable-cgid \

        --enable-zlib \

        --with-apr=/usr/local/apr \

        --with-apr-util=/usr/local/apr-util \

        --with-pcre=/usr/local/pcre

        make && make install

        编译完成之后测试启动apache  /usr/local/apache/bin/apachectl start

        检查httpd是否启动  netstat -tnpl |grep httpd

    注:如httpd进程未启动,则检查/usr/local/apache/logs/error_log

[proxy_balancer:emerg] [pid 43810:tid 140389290723072] AH01177: Failed to lookup provider 'shm' for 'slotmem': is mod_slotmem_shm loaded??
[Mon Jun 23 13:10:43.767832 2014] [:emerg] [pid 43810:tid 140389290723072] AH00020: Configuration Failed, exiting

        可以看出是proxy_balancer这个模块的问题,编辑配置文件注释proxy_balancer.so这个模块,重新启动

 

        添加apache到系统变量 echo 'export PATH=$PATH:/usr/local/apache/bin' >>/etc/profile.d/httpd.sh

 

配置虚拟主机:

 

配置中心主机注释中心主机并开启虚拟主机

注释:DocumentRoot "/usr/local/apache/htdocs"

开启:Include /etc/httpd/extra/httpd-vhosts.conf

配置虚拟主机:vim /etc/httpd/extra/httpd-vhosts.conf

<virtualhost *:80>

    servername www.example.com

    documentroot "/www/example.com"

    errorlog "/var/log/httpd/error_log"

    customlog "/var/log/httpd/access_log" combined

    <directory "/www/example.com">

    options none

    allowoverride none

    require all granted

    </directory>

#限制目录访问功能:

#    <directory "/www/example.com">

#    options none

#    allowoverride authconfig

#    authtype basic

#    authname "example.com"

#    authuserfile "/etc/httpd/.htpassword"

#    require vaild-user   

</virtualhost>

启用apache的ssl功能:

    启用LoadModule ssl_so

    启用Include /etc/httpd/extra/httpd-ssl.conf      

二、源码安装mysql

    groupadd -r -g 306 mysql

    useradd -r -g mysql -s /sbin/nolog mysql

    tar zxf mysql-5.6.19-linux-glibc2.5.x86_64.tar.gz -C /usr/local

    cd /usr/local

    ln -s mysql-5.6.19-linux-glibc2.5.x86_64 mysql

    cd mysql

    chown -R mysql.mysql .

    mkdir /mydata

    chown -R mysql.mysql /mydata

    ./usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/mydata

    vim my.cnf

        [mysqld]

        user=mysql

        socket=/tmp/mysql.sock

        datedir=/mydata

        [client]

        socket=/tmp/mysql.sock

        

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

    chkconfig --add mysqld

    chkconfig mysqld on

    echo 'export PATH=$PATH:/usr/local/mysql/bin'>>/etc/profile.d/mysqld.sh

    chown -R root .

    echo '/usr/local/mysql/lib'>>/etc/ld.so.conf.d/mysqld.conf

    ldconfig

    ldconfig -v |grep mysql

      service mysqld start  ――――>mysql客户端连接查看


三、编译安装PHP

    tar jxf php-5.5.13.tar.bz2

    cd php-5.5.13

    ./configure --prefix=/usr/local/php \

    --with-apxs2=/usr/local/apache/bin/apxs \

    --with-mysql=/usr/local/mysql \

    --enable-fpm \

    --with-config-file-path=/etc/php \

    --sysconfdir=/etc/php \

    --with-config-file-scan-dir=/etc/php/php.d \

    --with-zlib \

    --with-bz2 \

    --enable-mbstring \

    --with-mysqli=/usr/local/mysql/bin/mysql_config \

    --enable-zip \

    --with-jpeg-dir \

    --with-png-dir \

    --with-openssl

    make && make install

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

    输出php脚本到系统环境变量:

      echo 'export PATH=$PATH:/usr/local/php/bin'>>/etc/profile.d/php.sh

    编辑httpd配置文件加载php模块

    LoadModule php5_module    modules/libphp5.so

    DirectoryIndex  index.php index.html

    AddType application/x-httpd-php .php

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

    重启httpd 新建index.php页面,测试访问

    建立mysql_connect()函数测试php与mysql连接

        <?php

        $conn=mysql_connect('localhost','root','');

        if ($conn)

            echo "scuess...";

        else

            echo "failure..."

        ?>

    安装xcache:

        tar zxf xcache-3.1.0.tar.gz

        cd xcache-3.1.0

        yum install autoconf -y

        /usr/local/php/bin/phpize

        ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config

        make && make install

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

        修改vim /etc/php/php.d/xcache.ini 指定正确的PHP扩展路径即编译xcache时make install最后输出的路径

        重启httpd 使用phpinfo查看xcache是否加载成功    

四、配置php与apache以fastcgi的方式工作

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

    chmod +x /etc/init.d/php-fpm

    chkconfig --add php-fpm

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

    配置FPM的相关选项,并启用PID文件:

    vim /etc/php/php-fpm.conf

        pm.max_children = 100 --->最大连接数

        pm.start_servers = 8 --->服务启动进程数

        pm.min_spare_servers = 5 --->最小空闲进程数

        pm.max_spare_servers = 20 --->最大空闲进程数

        pid = /usr/local/php/var/run/php-fpm.pid

    接下来启动php-fpm  service php-fpm start

     

    httpd上需要做的修改:vim /etc/httpd/httpd.conf

    启用模块:

        LoadModule proxy_module modules/mod_proxy.so

        LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

      注释模块:

        LoadModule php5_module  modules/libphp5.so

    在相应的虚拟机中添加类似如下两行:

        proxyrequests Off

        proxypassmatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1

 

例:

   <virtualhost *:80>

        documentroot "/www/example.com"

        servername www.example.com

        proxyrequests Off

        proxypassmatch ^/(*.\.php)$ fcgi://127.0.0.1:9000/www/example.com/$1

        <directory "/www/example.com">

        options none

        allowoverride none

        require all granted

        </directory>

    </virectoryhost>                       

本文出自 “fight” 博客,谢绝转载!

你可能感兴趣的:(mysql,local,编译)