需要的软件包

在Linux系统 phpsoft文件夹下
解压 php-5.6.28.tar.gz
tar zxvf php-5.6.28.tar.gz
cd php-5.6.28
运行安装命令
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --enable-track-vars --with-xml --with-mysql-dir=/usr/include/mysql/mysql.h --with-zlib-dir=/usr/lib
如果出现如下错误

说明需要安装
libxml2-devel 依赖包
从系统光驱里拷贝
安装时提示错误 还是缺少依赖库

继续从光驱里拷贝


安装完之后查找xml2-config文件是否存在
[root@XKWB3403 php-5.3.8]# find / -name "xml2-config"
/usr/bin/xml2-config
再次执行
[root@localhost php-7.0.12]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --enable-track-vars --with-xml --with-mysql-dir=/usr/include/mysql/mysql.h --with-zlib-dir=/usr/lib
出现下面说明安装成功

配置Apache能够解析PHP代码
在Apache的配置文件中
cd /usr/local/apache/htdocs
<IfModule dir_module> DirectoryIndex index.html index.php
</IfModule>
新增下面配置


如果出现错误

通常情况下会自动在Apache下生成

如果没有可以到下面路径中拷贝

修改时区

将本机ip地址改为Apache配置文件中的serverName

此时可以解析PHP代码了
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
连接数据库代码如下
**注意要使用 mysqli而不是mysql
**
<?php
header('content-type:text/html;charset=utf-8'); $link=mysqli_connect('127.0.0.1','root','');
if (!$link){
echo '连接失败
';
die(mysql_errno());
}
mysqli_select_db($link,'lesson');
mysqli_query($link,'set names utf8');
$sql = "select * from study";
$query=mysqli_query($link,$sql);
$result = array();
while ($row = mysqli_fetch_assoc($query)){
$result[]=$row;
}
print_r($result);

直接输入127.0.0.1也可以

网友评论