免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1429 | 回复: 0
打印 上一主题 下一主题

Ubuntu Linux 7.04下的apache2+php4+mysql5源码安装详解 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-05-26 12:25 |只看该作者 |倒序浏览

作者:zieckey(
zieckey@yahoo.com.cn
)
All Right Reserved!
Linux环境说明:
Ubunut 7.04
mysql-5.0.41
httpd-2.0.53
php-4.4.7
一、Apache服务器的安装
mkdir /home/zieckey/programfiles/apache
mkdir /home/zieckey/programfiles/php
mkdir /home/zieckey/programfiles/mqsql
[email=zieckey@zieckey-laptop:~/temp$]zieckey@zieckey-laptop:~/temp$[/email]
tar zxvf httpd-2.0.53.tar.gz
[email=zieckey@zieckey-laptop:~/temp/httpd-2.0.53$]zieckey@zieckey-laptop:~/temp/httpd-2.0.53$[/email]
./configure --prefix=/home/zieckey/programfiles/apache  --enable-module=so
[email=zieckey@zieckey-laptop:~/temp/httpd-2.0.53$]zieckey@zieckey-laptop:~/temp/httpd-2.0.53$[/email]
sudo make
[email=zieckey@zieckey-laptop:~/temp/httpd-2.0.53$]zieckey@zieckey-laptop:~/temp/httpd-2.0.53$[/email]
sudo make install
安装成功!
启动:
[email=zieckey@zieckey-laptop:~/temp/httpd-2.0.53$]zieckey@zieckey-laptop:~/temp/httpd-2.0.53$[/email]
cd /home/zieckey/programfiles/apache/
[email=zieckey@zieckey-laptop:~/programfiles/apache$]zieckey@zieckey-laptop:~/programfiles/apache$[/email]
./bin/apachectl start
(13): make_sock: could not bind to address [::]:80
no listening sockets available, shutting down
Unable to open logs
也许会出现上述错误,没关系,很好解决:
错误原因是Apache无法找到服务器的FQDN(Fully Qualified Domain Name).
最简单的,修改httpd.conf文件,增加:
ServerName
我的改为:
ServerName
www.zieckey.com:80
再次启动:
[email=zieckey@zieckey-laptop:~/programfiles/apache$]zieckey@zieckey-laptop:~/programfiles/apache$[/email]
./bin/apachectl start
(13): make_sock: could not bind to address [::]:80
no listening sockets available, shutting down
Unable to open logs
也许还会出现上面的问题,这个是因为Apache要用到的80端口被其他应用程序占用了,我们改个端口就好了:
conf/httpd.conf 中的
Listen 80 改为 Listen (你要使用的端口) 如 Listen 8080
不过这时在你访问你的apache 下的Web服务时 在域名后要加上端口号
如:
http://localhost:8080
另外,不要忘记下面的地方也要改为8080:
ServerName
www.zieckey.com:8080
好了,再启动:
[email=zieckey@zieckey-laptop:~/programfiles/apache$]zieckey@zieckey-laptop:~/programfiles/apache$[/email]
./bin/apachectl start
(13): httpd: could not open error log file /home/zieckey/programfiles/apache/logs/error_log.
Unable to open logs
哦没有权限:
[email=zieckey@zieckey-laptop:~/programfiles/apache$]zieckey@zieckey-laptop:~/programfiles/apache$[/email]
sudo ./bin/apachectl start
启动成功了!
在浏览器地址栏输入:
http://localhost:8080
或者
http://192.168.0.231:8080
看到了你要看到页面没有?

二 、MySQL的安装
1、下载mysql5的linux版本。
2、安装GCCt等必备的软件:
在终端下执行(网通用户请用交大的源):
sudo apt-get install gcc cpp g++ libncurses5-dev
sudo apt-get install make autoconf automake libtool
3、解压:
对于*.tar.gz的文件使用命令tar zxvf *.tar.gz来解压;
对于*.tar.bz2的文件使用命令tar jxvf *.tar.bz2来解压.
将mysql,php,apache以及gd安装到/opt/目录下,便于管理.
具体过程可参考:
把桌面上刚下的MySQL复制到/tmp下:cp Desktop/mysql-5.0.41.tar.gz /tmp
进入/tmp目录:cd /tmp
解压并展开:tar zxvf mysql-5.0.41.tar.gz
4、编译安装MySQL:
进入到解压后的mysql目录:
cd mysql-5.0.41
假设我常用用户是zieckey,则在终端输入下面的命令:
./configure --prefix=/home/zieckey/programfiles/mysql --with-mysqld-user=zieckey --with-extra-charsets=all --with-unix-socket-path=/tmp/mysql.sock
--prefix=/home/zieckey/programfiles/mysql 把mysql-5.0.41指定安装到/home/zieckey/programfiles/mysql目录中;
--with-extra-charsets=all 对多语言的支持;
--with-unix-socket-path=/tmp/mysql.sock 这个是指定mysql服务器启动后,联机套接字文件所处的位置和文件名,也就是说,如果mysql服务器成功启动后,就能在/tmp 目录中看到mysql.sock文件。如果看不到,肯定是mysql启动不了。
--with-mysqld-user=zieckey 这个是让mysql服务器也能让系统中普通用户zieckey也能启动mysql服务器。用普通用户来启动mysql的好处是:mysql的进程会自己死掉自动退出。当然root用户也可以,不过有时mysql有些进程死了,但不会自动退出,root自己也杀不掉。所以用普通用户就有这样的好处,大多不会出现mysql进程已死,但不会退出的情况;
当您看到“Thank you for choosing MySQL!”时,说明成功。
也许会看到如下信息:
checking for termcap functions library... configure: error: No curses/termcap library found
这说明系统中某些库文件没有,那么我们要安装这些库文件。安装上libncurses5-dev (不同的系统可能名字也有所差异)这个包就好了
sudo apt-get install libncurses5-dev
5、编译安装
sudo make
sudo make install
sudo scripts/mysql_install_db
6、后期配置
创建一个数据库管理员
sudo groupadd mysql
sudo useradd -g  mysql mysql
改变权限
sudo chown -R root  /home/zieckey/programfiles/mysql
sudo chown -R mysql /home/zieckey/programfiles/mysql/var
sudo chgrp -R mysql /home/zieckey/programfiles/mysql
sudo chown -R zieckey /home/zieckey/programfiles/mysql/var           //如果希望使用zieckey这个用户来启动mysql的话
sudo chgrp -R zieckey /home/zieckey/programfiles/mysql
配置环境变量
cd    //回到你的用户目录。
cp .bashrc .bashrc_bak    //备份.bashrc
gedit ~/.bashrc
在最后加入:
MySQL_HOME=/home/zieckey/programfiles/mysql
PATH=$MySQL_HOME/bin:$PATH
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MySQL_HOME/lib/mysql/
export JAVA_HOME CLASSPATH MySQL_HOME  LD_LIBRARY_PATH PATH  
然后在终端输入:source ~/.bashrc    //使刚修改的起作用
设置MYSQL自动启动:
sudo cp /home/zieckey/programfiles/mysql/mysql.server /etc/rc2.d/S20mysql
7、启动mysql服务器
[email=zieckey@zieckey-laptop:~/temp/mysql-5.0.41$]zieckey@zieckey-laptop:~/temp/mysql-5.0.41$[/email]
mysqld_safe -u mysql&
[1] 21845
[email=zieckey@zieckey-laptop:~/temp/mysql-5.0.41$]zieckey@zieckey-laptop:~/temp/mysql-5.0.41$[/email]
Starting mysqld daemon with databases from /home/zieckey/programfiles/mysql/var
查看是否启动了
[email=zieckey@zieckey-laptop:~/temp/mysql-5.0.41$]zieckey@zieckey-laptop:~/temp/mysql-5.0.41$[/email]
pgrep mysql
21845
21866
启动一个mysql客户端
[email=zieckey@zieckey-laptop:~/temp/mysql-5.0.41$]zieckey@zieckey-laptop:~/temp/mysql-5.0.41$[/email]
mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.41 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use test
Database changed
mysql> show tables;
Empty set (0.01 sec)
mysql>
至此,MySQL安装完成
三、安装PHP4
1.  安装php的时候,系统默认缺少两个组件,先安装
sudo apt-get install flex libxml2 libxml2-dev

下面是安装GD支持库
2.freetype
tar -xvjf freetype-2.1.3.tar.bz2
cd freetype-2.1.3
./configure
make
sudo make install
3.jpeg
tar -xvzf jpegsrc.v6b.tar.gz
cd jpeg-6b/
./configure --enable-shared --enable-static
make
mkdir /usr/local/man
mkdir /usr/local/man/man1
sudo make install
这里也许会出现错误:
/usr/bin/install -c -m 644 ./cjpeg.1 /usr/local/man/man1/cjpeg.1
/usr/bin/install: 无法创建一般文件 ‘/usr/local/man/man1/cjpeg.1’: No such file or directory
make: *** [install] 错误 1
这样解决:
[email=zieckey@zieckey-laptop:~/temp/jpeg-6b$]zieckey@zieckey-laptop:~/temp/jpeg-6b$[/email]
sudo mkdir -p /usr/local/man/man1/
在安装就好了:
sudo make install
4.zlib
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make
sudo make install
5.libpng
tar zxvf libpng-1.2.8-config.tar.gz
cd zlib-1.2.8
./configure
make
sudo make install
6.gd2
tar -zxvf gd-2.0.27.tar.gz
cd gd-2.0.27/
./configure --prefix=/home/zieckey/programfiles/gd2
make
make install
7. 安装PHP
[email=zieckey@zieckey-laptop:~/temp$]zieckey@zieckey-laptop:~/temp$[/email]
tar zxvf php-4.4.7.tar.gz
[email=zieckey@zieckey-laptop:~/temp$]zieckey@zieckey-laptop:~/temp$[/email]
cd php-4.4.7/
[email=zieckey@zieckey-laptop:~/temp/php-4.4.7$]zieckey@zieckey-laptop:~/temp/php-4.4.7$[/email]
./configure --with-gd=/home/zieckey/programfiles/gd2 --with-apxs2=/home/zieckey/programfiles/apache/bin/apxs --with-xml --with-mysql=/home/zieckey/programfiles/mysql
[email=zieckey@zieckey-laptop:~/temp/php-4.4.7$]zieckey@zieckey-laptop:~/temp/php-4.4.7$[/email]
make
[email=zieckey@zieckey-laptop:~/temp/php-4.4.7$]zieckey@zieckey-laptop:~/temp/php-4.4.7$[/email]
sudo make install
[email=zieckey@zieckey-laptop:~/temp/php-4.4.7$]zieckey@zieckey-laptop:~/temp/php-4.4.7$[/email]
sudo cp php.ini-dist /usr/local/lib/php.ini
四、最后的配置
cd /home/zieckey/programfiles/apache/conf/
[email=zieckey@zieckey-laptop:~/programfiles/apache/conf$]zieckey@zieckey-laptop:~/programfiles/apache/conf$[/email]
sudo cp httpd.conf httpd.conf.bak.good
[email=zieckey@zieckey-laptop:~/programfiles/apache/conf$]zieckey@zieckey-laptop:~/programfiles/apache/conf$[/email]
sudo gedit httpd.conf
对apache做如下配置
将ServerAdmin
q3boy@younet.com
一行改为您的邮箱地址
DocumentRoot "/home/httpd/html/" 此处为html文件主目录
增加下面几行:

AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
sudo gedit  /usr/local/lib/php.ini
添加:
register-golbals = On
五、测试
编写一个简单的PHP文件:hello.php

html>
meta http-equiv=Content-Type content=text/html; charset=utf8>
head>
title>Hello in PHP/title>
/head>
body>
h1>Hello in PHP/h1>
?php
print "Hello, world! ";
$link=mysql_connect('localhost','root','');
if(!$link) echo "数据库连接失败!";
else echo "数据库连接成功!";
mysql_close();
?>
/body>
/html>
保存到Apache目录下的htdocs,我的是:
/home/zieckey/programfiles/apache/htdocs
打开MySQL数据库服务器:
[email=zieckey@zieckey-laptop:~/temp/mysql-5.0.41$]zieckey@zieckey-laptop:~/temp/mysql-5.0.41$[/email]
mysqld_safe -u mysql&
在浏览器下输入:
http://localhost:8080/hello.php
看到了你想看的结果没有?
Hello in PHP
Hello, world! 数据库连接成功!
这里需要注意的一个问题就是,如果你的php页面是从其他FS拷贝过来的,比如从win2k的ntfs盘拷贝过来的,一定要重新设置所有文件的权限,否则会报错:
Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
Warning: Unknown: Failed opening '/usr/local/Webroot/index.php' for inclusion (include_path='.:/usr/local/php/lib/php') in Unknown on line 0
我一开始就被这个报错信息给误导了,找了半天关于include_path='.:/usr/local/php/lib/php'这个的原因,浪费了大量的时间

至此,Ubuntu Linux 7 下的apache2+php4+mysql5源码安装全过程已完成,下面就开始我们激动人心的PHP动态网页编程之旅吧。


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/16292/showart_310123.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP