CentOS6.7上编译安装php

环境:CentOS6.7,minimal安装。

前提条件:安装了编译环境,安装了Apache/Nginx,安装了MySQL/MariaDB。具体安装见:http://www.178linux.com/16583    http://www.178linux.com/17497 

1、解决依赖关系:


请配置好yum源(系统安装源及epel源)后执行如下命令:

# yum -y groupinstall "Desktop Platform Development" 
# yum -y install bzip2-devel libmcrypt-devel libxml2-devel
[root@localhost php-5.4.45]# yum -y install bzip2-devel libmcrypt-devel libxml2-devel
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Package bzip2-devel-1.0.5-7.el6_0.x86_64 already installed and latest version
No package libmcrypt-devel available.
Package libxml2-devel-2.7.6-21.el6.x86_64 already installed and latest version
Nothing to do


如果提示说 libmcrypt-devel无法安装,请安装epel源

解决方法:

yum  install epel-release  //扩展包更新包
yum  update //更新yum源
yum install libmcrypt libmcrypt-devel mcrypt mhash  就ok了



2、编译安装php-5.4.26


首先下载源码包至本地目录,下载位置ftp://172.16.0.1/pub/Sources/new_lamp,或者用wget方法下载,具体下载用法见我前面博客。


# tar xf php-5.4.26.tar.bz2
# cd php-5.4.26
# ./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/apache24/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts


说明:

1、这里为了支持apache的worker或event这两个MPM,编译时使用了–enable-maintainer-zts选项。

2、如果使用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
# make -j 10
# make test
# make intall

3、为php提供配置文件

# cp php.ini-production /etc/php.ini

 编辑apache配置文件httpd.conf,以apache支持php


# vim 
/usr/local/apache24/conf/httpd.conf


 1)添加如下二行

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

 2)定位至DirectoryIndex index.html 

   修改为:

DirectoryIndex  index.php  index.html


而后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用。



测试页面index.php示例如下:

<?php
    $link = mysql_connect('127.0.0.1','root','mageedu');
    if ($link)
        echo "Success...";
    else
        echo "Failure...";
    mysql_close();
    phpinfo();
?>

4、安装phpMyadmin

# unzipphpMyAdmin-4.6.2-all-languages
# mv phpMyAdmin-4.6.2-all-languages /usr/local/apache24/htdocs/pmc
# cd/usr/local/apache24/htdocs/pmc
# cp config.sample.inc.php config.inc.php
# vim /usr/local/apache24/htdocs/pmc/config.inc.php

填充以下参数(这里的参数随便填写):

$cfg['blowfish_secret'] = 'sdaf32gretg435yerfwr<F>saadf';

phpmyadmin.png

测试访问phpMyadmin。访问phpMyadmin时,mysql需要密码,空密码不允许访问。

给mysql用户添加密码,删除空密码帐号。

mariadb.png

访问测试:http://192.168.163.13/pmc

5、安装xcache,为php加速

1)压力测试:

ab -c 10 -n 100 http://192.168.163.13/pmc/index.php
ab -c 100 -n 10000 http://192.168.163.13/pmc/index.php

多测试几次。然后安装xcache后再压力测试,对比。

2)安装xcache:

# tar xf xcache-3.2.0.tar.gz 
# cd xcache-3.2.0
# /usr/local/php/bin/phpize
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
# make && make install

3)编辑php.ini,整合php和xcache

安装结束时,会出现类似如下行:

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

首先将xcache提供的样例配置导入php.ini。或者创建php配置文件的分段目录

[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 
[root@localhost xcache-3.2.0]# service httpd24 reload

说明:xcache.ini文件在xcache的源码目录中。


接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:

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


注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。

再测试对比。

原创文章,作者:Net17-卓格,如若转载,请注明出处:http://www.178linux.com/17513

赞 (0)
Net17-卓格Net17-卓格
上一篇 2016-06-03 15:00
下一篇 2016-06-03 15:09

相关推荐

  • 马哥linux运维网络班第22期-第一周博客作业

    计算机的组成及其功能 计算机由运算器,控制器,存储器,输入装置和输出装置组成 (1)运算器 对数据进行常规运算(+,-,*,/)和逻辑运算(与,或,非等)及比较位移等操作 (2)控制器 分析从存储器中读出的指令并按预先规定的步奏执行操作 (3)存储器 存储程序和数据信息并实现快速存取 (4)输入设备 把各种类型的信息转换为二进制编码输入进计算机存储起来 (5…

    Linux干货 2016-08-14
  • 2016-08-12博客作业

    德摩根定理       在命题逻辑和逻辑代数中,德摩根定律(或称德摩根定理)是关于命题逻辑规律的一对法则。奥古斯塔斯·德摩根首先发现了在命题逻辑中存在着下面这些关系: 非(P 且 Q)=(非 P)或(非 Q) 非(P 或 Q)=(非 P)且(非 Q)     …

    Linux干货 2016-08-15
  • 8.1作业习题

    1,创建testuser uid 1234,主组:bin,辅助组:root,ftp,shell:/bin/csh home:/testdir/testuser useradd -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/testuser testuser 2.修改testuser uid:4321,主…

    Linux干货 2016-08-04
  • 第六周作业 bash编程学得好痛苦啊,啊啊啊~~需要挺住!

    请详细总结vim编辑器的使用并完成以下练习题 VIM很强大,但是万变不离其宗,最核心的三模式以下图表示: 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; :%s/^[[:blank:]]\+.*/\0#/g 2、复制/boot/grub/grub.conf至/…

    Linux干货 2016-12-19
  • 第六次上课作业

    1、三种权限rwx对文件和目录的不同意义 对文件 r:read  可读取此文件的实际内容,如读取文本文件的文字内容等 w: write  可以编辑,新增或修改该文件的内容 x:execute  该文件具有可以被系统执行的权限==>>针对二进制文件或脚本 X:针对目录会加上x权限…

    Linux干货 2016-08-04