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
下一篇 2016-06-03

相关推荐

  • Centos6基于虚拟主机的Lamp配置bbs、Blog、PhpMyAdmin应用程序

    Centos6实现基于虚拟主机的各应用程序搭建: 一、配置三个基于名称的虚拟主机;       虚拟主机一、discuzX       虚拟主机二、wordpress       虚拟主机三…

    Linux干货 2016-10-09
  • 系统管理之磁盘管理(二)磁盘配额,RAID,LVM

    上篇博文给大家介绍了磁盘和文件系统的基础知识,也是最基本的使用.在实际生产环境中,对于磁盘的使用,要求稳定,灵活,那么下面给大家分享下磁盘的高级用法.磁盘配额,RAID,LVM等相关知识. 1.磁盘配额2.磁盘RAID3.LVM 一.磁盘配额 1.概述: • 在内核中执行 • 以文件系统为单位启用 • 对不同组或者用户的策略不同…

    Linux干货 2016-09-05
  • 第十六周作业

    1、源码编译安装LNMP架构环境;     安装nginx:      1)安装依赖包 ]# yum groupinstall “Development Tools” “Development Libraries” -y ]# yum install wget openssl-devel ncurses-de…

    2017-05-02
  • LVS实现负载均衡wordpress

    项目构建: LVS实现基于https wordpress 组建 必需软件: nfs-utils-1.2.3-70.el6.x86_64 配置步骤: 1.在D主机设置NFS共享目录 /app/nfsdata #mkdir /app/nfsdata //最好用LVM 实现在线扩展 #chown mysql: /app/data //确认该主机mysql用户存在 …

    2017-05-12
  • AWK学习总结

    AWK是一种优良的文本处理工具。其名称得自于它的创始人阿尔佛雷德·艾侯、彼得·温伯格和布莱恩·柯林汉姓氏的首个字母。AWK提供了极其强大的功能:可以进行正则表达式的匹配,样式装入、流控制、数学运算符、进程控制语句甚至于内置的变量和函数。它具备了一个完整的语言所应具有的几乎所有精美特性。 AWK学习总结 函数rand(): 函数length() 函数int()…

    Linux干货 2016-12-03
  • yum报错2

    我的系统是centos 6.8 x86的; 安装pam_mysql时报错如下: [root@Ams ~]# yum install pam_mysql -y Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror…

    Linux干货 2016-08-02