码迷,mamicode.com
首页 > 其他好文 > 详细

LAMP 和 LNMP(LEMP) 编译安装

时间:2015-07-08 20:52:31      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:

一、Apache2.2+PHP5.3(module) + MariaDB5.5
    1.1 编译安装Apache2.2
    1.2 编译安装MariaDB5.5
    1.3 编译安装 PHP-5.3.29
    1.4 mysql测试
二、Apache 2.4+PHP5.4(fpm)+MariaDB5.5
    2.1 编译安装Apache2.4
    2.2 编译安装MariaDB5.5
    2.3 编译安装 PHP-5.4
2.4 mysql 测试
三、nginx1.6+ PHP5.3(fpm)+ MariaDB5.5
    3.1 编译安装nginx1.6
    3.2 编译安装MariaDB5.5
    3.3 编译安装PHP5.3
    3.4 mysql 测试
四、编译安装后的编译参数查询
五、PHP的缓存加速 xcache
六、数据库缓存与优化模块memcache客户端扩展模块安装

基础环境准备

一、Apache2.2+PHP5.3(module) + MariaDB5.5

1.1 编译安装Apache2.2

# 1.1.1 下载Apache2.2
wget http://apache.fayea.com//httpd/httpd-2.2.29.tar.gz
tar xf httpd-2.2.29.tar.gz 
cd httpd-2.2.29

# 1.1.2 安装依赖包
yum install zlib-devel openssl-devel pcre-devel -y

# 1.1.3 编译安装
./configure \
--prefix=/application/httpd-2.2.29 \
--enable-so \
--enable-ssl \
--enable-cgi  \
--enable-rewrite \
--with-zlib \
--with-pcre  \
--enable-modules=most \
--enable-deflate \
--enable-expires \
--enable-headers \
--with-mpm=worker
echo $?
make && make install 
echo $?
cd 

问题:libtool: install: error: cannot install `libaprutil-1.la‘ to a directory

    # 1.1.4 创建软连接
    ln -s /application/httpd-2.2.29/ /application/httpd

    # 1.1.5 启动httpd并测试
    /application/httpd/bin/apachectl start
    [root@lamp-module ~]# lsof -i:80
    COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    httpd   1541   root    4u  IPv6  11067      0t0  TCP *:http (LISTEN)
    httpd   2148 daemon    4u  IPv6  11067      0t0  TCP *:http (LISTEN)
    httpd   2149 daemon    4u  IPv6  11067      0t0  TCP *:http (LISTEN)
    httpd   2151 daemon    4u  IPv6  11067      0t0  TCP *:http (LISTEN)
    httpd   2232 daemon    4u  IPv6  11067      0t0  TCP *:http (LISTEN)

    技术分享
    出现以上界面说明httpd工作正常

    1.2 编译安装MariaDB5.5


    [root@lamp-module ~]# /etc/init.d/mysqld start
    Starting MySQL.. SUCCESS! 

    [root@lamp-module ~]# /application/mariadb/bin/mysql
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 2
    Server version: 5.5.44-MariaDB-log Source distribution

    Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

    Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

    能登陆msyql 说明mysql正常

    1.3 编译安装 PHP-5.3.29

    1.3.1 安装PHP的一些图形相关的lib库
    yum install zlib libxml libjpeg freetype libpng gd  curl libiconv  zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel openssl-devel libxslt-devel -y

    1.3.2 安装libiconv 字符编码转换的库
    wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
    tar zxf libiconv-1.14.tar.gz
    cd libiconv-1.14
    ./configure --prefix=/usr/local/libiconv
    echo $?
    make && make install
    echo $?
    cd

    1.3.3 下载php5.3.29
    wget http://cn2.php.net/distributions/php-5.3.29.tar.gz
    tar xf php-5.3.29.tar.gz
    cd php-5.3.29

    1.3.4 编译安装php5.3.29
    ./configure \
    --prefix=/application/php-5.3.29 \
    --with-apxs2=/application/httpd/bin/apxs \
    --with-mysql=/application/mariadb \
    --with-xmlrpc \
    --with-openssl \
    --with-zlib \
    --with-freetype-dir \
    --with-gd \
    --with-jpeg-dir \
    --with-png-dir \
    --with-iconv=/usr/local/libiconv \
    --enable-short-tags \
    --enable-sockets \
    --enable-zend-multibyte \
    --enable-soap \
    --enable-mbstring \
    --enable-static \
    --enable-gd-native-ttf \
    --with-curl \
    --with-xsl \
    --enable-ftp \
    --with-libxml-dir=/usr
    echo $?
    make -j 4 && make install
    echo $?
    cd

    # 1.3.5 创建软连接
    ln -s /application/php-5.3.29/ /application/php

    # 1.3.6 提供php配置文件
    cp php-5.3.29/php.ini-production /application/php/lib/

    查找php配置文件php.ini所在路径的二种方法    

    # 1.3.7 在httpd的主配置文件添加如下2行,用于解析php(如没有一打开就会下载)
    [root@lamp-module conf]# vim /application/httpd/conf/httpd.conf +311
    AddType application/x-httpd-php .php .phtml
    AddType application/x-httpd-php-source .phps

    # 1.3.8 在httpd的主配置文件将添加 index.php
    [root@lamp-module conf]# vim /application/httpd/conf/httpd.conf +168
    <IfModule dir_module>
        DirectoryIndex  index.php index.html
    </IfModule>

    # 1.3.9 添加php测试文件
    cat > /application/httpd/htdocs/index.php << EOF
    <?php
        phpinfo();
    ?>
    EOF

    # 1.3.10 重启apache服务
    /application/httpd/bin/apachectl restart

    # 1.3.11 PHP测试
    技术分享
    出现以上界面说明php工作正常

    1.4 mysql测试

    1.4.1 mysql的测试文件
    cat > /application/httpd/htdocs/tm.php << EOF
    <?php
        \$conn = mysql_connect(‘localhost‘,‘root‘,‘‘);
        if(\$conn)
            echo "succ";
        else
            echo "failure";
        mysql_close();
    ?>
    EOF

    1.4.2 开启mysql测试
    技术分享

    1.4.3 关闭mysql测试
    [root@lamp-module ~]# /etc/init.d/mysqld stop
    Shutting down MySQL. SUCCESS! 
    技术分享

    二、Apache 2.4+PHP5.4(fpm)+MariaDB5.5

    2.1 编译安装Apache2.4

    # 2.1.1 编译安装apr
    tar xf apr-1.5.2.tar.gz 
    cd apr-1.5.2
    ./configure --prefix=/usr/local/apr-1.5.2
    echo $?
    make && make install
    echo $?
    cd

    # 2.1.2 编译安装apr-util
    tar xf apr-util-1.5.4.tar.gz 
    cd apr-util-1.5.4
    ./configure --prefix=/usr/local/apr-util-1.5.4 --with-apr=/usr/local/apr-1.5.2
    echo $?
    make && make install
    echo $?
    cd

    # 2.1.3下载httpd-2.4.12

    # 2.1.4 安装相关的包
    yum install -y pcre-devel zlib-devel openssl-devel

    # 2.1.5 编译安装httpd-2.4.12
    tar xf httpd-2.4.12.tar.gz
    cd httpd-2.4.12
    ./configure \
    --prefix=/application/httpd-2.4.12 \
    --enable-so \
    --enable-ssl \
    --enable-cgi \
    --enable-rewrite \
    --with-zlib \
    --with-pcre \
    --with-apr=/usr/local/apr-1.5.2 \
    --with-apr-util=/usr/local/apr-util-1.5.4 \
    --enable-modules=most \
    --enable-mpms-shared=all \
    --with-mpm=event \
    --enable-deflate \
    --enable-expires
    echo $?
    make -j 4 && make install
    echo $?
    cd

    # 2.1.6 创建软链接
    ln -s  /application/httpd-2.4.12/ /application/httpd

    # 2.1.7 启动httpd,并测试
    /application/httpd/bin/apachectl start

    技术分享
    出现以上界面说明httpd服务正常

    2.2 编译安装MariaDB5.5


    [root@lamp-module ~]# /etc/init.d/mysqld start
    Starting MySQL.. SUCCESS! 

    [root@lamp-module ~]# /application/mariadb/bin/mysql
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 2
    Server version: 5.5.44-MariaDB-log Source distribution

    Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

    Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

    能登陆msyql 说明mysql正常

    2.3 编译安装 PHP-5.4

    # 2.3.1 安装必要的包
    yum install libxml2-devel libmcrypt-devel bzip2-devel libcurl-devel  libjpeg-devel libpng-devel freetype-devel libxslt-devel -y
    # gd可能需要gd的包

    # 2.3.2 编译安装 PHP-5.4.41
    tar xf php-5.4.41.tar.gz 
    cd php-5.4.41
    ./configure \
    --with-mysql=mysqlnd \
    --with-mysqli=mysqlnd \
    --prefix=/application/php-5.4.41 \
    --enable-mysqlnd \
    --with-openssl \
    --enable-mbstring \
    --with-freetype-dir \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib \
    --with-libxml-dir=/usr \
    --enable-sockets \
    --with-bz2 \
    --disable-rpath \
    --enable-bcmath \
    --enable-shmop \
    --enable-sysvsem \
    --with-curlwrappers \
    --enable-fpm \
    --with-gd \
    --enable-gd-native-ttf \
    --enable-pcntl \
    --enable-zip \
    --enable-soap \
    --enable-ftp \
    --enable-inline-optimization \
    --enable-short-tags \
    --enable-mbregex \
    --enable-xml \
    --with-xsl \
    --with-xmlrpc \
    --with-mhash \
    --with-gd \
    --with-mcrypt \
    --with-curl 
    echo $?
    make -j 4 && make install 
    echo $?

    # 2.3.3 软件软链接
    ln -s /application/php-5.4.41/ /application/php

    # 2.3.4 在httpd的主配置文件添加如下2行,用于解析php(如没有一打开就会下载)
    [root@lamp-module conf]# vim /application/httpd/conf/httpd.conf +379
    AddType application/x-httpd-php .php .phtml
    AddType application/x-httpd-php-source .phps

    # 2.3.5 在httpd的主配置文件添加访问时的主页
    [root@lamp-module conf]# vim /application/httpd/conf/httpd.conf +250
    <IfModule dir_module>
        DirectoryIndex index.php index.html
    </IfModule>

    # 2.3.6 在httpd的主配置文件开启反代模块,fcgi模块模块
    [root@lamp-module conf]# vim /application/httpd/conf/httpd.conf +115
    115 LoadModule proxy_module modules/mod_proxy.so
    119 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

    # 2.3.7 在httpd的主配置文件添加反代规则
    echo ‘ProxyRequests Off‘ >> /application/httpd/conf/httpd.conf
    echo ‘ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/application/httpd/htdocs/$1‘ >> /application/httpd/conf/httpd.conf

    # 2.3.8 添加php的配置文件
    cp php-5.4.41/php.ini-production /application/php/lib/php.ini

    # 2.3.9 fcgi的配置文件
    cp /application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf

    # 2.3.10 fcgi 配置文件测试
    /application/php/sbin/php-fpm -t

    # 2.3.11 httpd 服务重新reload
    /application/httpd/bin/apachectl graceful

    # 2.3 12 开启php-fpm 
    cp php-5.4.41/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    chmod +x /etc/init.d/php-fpm
    /etc/init.d/php-fpm start
    # 或者 
    [root@lamp-fpm ~]# /application/php/sbin/php-fpm 
    [root@lamp-fpm ~]# ss -tnlp
    State       Recv-Q Send-Q                   Local Address:Port                     Peer Address:Port 
    LISTEN      0      128                          127.0.0.1:9000                                *:*      users:(("php-fpm",77934,7),("php-fpm",77935,0),("php-fpm",77936,0))
    LISTEN      0      128                                 :::58888                              :::*      users:(("sshd",1113,4))
    LISTEN      0      128                                  *:58888                               *:*      users:(("sshd",1113,3))
    LISTEN      0      50                                   *:3306                                *:*      users:(("mysqld",58169,14))
    LISTEN      0      511                                 :::80                                 :::*      users:(("httpd",37244,4),("httpd",37245,4),("httpd",37246,4),("httpd",37247,4))

    # 2.3.13 添加php的测试文件
    cat > /application/httpd/htdocs/index.php << EOF
    <?php
        phpinfo();
    ?>
    EOF

    技术分享
    出现以上界面php工作正常

    # 2.3.14 (非必须)

    2.4 mysql 测试

    cat > /application/httpd/htdocs/tm.php << EOF
    <?php
        \$conn = mysql_connect(‘127.0.0.1‘,‘root‘,‘‘);
        if(\$conn)
            echo "succ";
        else
            echo "failure";
        mysql_close();
    ?>
    EOF

    经过测试:以上php的编译参数,当连接本地mysql时,需要地址为127.0.0.1,不能用localhost。连接其他主机的mysql也能正常。

    三、nginx1.6+ PHP5.3(fpm)+ MariaDB5.5

    3.1 编译安装nginx1.6

    3.1.1 下载nginx
    tar xf nginx-1.6.3.tar.gz
    cd nginx-1.6.3

    3.1.2 编译安装nginx
    yum install pcre pcre-devel openssl openssl-devel -y
    ./configure \
    --user=nginx \
    --group=nginx \
    --prefix=/application/nginx-1.6.3 \
    --with-http_stub_status_module \
    --with-http_ssl_module
    echo $?
    make -j 2 && make install 
    echo $?
    cd

    3.1.3 添加nginx账户
    useradd -M -s /sbin/nologin nginx

    3.1.4 启动nginx
    [root@lnmp nginx-1.6.3]# /application/nginx/sbin/nginx
    [root@lnmp nginx-1.6.3]# ss -tnl
    State       Recv-Q Send-Q                   Local Address:Port                     Peer Address:Port 
    LISTEN      0      128                                 :::58888                              :::*     
    LISTEN      0      128                                  *:58888                               *:*     
    LISTEN      0      511                                  *:80                                  *:* 

    技术分享
    出现以上网页nginx工作正常

    3.2 编译安装MariaDB5.5


    [root@lamp-module ~]# /etc/init.d/mysqld start
    Starting MySQL.. SUCCESS! 

    [root@lamp-module ~]# /application/mariadb/bin/mysql
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 2
    Server version: 5.5.44-MariaDB-log Source distribution

    Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

    Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

    能登陆msyql 说明mysql正常

    3.3 编译安装PHP5.3

    3.3.1 安装PHP的一些图形相关的lib库
    yum install zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel openssl-devel libxslt-devel libmcrypt-devel libtool-ltdl-devel -y
    #  zlib libxml libjpeg freetype libpng gd  curl  libiconv    ==>这些参数去掉后安装的编译安装未测试
     
    3.3.2 下载php5.3.29
    wget http://cn2.php.net/distributions/php-5.3.29.tar.gz
    tar xf php-5.3.29.tar.gz
    cd php-5.3.29

    3.3.3 编译安装php5.3.29
    ./configure \
    --prefix=/application/php-5.3.29 \
    --with-mysql=/application/mysql \
    --with-mysqli=/application/mysql/bin/mysql_config \
    --with-freetype-dir \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib \
    --with-libxml-dir=/usr \
    --enable-xml \
    --disable-rpath \
    --enable-safe-mode \
    --enable-bcmath \
    --enable-shmop \
    --enable-sysvsem \
    --enable-inline-optimization \
    --with-curl \
    --with-curlwrappers \
    --enable-mbregex \
    --enable-fpm \
    --enable-mbstring \
    --with-mcrypt \
    --with-gd \
    --enable-gd-native-ttf \
    --with-openssl \
    --with-mhash \
    --enable-pcntl \
    --enable-sockets \
    --with-xmlrpc \
    --enable-zip \
    --enable-soap \
    --enable-short-tags \
    --enable-zend-multibyte \
    --enable-static \
    --with-xsl \
    --with-fpm-user=nginx \
    --with-fpm-group=nginx \
    --enable-ftp
    echo $?
    make -j 4 && make install
    echo $?
    cd

    # 3.3.4 创建软连接
    ln -s /application/php-5.3.29/ /application/php
     
    # 3.3.5 提供php配置文件
    cp /root/php-5.3.29/php.ini-production /application/php/lib/php.ini
     
    查找php配置文件php.ini所在路径的二种方法   
    http://www.jb51.net/article/50406.htm
     
    # 3.3.6 fcgi的配置文件
    cp /application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf

    # 3.3.7 修改nginx的主配置文件
    cat > /application/nginx/conf/nginx.conf << EOF
    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        server {
            listen       80;
            server_name  www.test.com;
            index index.php index.html index.htm;
            location / {
                root   html;
                index  index.php index.html index.htm;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
            location ~.*\.(php|php5)?$
            {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                include        fastcgi.conf;
            }
        }
    }
    EOF

    # 3.3.8 重新加载nginx配置文件
    # /application/nginx/sbin/nginx -t    ==>测试配置文件
    /application/nginx/sbin/nginx -s reload

    # 3.3 9 开启php-fpm
    cp php-5.3.29/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    chmod +x /etc/init.d/php-fpm
    /etc/init.d/php-fpm start
    # 或者
    [root@lamp-fpm ~]# /application/php/sbin/php-fpm 
     
    # 3.3.10 添加php测试文件
    cat > /application/nginx/html/index.php << EOF
    <?php
        phpinfo();
    ?>
    EOF

    # 3.3.11 测试 php
    技术分享
    当出现以上网页时php工作正常

    3.4 mysql 测试

    cat >  /application/nginx/html/tm.php << EOF
    <?php
        \$conn = mysql_connect(‘127.0.0.1‘,‘root‘,‘‘);
        if(\$conn)
            echo "succ";
        else
            echo "failure";
        mysql_close();
    ?>
    EOF

    技术分享


    测试于另一台数据库连接
    cat > /application/nginx/html/tm.php << EOF
    <?php
        \$conn = mysql_connect(‘172.16.0.118‘,‘test‘,‘test‘);
        if(\$conn)
            echo "succ";
        else
            echo "failure";
        mysql_close();
    ?>
    EOF

    [root@lnmp ~]# /application/mysql/bin/mysql -h172.16.0.118 -utest -ptest
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 5
    Server version: 5.5.44-MariaDB-log Source distribution

    Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

    Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

    MariaDB [(none)]> 

    经过测试:用以上参数编译的php,localhost和IP都可以连接mysql,连接其他主机的mysql也能正常。

    四、编译安装后的编译参数查询

    编译参数查询如下示:
    • 查看nginx编译参数:/application/nginx/sbin/nginx -V
    • 查看apache编译参数: cat /application/apache/build/config.nice 
    • 查看mysql编译参数:grep CONFIGURE_LINE /application/mysql/bin/mysqlbug 
    • 查看php编译参数:/application/php/bin/php -i|grep configure

    五、PHP缓存加速软件 xcache

    php缓存加速种类:xcache,eaccelerator,Zend,apc

    phpize是用来扩展php模块的,通过phpize可以建立php的外挂模块

    tar xf xcache-3.2.0.tar.gz
    cd xcache-3.2.0
    /application/php/bin/phpize
    ./configure --enable-xcache   --with-php-config=/application/php/bin/php-config
    echo $?
    make
    echo $?
    make install
    ll /application/php5.3.29/lib/php/extensions/no-debug-non-zts-20090626/
    # 修改模块的目录
    sed -i ‘s#; extension_dir = "./#extension dir = "/application/php5.3.29/lib/php/extensions/no-debug-non-zts-20090626/"#g‘
    echo “extension = memcache.so” >> /application/php/lib/php.ini
    技术分享

    六、数据库缓存与优化模块memcache客户端扩展模块安装

    gunzip -d memcache-2.2.7.tgz
    tar xf memcache-2.2.7.tar
    cd memcache-2.2.7
    /application/php/bin/phpize
    ./configure --with-php-config=/application/php/bin/php-config
    make && make install
    ll /application/php5.3.29/lib/php/extensions/no-debug-non-zts-20090626/
    echo “extension = xcache.so” >> /application/php/lib/php.ini
    技术分享

    LAMP 和 LNMP(LEMP) 编译安装

    标签:

    原文地址:http://www.cnblogs.com/kwstars/p/4631131.html

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    登录后才能评论!
    © 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
    迷上了代码!