安装Apache

1.切换到root用户:su root
(2.删除非空目录,强制删除,不提示)
2.解压apache软件包 tar -zxvf httpd-2.4.6.tar.gz
3.创建LAMP/Apache
4.进入解压后的Apace目录 cd httpd-2.4.6
5. ./configure --prefix=home/cg/LAMP/Apache
(error:APR NOT FOUND)
6.安装APR
./configure --prefix=home/cg/LAMP/APR
(不知道是否安装成功了)
7 .    ./configure --prefix=/home/cg/LAMP/Apache (注意home的路径,若不加/,会报错:expected an absolute directory name)
(error:APR NOT FOUND)
8删除APR
9.    安装apr-util
./configure --prefix=/home/cg/LAMP/apr-util  --with-apr=/home/cg/LAMP/APR/bin/apr-1-config
2013年11月24日
10.安装PHP时,图简便,我没有安装GD等库。在安装的过程中,报错无libxml,没有提示缺少其他的。安装了libxml后,可以安装PHP了。make 之后,提示信息说要make test,于是make test,花的时间有点长。
11.make install PHP 之后,书上说要在apache的httpd.conf中修改配置文件,(见《php典型模块》P35 2.4.4)。但我在httpd.conf中没有发现书上说的相关东西,因此不知道如何修改。
12.没有修改apache的配置文件httpd.conf时,访问PHP文件,显示的PHP文件源码。
13.我尝试一下如何修改才能让apache支持php
在#AddType application/x-gzip .tgz加上
 LoadModule php5_module modules/libphp5.so
   AddType application/x-httpd-php .php
后重启apache,得到报错信息
httpd: Syntax error on line 365 of /home/cg/LAMP/apache/conf/httpd.conf: Cannot load modules/libphp5.so into server: /home/cg/LAMP/apache/modules/libphp5.so: cannot open shared object file: No such file or directory
14.为解决13的问题,决定重新编译PHP。为此,要先删除原来的PHP。用普通的删除命令把安装php的目录删除了---rm -f php。再用普通命令删除。
15.进入php的源码目录,使用安装命令
./configure --prefix=/home/cg/LAMP/php --with-apxs=/home/cg/LAMP/apache/bin/apxs --with-config-file-path=/home/cg/LAMP/php/etc --with-MySQL=/home/cg/LAMP/mysql --with-libxml=/home/cg/LAMP/libxml
提示信息,截取一部分
Configuring SAPI modules
checking for AOLserver support... no
checking for Apache 1.x module support via DSO through APXS... configure: error: You have enabled Apache 1.3 support while your server is Apache 2.  Please use the appropiate switch --with-apxs2
不知道是什么意思,对上面的命令稍作修改再试一试。
./configure --prefix=/home/cg/LAMP/php --with-apxs2=/home/cg/LAMP/apache/bin/apxs --with-config-file-path=/home/cg/LAMP/php/etc --with-MySQL=/home/cg/LAMP/mysql --with-libxml=/home/cg/LAMP/libxml
16。15中的最后一步后,再执行make时报错,估计是--with-libxml出错,改为--with-libxml-dir后再试一试。
17.运行make后,最后提示
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
directorytreeiterator.inc
invertedregexiterator.inc
pharcommand.inc
clicommand.inc
directorygraphiterator.inc
phar.inc


Build complete.
Don't forget to run 'make test'.

我认为成功了。为节约时间,这次,步运行make test,看看会出现什么情况。
18.make install
提示信息
Installing PHP SAPI module:       apache2handler
/home/cg/LAMP/apache/build/instdso.sh SH_LIBTOOL='/home/cg/LAMP/apr/build-1/libtool' libphp5.la /home/cg/LAMP/apache/modules
/home/cg/LAMP/apr/build-1/libtool --mode=install install libphp5.la /home/cg/LAMP/apache/modules/
libtool: install: install .libs/libphp5.so /home/cg/LAMP/apache/modules/libphp5.so
libtool: install: install .libs/libphp5.lai /home/cg/LAMP/apache/modules/libphp5.la
libtool: install: warning: remember to run `libtool --finish /home/cg/下载/php-5.4.15/libs'
chmod 755 /home/cg/LAMP/apache/modules/libphp5.so
[activating module `php5' in /home/cg/LAMP/apache/conf/httpd.conf]
Installing PHP CLI binary:        /home/cg/LAMP/php/bin/
Installing PHP CLI man page:      /home/cg/LAMP/php/php/man/man1/
Installing PHP CGI binary:        /home/cg/LAMP/php/bin/
Installing build environment:     /home/cg/LAMP/php/lib/php/build/
Installing header files:          /home/cg/LAMP/php/include/php/
Installing helper programs:       /home/cg/LAMP/php/bin/
  program: phpize
  program: php-config
Installing man pages:             /home/cg/LAMP/php/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /home/cg/LAMP/php/lib/php/
[PEAR] Archive_Tar    - installed: 1.3.11
[PEAR] Console_Getopt - installed: 1.3.1
warning: pear/PEAR requires package "pear/Structures_Graph" (recommended version 1.0.4)
warning: pear/PEAR requires package "pear/XML_Util" (recommended version 1.2.1)
[PEAR] PEAR           - installed: 1.9.4
Wrote PEAR system config file at: /home/cg/LAMP/php/etc/pear.conf
You may want to add: /home/cg/LAMP/php/lib/php to your php.ini include_path
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util       - installed: 1.2.1
/home/cg/下载/php-5.4.15/build/shtool install -c ext/phar/phar.phar /home/cg/LAMP/php/bin
ln -s -f /home/cg/LAMP/php/bin/phar.phar /home/cg/LAMP/php/bin/phar
Installing PDO headers:          /home/cg/LAMP/php/include/php/ext/pdo/


我认为:安装成功了。
19.重启apache,看是否支持PHP。
运行phpinfo.php,打印出了相关信息。这说明加上13步的设置,php安装成功了。但仍有正常情况下不会出现的信息
Warning : phpinfo(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in  /home/cg/LAMP/apache/htdocs/www/phpinfo.php  on line  2
20.根据19中的warning,想在php.ini中修改配置。但是却在../php/lib中没有发现php.ini,在home/cg/LAMP/php/etc中也没有发现php.ini,经过搜索,发现要更改php.ini目录,而且,在更改的同时,需要从PHP发行包中将php.ini配置文件(可能不是这个名字)复制到设定的php.ini搜索目录。PHP manual上的命令是
--with-config-file-path=/etc    (将php.ini的搜索目录设置为/etc)
--with-config-file-scan-dir=PATH(复制php.ini文件到搜索目录)
我配置安装php时没有用第二个命令,在php的安装目录没有发现php.ini文件。想在安装完毕之后,再从发行包复制此文件,但是我发现php.ini-development文件空白的,php.ini-production不是空白的。我把php.ini-producttion复制到/etc看php.ini能否生效
命令
cp /home/cg/下载/php-5.4.15/php.ini-production /home/cg/LAMP/php/etc
由于在php-5.4.15中,实际使用的命令是
cp -f php.ini-production /home/cg/LAMP/php/etc
此命令成功了,但忘记把php.ini-production 改名为php.ini,故删除复制过去的文件,重新复制,命令
cp -f php.ini-production /home/cg/LAMP/php/etc/php.ini
成功。再检测此处的php.ini是否有效。
21.修改php安装目录中的php.ini,在;date.timezone=下加了一行
date.timezone=PRC,再次运行相关php文件,发现无效。打算重启,重启php,不知道如何重启。那就重启apche,看是否有效。
无效。
22.重复执行第21步骤,但把date.timezone=Asia/Shanghai,仍然无效。改成
date.timezone="Asia/Shanghai"再执行第21步骤。无效。
23.根据PHP MANUAL上的这段
(以后补充)
得知:--with-config-file-path = /home/cg/LAMP/php/etc没有产生作用,可能上因为没有同时复制php发行包中的php.ini-production导致的。根据phpinfo信息得知,php.ini的搜索目录仍然是../lib.为了使php.ini生效,我把/home/cg/LAMP/php/etc中的php.ini复制到/home/cg/LAMP/php/lib中,命令
cp -f /home/cg/LAMP/php/etc/php.ini /home/cg/LAMP/php/lib/php.ini
由于在etc目录,所以实际使用的命令是
cp -f php.ini /home/cg/LAMP/php/lib/php.ini
删除etc目录下的php.ini,命令rm -f php.ini(或rm -rf php.ini)
再次运行相关php文件,发现php.ini生效了
24.运行连接数据库的php文件时,报错
网站在检索(该文件时)遇到错误,可能上网站关闭或配置步正确。
我认为,是因为在编译安装PHP时没有关联mysql,故需要重新编译安装php.
25.PHP代码中存在错误时,无报错,修改php.ini中的如下配置后,出现报错信息。配置如下:
error_reporting = E_ALL 
error_log=/path/to/your/php_errors.log 
display_errors=On (仅修改此项)
26.在未修改PHP的报错配置时,运行连接数据库的代码,就会提示网站未配置后等信息,修改报错配置后,再运行同样的代码,出现报错信息:
Fatal error: Call to undefined function mysql_connect() in /home/cg/LAMP/apache/htdocs/www/strtolower.php on line 5
我认为原因上没有安装PHP的mysql相关的扩展,到哪里去下载该扩展?在PHP的官网的这个页面http://www.php.net/manual/en/mysql.installation.php没有看到扩展下载链接。
我认为很多扩展比如mysql扩展就在下载的PHP源码包的ext中。
27.
第一步:进入php源码中的"ext/mysql"目录下
第二步:在当前目录下运行phpize
root@startos:/home/cg/下载/php-5.4.15/ext/mysql# /home/cg/LAMP/php/bin/phpize --with-mysql=/home/cg/LAMP/mysql
运行上述命令后,出现提示信息:
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
不知道它们是什么意思。
第三步:运行刚才生成的configure文件
根据教程,phpize(一个专门挂接php扩展的工具,在PHP的安装目录的bin目录下)的规则:去哪个目录下运行phpize文件,那么就会在该目录下生成一个configure文件。在
/home/cg/下载/php-5.4.15/ext/mysql目录下,我看到了一个configure,但是由于在执行上述命令之前,我没有留意此目录下有无configure,故我不能确定configure是不是上述命令生成。configure里面是我看不懂的大量代码。
运行命令:
root@startos:/home/cg/下载/php-5.4.15/ext/mysql# ./configure --with-php-configure=/home/cg/LAMP/php/bin/php-config --with-mysql=/home/cg/LAMP/mysql
报错信息:
configure: WARNING: unrecognized options: --with-php-configure
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
configure: error: Cannot find php-config. Please use --with-php-config=PATH
将上述命令修改为
root@startos:/home/cg/下载/php-5.4.15/ext/mysql# ./configure --with-php-config=/home/cg/LAMP/php/bin/php-config --with-mysql=/home/cg/LAMP/mysql
截取提示信息的最后部分
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
我认为是上述命令执行成功了。
第四步:编译生成.so文件。最终要的东西
执行命令root@startos:/home/cg/下载/php-5.4.15/ext/mysql# make
提示信息的最后部分
Build complete.
Don't forget to run 'make test'.
执行命令root@startos:/home/cg/下载/php-5.4.15/ext/mysql# make test
执行命令root@startos:/home/cg/下载/php-5.4.15/ext/mysql# make install
提示信息:
Installing shared extensions:     /home/cg/LAMP/php/lib/php/extensions/no-debug-zts-20100525/
不知是什么意思。

第五步:配置php引擎加载该扩展(如何做)
在php.ini中加入
;added at 12/07/2013
extension_dir = "/home/cg/LAMP/php/lib/php/extensions/no-debug-zts-20100525/"
extension = mysql.so
重启apache,再运行phpinfo,看到了mysql的扩展。
再运行使用了mysql扩展中的函数的脚本测试,OK,说明已经成功安装了php的mysql扩展。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值