linux安装配置PHP环境

附原文地址:传送门
对于没有接触过 Linux 系统的人来说,在配置 PHP 环境上是比较头疼的。以下是别人的文章,在这里复制一份。

参考别人的做法,遇到问题上网查,下面就是安装步骤.
一、安装Apache2.2.22
1、到官网下载 http://httpd.apache.org/download.cgi
2、解压
tar -zxvf httpd-2.2.22.tar.gz
3、建立目标文件夹(注意以下所有操作都时在root用户下执行的)
mkdir /usr/local/apache2
也就是说等下安装的apache2要安装到这个文件夹里面
4、配置
回到原来解压之后产生的文件夹
./configure –prefix=/usr/local/apache2 –enable-module=shared
要加上后面的参数,否则无法使用php,-enable-module=shared表示Apache可以动态的加载模块

这一步,出现了很多问题:

第一个错误为:

checking for APR… no
configure: error: APR not found. Please read the documentation.
解决方法:

download the latest versions of both APR and APR-Util from Apache APR, unpack them into ./srclib/apr and ./srclib/apr-util (be sure the domain names do not have version numbers; for example, the APR distribution must be under ./srclib/apr/)

then do

./configure –with-included-apr
原文章地址:http://stackoverflow.com/questions/9436860/apache-httpd-setup-and-installatio
另外一种解决方法为:
分别安装APR和APR-util,安装方法为:首先下载这两个文件,然后解压,进入解压后目录,然后把APR和APR-util分别安装到/usr/local/文件夹的apr和apr-util文件夹下。APR的具体安装方法为:
[root@localhost 52lamp]# tar -zxvf apr-1.4.2.tar.gz //unzip -o apr-1.4.2.zip
[root@localhost 52lamp]# cd apr-1.4.2
[root@localhost apr-1.4.2]# ./configure –prefix=/usr/local/apr
[root@localhost apr-1.4.2]# make
[root@localhost apr-1.4.2]# make install
安装Apr-util 在./confiure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
其他步骤类似。

第二个错误为:no acceptable C compiler found in $Path
直接运行 yum install gcc,安装Gcc即可
第三个问题为:pcre-config for libpcre not found
解决方法就是 下载prce安装包,和APR类似,安装到/usr/local/pcre文件夹下面即可。PS:fedora下安装c++编译器g++的命令为:yum install gcc-c++ 。
5、编译
make
6、安装
make install
7、启动,重启和停止 ,先切换到安装完成后的目录/usr/local/apache2/bin
./apachectl -k start
./apachectl -k restart
./apachectl -k stop
8、配置文件(满足最基本的配置)
编辑 /usr/local/apache2/conf/httpd.conf 文件
找到:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在后面添加:
AddType application/x-httpd-php .php(使Apcche支持PHP)
AddType application/x-httpd-php-source .php5
找到:

DirectoryIndex index.html

添加:

DirectoryIndex index.html index.php

找到:
#ServerName www.example.com:80
修改为:
ServerName 127.0.0.1:80或者ServerName localhost:80
记得要去掉前面的“#”
9、测试
在浏览器里输入http://127.0.0.1
如果出现It Works!说明成功。这是我的测试结果:O(∩_∩)O哈哈~
这里写图片描述
10、修改默认的Web站点目录

 默认的目录为  "/usr/local/apache2/htdocs",修改apache的配置文件httpd.conf,比如在新建一个 /home/gyw/WebSite的目录作为apache的站点目录

找到DocumentRoot这一行修改为:DocumentRoot "/home/gyw/WebSite"

找到 这一行修改为:

<?php

$link=mysql_connect('localhost','root','123456');

if(!$link) echo "F!";

else echo "S!";

mysql_select_db("students") or die("Could not select database");
$query="SELECT * FROM student;";
$result=mysql_query($query) or die("Query failed");
print "<table>\n";

 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {        
print "\t<tr>\n";      
  foreach ($line as $col_value) {    
        print "\t\t<td>$col_value</td>\n";       
 }       
 print "\t</tr>\n";    }   
 print "</table>\n";



    /* 释放资源 */



mysql_free_result($result);
mysql_close();

?>

这里写图片描述

posted @ 2015-10-30 13:52  PeterZhaoChina  阅读(154)  评论(0编辑  收藏  举报