Linux之PHP

1.下载源码包并解压

cd /usr/local/src
wget
http://cn2.php.net/distributions/php-5.6.18.tar.gz
tar zxvf php-5.6.18.tar.gz
cd php-5.6.1

 2. 安装相关的依赖包

安装libiconv库

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar -xvf libiconv-1.14.tar.gz
cd libiconv-1.14

./configure --prefix=/usr/local/libconv make make install

安装相关依赖环境

yum -y install curl-devel  libxslt libxslt-devel libxml2 libxml2-devel bzip2 bzip2-devel openssl openssl-devel libpng libpng-devel  freetype freetype-devel 

 

3.编译  (./configure --help 可以查看相关参数)

./configure \
--prefix=/usr/local/php5.6.18 \
 --with-apxs2=/usr/local/apache2.2.31/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-xmlrpc \
--with-openssl \
--with-zlib \
--with-freetype-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-iconv=/usr/local/libiconv \
--enable-short-tags \
--enable-sockets \--enable-soap \
--enable-mbstring \
--enable-static \
--enable-gd-native-ttf \
--with-curl \
--with-xsl \
--enable-ftp \
--with-libxml-dir

4.安装

make && make install 

5.拷贝生产环境配置的文件

cp php.ini-production /usr/local/php5.6.18/lib/php.ini

 6.apache结合php

Apache主配置文件为:/usr/local/apache2/conf/httpd.conf

vim /usr/local/apache2/conf/httpd.conf 

找到:

AddType application/x-gzip .gz .tgz

在该行下面添加:

AddType application/x-httpd-php .php

找到:

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

将该行改为:

<IfModule dir_module>
    DirectoryIndex index.html index.htm index.php
</IfModule>

找到:

#ServerName www.example.com:80

修改为:

ServerName localhost:80

7.测试与mysql的连接
在/usr/local/apache/htdocs下建立testmysql.php
<?php
/* 
测试连接
*/
    //$link_id=mysql_connect('主机名','用户','密码');
    $link_id=mysql_connect('localhost','root','123456') or mysql_error();
    //$link_id=mysql_connect('localhost','test','');
    if($link_id){
        echo "mysql conn successful !";
    }else{
        echo mysql_error();
    }

?>

 

 

你可能感兴趣的:(Linux之PHP)