编译安装PHP5.4.41
一、部署LAMP环境,安装顺序
二、编译、安装php
三、安装xcache,为php(opcode)加速
四、其他
一、部署LAMP环境,安装顺序
编译安装部署LAMP环境,安装顺序
1、编译安装apache,http://64314491.blog.51cto.com/2784219/1652948
2、编译安装mysql,http://64314491.blog.51cto.com/2784219/1652999
3、编译安装php
二、编译、安装php
1、下载php并解压
[root@localhostdownloads]#wgethttp://cn2.php.net/distributions/php-5.4.41.tar.bz2[root@localhostdownloads]#tarxfphp-5.4.41.tar.bz2
2、编译前准备工作
(1)、编译选项
./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
(2)、直接编译,会有如下提醒,所以需提前准备
1、configure:error:xml2-confignotfound.Pleasecheckyourlibxml2installation.2、configure:error:PleasereinstalltheBZip2distribution3、configure:error:mcrypt.hnotfound.Pleasereinstalllibmcrypt.4、configure:error:CannotfindMySQLheaderfilesunder/usr/local/mysql.#这个问题就需要先安装mysql后,再来编译php了,所以最好按照步骤apache-->mysql-->php
所以编译前需要安装依赖环境
1、#yum-yinstalllibxml2libxml2-devel2、#yum-yinstallbzip2-devel下载libmcryptlibmcrypt-devel,并安装#wgethttp://mirrors.sohu.com/fedora-epel/6Server/x86_64/libmcrypt-2.5.8-9.el6.x86_64.rpm#wgethttp://mirrors.sohu.com/fedora-epel/6Server/x86_64/libmcrypt-devel-2.5.8-9.el6.x86_64.rpm3、#rpm-ivhlibmcrypt-2.5.8-9.el6.x86_64.rpm#rpm-ivhlibmcrypt-devel-2.5.8-9.el6.x86_64.rpm
3、编译、安装php
#./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#make&&makeinstall
注:--enable-maintainer-zts 编译模块worker、event时,需要使用该选项
4、编辑/etc/httpd/httpd.conf
(1)、在AddType application/x-gzip .gz .tgz后添加以下信息,使httpd识别php格式的页面
ADDTypeapplication/x-httpd-php.phpADDTypeapplication/x-httpd-php-source.phps
(2)、添加默认起始页文件名
DirectoryIndex index.php
<IfModuledir_module>DirectoryIndexindex.phpindex.html</IfModule>
完成配置后,重载配置
[root@localhost~]#servicehttpdgraceful
(3)、为php提供配置文件,在我们解压出的源码目录中,有两个配置文件样例
[root@localhost~]#cd/root/downloads/php-5.4.41[root@localhostphp-5.4.41]#ls|grepphp.iniphp.ini-development#适用于开发环境php.ini-production#适用于生产环境
编译安装时,我们指定了php的配置文件目录/etc,这里我们把适用于生产环境的配置文件复制过去
[root@localhostphp-5.4.41]#cpphp.ini-production/etc/php.ini
(4)、测试
之前编译安装的apache,配置文件中,默认网站根目录是DocumentRoot "/usr/local/apache/htdocs"
在该路径新建一个测试页面index.php,内容如下
<h2>host1</h2><?phpphpinfo();?>
在浏览器输入主机地址测试,出现下图所示,说明安装、配置成功
(5)、测试连接mysql
/usr/local/apache/htdocs在该路径新建一个测试页面pcmysql.php,内容如下
<h2>host1</h2><?php$link=mysql_connect(localhost,root,'password');#注意之前给mysql的root用户改过密码执行函数返回值mysql_connect(localhost,"root",)存储在变量$link中if($link)echo"Sueccess.";elseecho"Failure.";?>
然后用浏览器访问这个页面,显示如下信息则说明php成功连接mysql
三、安装xcache,为php(opcode)加速
1、下载xcache
wgethttp://xcache.lighttpd.net/pub/Releases/3.1.2/xcache-3.1.2.tar.gz
2、为php添加xcache
[root@localhostdownloads]#tarxfxcache-3.1.2.tar.gz[root@localhostdownloads]#cdxcache-3.1.2[root@localhostxcache-3.1.2]#/usr/local/php/bin/phpizeConfiguringfor:PHPApiVersion:20100412ZendModuleApiNo:20100525ZendExtensionApiNo:220100525
3、编译安装xcache
[root@localhostxcache-3.1.2]#./configure--enable-xcache--with-php-config=/usr/local/php/bin/php-config[root@localhostxcache-3.1.2]#make&&makeinstall
安装完成,提示模块安装的位置
Installingsharedextensions:/usr/local/php/lib/php/extensions/no-debug-zts-20100525/
4、将xcache配置文件复制到php配置文件目录
[root@localhostxcache-3.1.2]#mkdir/etc/php.d[root@localhostxcache-3.1.2]#cpxcache.ini/etc/php.d[root@localhostxcache-3.1.2]#vim/etc/php.d/xcache.ini[root@localhostxcache-3.1.2]#servicehttpdgraceful#重载配置
新建测试页面,在浏览器中访问测试页面,显示如下画面,说明模块正常加载
vim/usr/local/apache/htdocs/test.php编辑如下内容<?phpphpinfo();?>
#配置文件已经载入
如果xcache没有正常工作,试试编辑xcache.ini,编辑extension = xcache.so,修改为全路径
extension=/usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
四、其他
配置文件/etc/php.ini,/etc/php.d/目录下的*.ini
php.ini官方文档:
配置参数:http://www.php.net/manual/zh/ini.list.php
核心配置参数详解:http://www.php.net/manual/zh/ini.core.php
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。