依然使用几年前的centos5.4版本,现在都到了7.0了,还没有更换。老的系统了装了不少东西,没舍得换。最近学习一下脚本语言php,语法挺简单的,环境搭建费了点劲,记录一下。
首先下载相关的软件。
1.HTTP Apache
http://httpd.apache.org/download.cgi
http://archive.apache.org/dist/httpd/httpd-2.4.9.tar.gz
2.PHP5
http://www.php.net/downloads.php
http://cn2.php.net/get/php-5.5.15.tar.gz/from/a/mirror
接下来开始安装
1、apache:
#tar -zxvf httpd-2.4.9.tar.gz #cd httpd-2.4.9 #./configure --prefix=/usr/local/httpd --enable-so #make #make install
2、安装php
#tar zxvf php-5.5.15.tar.gz #cd php-5.5.15 #./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysql apxs2=/usr/local/httpd/bin/apxs #make #make install #cp php.ini-development /usr/local/php/php.ini
好了,来检验一下吧!
查看apache版本
httpd -v
或者 apachectl -v
显示结果:
Server version: Apache/2.2.3 Server built: Sep 3 2009 17:38:51
查看php的版本
需要将php命令加入到环境变量中:
修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码
PATH=$PATH:/usr/local/php/bin export PATH
最后:执行 命令source /etc/profile或 执行点命令 ./profile使其修改生效,执行完可通过echo $PATH命令查看是否添加成功。
配置Apache:
修改apache配置文件httpd.conf,注意在/etc/httpd/conf下修改
找到#AddType application/x-tar .tgz这一行,在下面加一行
AddType application/x-httpd-php .php 目的是让apache能解释 php 程序
找到 DirectoryIndex index.html 这一行,修改为
DirectoryIndex index.html index.php
Apache的启动、关闭、重启
启动命令:service httpd start
关闭命令:service httpd stop
重启命令:service httpd restart
错误解决:
1、在执行#./configure –prefix=/usr/local/httpd –enable-so时,出现错误:
Error – checking for apr… no configure error apr not found. please read the documentation
解决版本,安装apr,参考:http://opensourcemanual.wordpress.com/2013/07/25/error-checking-for-apr-no-configure-error-apr-not-found-please-read-the-documentation/
When we get an error as above while configuring apache, then the solution would be
Download the latest versions of both apr and apr-util from here and put them inside /tmp (any location would be fine)
cd /tmp gunzip -d apr-n.n.n.tar.gz tar -xvf apr-n.n.n gunzip -d apr-util-n.n.n.tar.gz tar -xvf apr-util-n.n.n.tar.gz
Now copy the contents of the above extracted files into them into .srclib/apr and srclib/apr-util folder of our apache installation folder. Lets assume that we have out httpd-n.n.n also in /tmp
cd /tmp/httpd-2.n.n/srclib mkdir apr mkdir apr-util cd apr cp /tmp/apr-n.n.n/* . -rf cd ../apr-util cp /tmp/apr-util-n.n.n/* . -rf cd ..
2、在make时出现错误:error:pcre-config for libpcre not found.
解决办法:下载pcre,安装,配置一下。
下载地址:http://www.linuxfromscratch.org/blfs/view/svn/general/pcre.html
安装pcre in /usr/local/pcre, using
./configure –prefix=/usr/local/pcre
make
sudo make install
在安装apache时,使用命令:
./configure –with-included-apr –with-pcre=/usr/local/pcre
make
sudo make install
3、安装pcre时出现错误:
configure: error: newly created file is older than distributed files!
解决办法:出现此编译错误,请检查你的系统时间是否设置有误……
修改系统时间命令:
# date -s 14-08-20 (2014年8月20号)
# date -s 10:30:30 (10点30分30秒)
# hwclock -w (将当前时间和日期写入BIOS,避免重启后失效)
完整过程:
./configure –with-included-apr –with-pcre=/usr/local/pcre/bin/pcre-config –prefix=/usr/local/httpd –enable-so