• Linux服务 编译安装LAMP


    LAMP组合编译安装(使用的是Centos6)
        
        httpd+php
            modules:把php便以成 httpd的DSO模块;
                prefork:libphp5
                event、worker :libphp5-zts
            cgi
            fpm(fastcgi):php作为独立的服务,监听在某个套接字上向外提供服务;
            httpd对fastcgi协议的支持:
                httpd-2.2:需要额外安装fcgi模块:
                httpd-2.4:自带fcgi模块;
        安装顺序:httpd→ MariaDB→ php      其实只要保证php最后安装即可;
            1.首先需要安装编译环境以及依赖关系处理;
                yum groupinstall “Development Tools” “Server Platform Development” -y
                yum install pcre pcre-devel  → httpd依赖这两个包
                yun install bzip2-devel libmcrypt-devel libxml2-devel.x86_64 -y → PHP用到这三个包
                    注:libmcrypt-devel是在epel源中的,所以需要事安装epel源;
            2.下载待编译的源码包;
                apr:http://archive.apache.org/dist/apr/apr-1.5.0.tar.bz2
                apr-util:http://archive.apache.org/dist/apr/apr-util-1.5.3.tar.bz2      
                httpd:http://archive.apache.org/dist/httpd/httpd-2.4.10.tar.gz
                MariaDB:https://downloads.mariadb.org/mariadb/5.5.62/mariadb-5.5.62-linux-x86_64.tar.gz   
                PHP:http://php.net/releases/
            3.解压及编译;
                apr:
                    tar -xf apr-1.5.0.tar.bz2
                     cd apr-1.5.0/
                     ./configure –prefix=/usr/local/apr
                    make && make install
                apr-until:
                     tar -xf apr-util-1.5.3.tar.bz2
                    cd apr-util-1.5.3/
                     ./configure --prefix=/usr/local/apr-until –with-apr=/usr/local/apr
                        因为apr-until是针对于apr编译的所以后面要指明apr的位置;
                    make && make install
                    注:因为我的手误将apr-util写成了apr-until,大家做的时候注意更正过来;
                httpd:httpd在编译的时候我们尽量让它对每一个模块都支持;
                    编译安装前注意各个相关的软件为新版本,我在编译的时候就报一个ssl版本过旧的错误,如果你也碰到了使用yum install openssl-devel.x86_64 -y 以及yum update openssl即可;
                     tar -xf httpd-2.4.10.tar.bz2
                    cd httpd-2.4.10/
                     ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite  --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-until --enable-modules=most --enable-mpms-shared=all –with-mpm=event
                    make && make install
                    cd /etc/rc.d/init.d
                    cp httpd httpd24
                    vim httpd24
                        apachectl=/usr/localapache/bin/apachectl
                        httpd=${HTTPD-/usr/local/apache/bin/httpd}
                        prog=httpd
                        pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}
                        lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
                        RETVAL=0
                        STOP_TIMEOUT=${STOP_TIMEOUT-10}
                    chkconfig --add httpd24            
                    chkconfig --list  httod24
                    hash -r
                    httpd -t
                    vim /etc/profile.d/httpd24.sh
                        export PATH=/usr/local/apache/bin:$PATH
                    . /etc/profile.d/httpd24.sh
                    hash
                    httpd -M
                         mpm_event_module (shared)
                    vim /etc/httpd24/httpd.conf
                        查找LoadModule → 启用需要的模块
                MariaDB:
                    请查看:https://blog.csdn.net/qq_32501535/article/details/85102155
                PHP(模块方式):
                    tar -xf php-5.4.40.tar.bz2
                     cd php-5.4.40/
                    ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
                    --prefix=/usr/local/php                 指定安装路径
                    --with-mysql=/usr/local/mysql    指定php是指定针对哪个mysql安装的
                    --with-openssl                              指定openssl
                    --with-mysqli=/usr/local/mysql/bin/mysql_config   对mysql中数据库的另外一种接口
                    --enable-mbstring                  启用对多字节字符串的支持,使用中文的话就需要启动
                    --with-freetype-dir                 指定使用多种字体格式    
                    --with-jpeg-dir                       支持处理jpeg格式的图片
                    --with-png-dir                        支持处理png格式的图片
                    --with-zlib                              支持压缩库
                    --with-libxml-dir=/usr            支持处理xml格式的文档
                    --enable-xml                           启用xml功能
                    --enable-sockets                      支持基于socket通信
                    --with-apxs2=/usr/local/apache/bin/apxs     把php编译成apache的模块
                    --with-mcrypt                          支持加解密库
                    --with-config-file-path=/etc     php配置文件路径
                    --with-config-file-scan-dir=/etc/php.d          .d目录  → 你懂的:跟php有关的配置都可以放在这个目录中,php会自动加载其中的文件
                    --with-bz2                                支持bz2格式
                    --enable-maintainer-zts            httpd使用的是event或worker的话,就需要这个选项,否则就不用加;我们前面使用的就是event,所以。。。
                    make && make install
                    
                    编译成功以后我们还要回去配置httpd,因为httpd默认是不支持php的
                            cd /etc/httpd24/
                            cp httpd.conf{,.bak}    
                             vim httpd.conf
                                DirectoryIndex index.php index.html
                                AddType application/x-httpd-php .php
                                    AddType application/x-httpd-php-source .phps
                安装xcache,为php加速
                    下载源码包:http://xcache.lighttpd.net/wiki/Release-3.2.0
                    tar -xf xcache-3.2.0.tar.bz2
                    cd xcache-3.2.0/
                    /usr/local/php/bin/phpize     xcache的configure时需要借助php的phpize这个工具程序来读取模块文件而生成的;
                     ./configure --enable-xcache--with-php-config=/usr/local/php/bin/php-config
                         --enable-xcache      启用xcache模块
                        --with-php-config=/usr/local/php/bin/php-config     将xcache编译成php的模块,xcache从本质上讲是php的一个扩展;=右边的就是php的一个扩展接口;
                    make && make install
                    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
                
                PHP(以fpm方式):
                    tar -xf php-5.4.40.tar.bz2
                    cd php-5.4.40/
                     ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc/php5 --with-config-file-scan-dir=/etc/php5.d --with-bz2
                    make && make install
                在apache httpd2.4以后已经专门有一个模块用于针对FastCGI的实现,此模块为mod_proxy_fcgi.so ,它其实是作为mod_proxy.so模块的扩展,因此两个模块都需要加载;
                    同样需要在httpd的配置文件中添加
                    vim /etc/httpd2-4/httpd.conf      使httpd支持php格式文件,并且加载相关模块
                        注:这个httpd的配置文件不是接上文中编译的那个,而是重新安装的,因为上文使用的是event模块模式的,其中的一些模块是fpm不需要的,所以建议另外重新找到一个httpd的配置文件来使用;   
                        DirectoryIndex index.php index.html
                        AddType application/x-httpd-php .php
                           AddType application/x-httpd-php-source .phps
                        LoadModule proxy_module modules/mod_proxy.so
                        LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
                        配置虚拟主机支持使用fcgi  
                            在相应的虚拟主机中添加类似以下两行:
                                ProxyRequests Off        关闭正向代理
                                ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
                                    /PATH/TO/DOCUMENT_ROOT:存放.php资源的目录;
                                    $1:正则表达式的后向引用;
                                    作用:在虚拟主机中以反向代理的方式告诉用户所有对.php格式结尾的URL的请求都基于fcgi协议送给某个服务器(127.0.0.1)上的9000端口,以请求资源;
                        例子:
                            <VirtualHost *:80>
                                DocumentRoot “/var/www/html”
                                ServerName guowei.com
                                ServerAlias www.guowei.com
                            ProxyRequests Off        
                            ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
                                <Directory “/var/www/html”>
                                    Options none
                                    AllowOverride none
                                    Require all granted
                                </Directory>
                            </VirtualHost>
                    mkdir /etc/php5{,.d}
                    cp php.ini-production /etc/php5/php.ini                        php的配置文件
                    cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm      服务启动脚本
                    chmod +x /etc/rc.d/init.d/php-fpm
                    chkconfig --add php-fpm
                    cd /usr/local/php5/etc/
                    cp php-fpm.conf.default php-fpm.conf                          php-fpm的配置文件
                    vim php-fpm.conf
                        pm.max_children = 50            最多启动多少个进程
                        pm.start_servers = 5                服务启动时就启动多少个进程
                        pm.min_spare_servers = 2      最小空闲进程
                        pm.max_spare_servers = 5      最大空闲进程
                        pid = /usr/local/php5/var/run/php-fpm.pid        pid的位置
                    service php-fpm start
                    ps -aux | grep fpm
                   

    注:根据马哥视频做的学习笔记,如有错误,欢迎指正:侵删
                        
     

  • 相关阅读:
    一名菜鸟程序员的跳槽经历以及其所感所想(二)
    C#调用WebService
    IIS Error:404.2 The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server
    C#操作XML简析系列(1)之增删修改查
    The web server process that was being debugged has been terminated by Internet Information Services (IIS).
    一名菜鸟程序员的跳槽经历以及其所感所想(一)
    访问WebService出现IIS错误:The request failed with HTTP status 401: Unauthorized
    Windows2008服务器搭建Apollo_MQTT服务
    [ObjC笔记] "self = [super init]"的解释与潜藏bug
    [LBS]查询离某个经纬附近的数据SQL语句
  • 原文地址:https://www.cnblogs.com/guowei-Linux/p/11072877.html
Copyright © 2020-2023  润新知