设为首页 收藏本站
查看: 1151|回复: 0

[经验分享] 编译安装LAMP实现PHP作为模块、FastCGI分离等方式

[复制链接]

尚未签到

发表于 2018-12-17 13:42:02 | 显示全部楼层 |阅读模式
  源码包:

httpd-2.4.9Apache2.4.9编译安装包
apr-1.5.1Apache可移植运行库
apr-util-1.5.3Apache可移植运行库工具
php-5.5.30PHP源码包
mysql-5.5.47通用二进制版( Generic)
  

  一、PHP作为模块编译LAMP:
注:
1、由于PHP作为Apache的模块,所以编译PHP的时候,需要在httpd之后。
2、这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项
3、PHP连接MySQL数据库需要mysql客户端的开发组件支持,不过:如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包了。mysqlnd从php 5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),但从PHP 5.4开始它就是默认设置了。
# ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
  1.编译apr-1.5.1:
[root@localhost ~]# yum install -y pcre-devel #安装perl正则表达式的依赖包
[root@localhost ~]# cd lamp/
[root@localhost lamp]# tar xf apr-1.5.1.tar.gz
[root@localhost lamp]# cd apr-1.5.1
[root@localhost apr-1.5.1]# ./configure --prefix=/usr/local/apr && make && make install  2.编译apr-util-1.5.3:
[root@localhost lamp]# tar xf apr-util-1.5.3.tar.bz2
[root@localhost lamp]# cd apr-util-1.5.3
[root@localhost apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ && make && make install  3.编译httpd-2.4.9:
[root@localhost lamp]# tar xf httpd-2.4.9.tar.gz
[root@localhost lamp]# cd httpd-2.4.9
[root@localhost httpd-2.4.9]# ./configure --prefix=/usr/local/httpd-2.4.9 \  #指定安装目录
> --sysconfdir=/etc/httpd \                     #配置文件目录
> --enable-modules=most \                       #编译进大多数常用模块   
> --enable-mods-shared=most \                   #将常用模块编译为动态模块,shared
> --enable-so \                                 #使Apache支持动态加载模块
> --enable-ssl \                                #支持ssl
> --enable-mpms-shared=all \                    #将所有支持的MPM模块编译为动态模块
> --with-apr=/usr/local/apr \                   #指定apr所在位置
> --with-apr-util=/usr/local/apr-util \         #指定apr-util位置
> --with-mpm=event \                            #指定默认MPM为event
> --enable-proxy \                              #开启代理模块
> --enable-proxy-fcgi \                         #开启fcgi模块,需要一并开启--enable-proxy选项
> --enable-deflate \                            #支持压缩
> make && make install                          #安装
#############安装完成后,还需要对运行环境做些配置################
将目录链接为httpd:
[root@localhost ~]# ln -sv /usr/local/httpd-2.4.9 /usr/local/httpd
添加命令搜索路径文件:
[root@localhost ~]# vim /etc/profile.d/httpd.sh
  1.添加一行:export PATH=/usr/local/httpd/bin:$PATH
加载环境变量文件:
[root@localhost ~]# source /etc/profile.d/httpd.sh
导出头文件
[root@localhost ~]# ln -sv /usr/local/httpd/include/ /usr/include/httpd
`/usr/include/httpd' -> `/usr/local/httpd/include/'
编辑man文档目录:
[root@localhost ~]# vim /etc/man.config
1.添加一行:MANPATH /usr/local/httpd/man  

  4.测试是否可以成功启动:
测试启动并查看是否监听在80端口:
[root@localhost ~]# httpd -k start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ::1. Set the 'ServerName' directive globally to suppress this message
[root@localhost ~]# ss -tnl|grep 80
LISTEN     0      128                      :::80                      :::*     
[root@localhost ~]#  

  5.解压mysql:

[root@localhost  lamp]# tar xf mysql-5.5.47-linux2.6-x86_64.tar.gz -C /usr/local/
#############安装完成后,还需要对运行环境做些配置################
创建用户和组:
[root@localhost  lamp]#  groupadd -r mysql
[root@localhost  lamp]#  useradd -r -g mysql mysql
将mysql-5.5.47目录链接为mysql:
[root@localhost  lamp]# ln -sv /usr/local/mysql-5.5.47-linux2.6-x86_64/ /usr/local/mysql
`/usr/local/mysql' -> `/usr/local/mysql-5.5.47-linux2.6-x86_64/'
提供命令搜索路径:
[root@localhost lamp]# vim /etc/profile.d/mysql.sh
  1.添加一行:export PATH=/usr/local/mysql/bin:$PATH
加载环境文件:
[root@localhost lamp]# source /etc/profile.d/mysql.sh
链接头文件:
[root@localhost lamp]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
`/usr/include/mysql/include' -> `/usr/local/mysql/include/'
导出库文件:
[root@localhost lamp]# vim /etc/ld.so.conf.d/mysql.conf
  1.添加一行:/usr/local/mysql/lib
重新加载库文件:
[root@localhost lamp]# ldconfig  6.配置、初始化并启动MySQL:
为目录添加权限:
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# chown -R root.mysql .
创建数据目录:
[root@localhost mysql]# mkdir /data
[root@localhost mysql]# chown -R mysql.mysql /data
初始化mysql:
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data   初始化
查看数据目录是否有文件,如果有就证明初始化成功:
[root@localhost mysql]# ls /data/
mysql  mysql-bin.000001  mysql-bin.000002  mysql-bin.index  performance_schema  test
提供启动脚本:
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on
提供配置文件并配置:
[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@localhost mysql]# vim /etc/my.cnf
  1.在[mysqld]范围中添加一行:datadir = /data
启动mysql测试:
[root@localhost mysql]# service mysqld start
Starting MySQL...                                          [  OK  ]
[root@localhost mysql]#
[root@localhost mysql]# ss -tnl|grep 3306
LISTEN     0      50                        *:3306                     *:*  

  7.编译php-5.5.30:
[root@localhost lamp]# yum install -y openssl-devel bzip2-devel libmcrypt-devel
[root@localhost lamp]# cd php-5.5.30
[root@localhost php-5.5.30]./configure --prefix=/usr/local/php-5.5.30 \                   #指定安装目录
> --with-mysql=/usr/local/mysql \                         #指定MySQL安装目录
> --with-openssl \                                        #使用openssl库,需要安装openssl-devel包
> --with-mysqli=/usr/local/mysql/bin/mysql_config \       #指定mysql_config
> --enable-mbstring \                                     #开启多字符串支持
> --with-freetype-dir \
> --with-jpeg-dir \                                       #支持jpeg
> --with-png-dir \                                        #支持png
> --with-zlib \                                           #指定zlib
> --with-libxml-dir=/usr \                                #指定libxml库
> --enable-xml  \                                         #开启xml
> --enable-sockets \                                      #开启套接字方式支持
> --with-apxs2=/usr/local/apache/bin/apxs \               #apxs是Apache的模块支持库,要想编译为Apache模块,依赖于apxs
> --with-mcrypt \                                         #指定加密库,需要libmcrypt-devel包
> --with-config-file-path=/etc \                          #指定配置文件所在目录
> --with-config-file-scan-dir=/etc/php.d \                #指定附加目录
> --with-bz2  \                                           #指定bz2压缩库,需要bzip2-devel
> --enable-maintainer-zts                                          #支持apache的worker或event这两个MPM

#############安装完成后,还需要对运行环境做些配置################
连接目录:
[root@localhost lamp]# ln -sv /usr/local/php-5.5.30/ /usr/local/php
`/usr/local/php' -> `/usr/local/php-5.5.30/
导出头文件:
[root@localhost lamp]# ln -sv /usr/local/php-5.5.30/include/ /usr/include/php
`/usr/include/php' -> `/usr/local/php-5.5.30/include/'
添加命令搜索路径文件:
[root@localhost lamp]# vim /etc/profile.d/php.sh
  1.添加一行:export PATH=/usr/local/php/bin:$PATH
读取到环境变量:
[root@localhost lamp]# source /etc/profile.d/php.sh
导出库文件:
[root@localhost lamp]# vim /etc/ld.so.conf.d/php.conf
  1.添加一行:/usr/local/php/lib
重新加载库文件:
[root@localhost  lamp]#  ldconfig  

  

  8.在httpd配置文件(/etc/httpd/httpd.conf)中添加如下两行并将DirectoryIndex修改为index.php:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

    DirectoryIndex index.php
  

  9.重新启动httpd服务并查看是否加载php模块:
[root@localhost mysql]# httpd -k restart
[root@localhost mysql]# httpd -M|grep php
php5_module (shared)
[root@localhost mysql]#  

  10.提供一个index.php文件并测试:
  上面这个文件是连接mysql,如果连接成功就输出Success,如果连接失败就输出Failure。并且后面跟着输出一个php测试页面。

  可以关闭掉mysql再测试:
[root@localhost htdocs]# service mysqld stop
Shutting down MySQL.                                       [  OK  ]
[root@localhost htdocs]#

  

  11.编译Xcache
解包:
[root@localhost lamp]# tar xf xcache-3.2.0.tar.gz
执行phpize(phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块):
[root@localhost lamp]# cd xcache-3.2.0
[root@localhost xcache-3.2.0]# phpize
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212
编译:
[root@localhost xcache-3.2.0]# ./configure \
> --enable-xcache \   #开启cache功能
> --with-php-config=/usr/local/php/bin/php-config \    #指定php的配置程序,这个程序是告诉编译程序php的信息的
> && make && make install
编译后有一条信息,记录下来稍后会用到:
Installing shared extensions:     /usr/local/php-5.5.3/lib/php/extensions/no-debug-zts-20121212/
复制xcache.ini到/etc/php.d目录:
[root@localhost xcache-3.2.0]# mkdir /etc/php.d
[root@localhost xcache-3.2.0]# cp xcache.ini /etc/php.d/
修改配置文件:
[root@localhost xcache-3.2.0]# vim /etc/php.d/xcache.ini
将:extension = xcache.so
修改为刚才编译完成后保留的位置:
extension = /usr/local/php-5.5.3/lib/php/extensions/no-debug-zts-20121212/xcache.so  12.测试Xcache的作用:
  没启动Xcache:

[root@localhost php.d]# ab -c 10 -n 100 http://10.10.10.11/pma/index.php
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 10.10.10.11 (be patient).....done

Server Software:        Apache
Server Hostname:        10.10.10.11
Server Port:            80
Document Path:          /pma/index.php
Document Length:        9047 bytes
Concurrency Level:      10
Time taken for tests:   3.876 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      1037900 bytes
HTML transferred:       904700 bytes
Requests per second:    25.80 [#/sec] (mean)
Time per request:       387.550 [ms] (mean)
Time per request:       38.755 [ms] (mean, across all concurrent requests)
Transfer rate:          261.53 [Kbytes/sec] received
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   5.4      0      27
Processing:   290  383  25.3    387     438
Waiting:      272  356  25.3    360     409
Total:        308  385  24.5    388     438
Percentage of the requests served within a certain time (ms)
  50%    388
  66%    399
  75%    401
  80%    404
  90%    412
  95%    419
  98%    430
  99%    438
100%    438 (longest request)  启动Xcache:
[root@localhost php.d]# ab -c 10 -n 100 http://10.10.10.11/pma/index.php
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 10.10.10.11 (be patient).....done

Server Software:        Apache
Server Hostname:        10.10.10.11
Server Port:            80
Document Path:          /pma/index.php
Document Length:        9047 bytes
Concurrency Level:      10
Time taken for tests:   0.728 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      1037900 bytes
HTML transferred:       904700 bytes
Requests per second:    137.39 [#/sec] (mean)
Time per request:       72.784 [ms] (mean)
Time per request:       7.278 [ms] (mean, across all concurrent requests)
Transfer rate:          1392.57 [Kbytes/sec] received
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   5.0      0      25
Processing:    29   70  23.4     67     129
Waiting:        8   53  23.2     50     128
Total:         29   72  23.9     69     129
Percentage of the requests served within a certain time (ms)
  50%     69
  66%     80
  75%     86
  80%     95
  90%    111
  95%    117
  98%    125
  99%    129
100%    129 (longest request)  

  二、PHP的FastCGI方式结合Apache:
  

  

  

  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-652479-1-1.html 上篇帖子: hackermi PHP 404 一句话*** 下篇帖子: install_httpd_php
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表