Linux,debian下源码编译安装gcc + apache2.2.6+php5.1.16+mysql5.0.

来源:互联网 发布:手机淘宝联盟怎么推广 编辑:程序博客网 时间:2024/06/07 06:12

作者:makiv的博客

转自:http://mikev.blog.163.com/blog/static/399110802009315102757247/


一、编译mysql 5.0.40
http://download.chinaunix.net/download/0008000/7159.shtml
下载地址

#cd /usr/local/src

# tar zxvf mysql-5.0.40.tar.gz
# cd mysql-5.0.46

#./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-enterprise-gpl --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all --with-pthread --enable-static --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-innodb --without-ndb-debug --without-isam

配置成功会提示:

MySQL has a Web site at http://www.mysql.com/ which carries details on the
latest release, upcoming features, and other information to make your
work or play with MySQL more productive. There you can also find
information about mailing lists for MySQL discussion.

Remember to check the platform specific part of the reference manual for
hints about installing MySQL on your platform. Also have a look at the
files in the Docs directory.

Thank you for choosing MySQL!

# make
编译的时间可能会比较长,毕竟优化的比较厉害。

# make install

编译安装完成后执行后续操作:
# groupadd mysql //添加组用户
# useradd mysql //添加 mysql 用户
# cd /usr/local/mysql
# bin/mysql_install_db --user=mysql
# chown -R root:mysql . //设置权限,注意后面有一个 "."
# chown -R mysql /var/lib/mysql //设置 mysql 目录权限
# chgrp -R mysql . //注意后面有一个 "."
# cp share/mysql/my-large.cnf /etc/my.cnf
# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld //开机自动启动 mysql。
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# /etc/init.d/mysqld start //启动 MySQL
#/usr/local/mysql/ bin/mysqladmin -u root password "password_for_root" // password_for_root为密码.本机是mysql

#/usr/local/mysql/bin/mysql –u root –p //进入mysql客户端

(/usr/local/mysql/bin/mysql –u root –p 提示Enter password: 输入密码,回车进入)
# /etc/init.d/mysqld start //关闭 MySQL

二 、编译安装 Apache
# cd /usr/local/src
# tar zxvf httpd-2.2.6.tar.gz
# cd httpd-2.2.6

#./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --with-mysql=/usr/local/mysql --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-static-support --enable-static-htpasswd --enable-static-htdigest --enable-static-rotatelogs --enable-static-logresolve --enable-static-htdbm --enable-static-ab --enable-static-checkgid --disable-cgid --disable-cgi

# make
# make install
# echo '/usr/local/apache2/bin/apachectl start ' >> /etc/rc.local //将 apachectl 的调用加入到你的系统启动文件中。

注解:
./configure //配置源代码树
--prefix=/usr/local/apache2 //体系无关文件的顶级安装目录PREFIX ,也就Apache的安装目录。
--enable-module=so //打开 so 模块,so 模块是用来提 DSO 支持的 apache 核心模块
--enable-mods-shared=all //编译全部的模板,对于不需要我们可以在httpd.conf去掉。
--enable-cache //支持缓存
--enable-file-cache //支持文件缓存
--enable-mem-cache //支持记忆缓存
--enable-disk-cache //支持磁盘缓存
--enable-static-support //支持静态连接(默认为动态连接)
--enable-static-htpasswd //使用静态连接编译 htpasswd - 管理用于基本认证的用户文件
--enable-static-htdigest //使用静态连接编译 htdigest - 管理用于摘要认证的用户文件
--enable-static-rotatelogs //使用静态连接编译 rotatelogs - 滚动 Apache 日志的管道日志程序
--enable-static-logresolve //使用静态连接编译 logresolve - 解析 Apache 日志中的IP地址为主机名
--enable-static-htdbm //使用静态连接编译 htdbm - 操作 DBM 密码数据库
--enable-static-ab //使用静态连接编译 ab - Apache HTTP 服务器性能测试工具
--enable-static-checkgid //使用静态连接编译 checkgid
--disable-cgid //禁止用一个外部 CGI 守护进程执行CGI脚本
--disable-cgi //禁止编译 CGI 版本的 PHP我们不再使用worker模式编译apache,worker模式和php貌似有一些不协调不稳定之处。所以使用了默认的perfork模式。

将apache设置成开机自启动:

在/etc/rc.d/rc.local文件中加入一行
/usr/local/apache2/bin/apachectl start
这样每次重新启动系统以后,apache也会随系统一起启动.

安装php
# cd /usr/local/src
# tar zxvf php-5.1.16.tar.gz
# cd php-5.1.16

#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-pear=/usr/share/php --with-zlib-dir --with-bz2 --with-libxml-dir=/usr --with-gd=/usr/local/gd2 --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf=shared,/usr --enable-mbstring --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/etc --with-iconv --disable-ipv6 --enable-static --enable-maintainer-zts --enable-zend-multibyte --enable-inline-optimization --enable-zend-multibyte --enable-sockets --enable-soap
配置成功会提示:

+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+

Thank you for using PHP.

# make

# make install

# cp php.ini-recommended /etc/php.ini

四 、整合apache 与php
# vi /usr/local/apache2/conf/httpd.conf
在最后一行加上:
AddType application/x-httpd-php .php

查找:(设置 WEB 默认文件)
DirectoryIndex index.html
替换为:
DirectoryIndex index.php index.html index.htm //在 WEB 目录不到默认文件,httpd 就会执行 /var/www/error/noindex.html

找到这一段:
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride none

更改为AllowOverride all
允许apache rewrite

保存httpd.conf,退出。

# /usr/local/apache2/bin/apachectl restart //重启 Apache

五、 测试
vi /usr/local/apache2/htdocs/test.php

新增加下面一行,并保存。

<?php phpinfo(); ?>

# chmod 755 /usr/local/apache2/htdocs/phpinfo.php

用浏览器打开 http://locahost/test.php

或者 http://本机ip/test.php
(如ip为192.168.4.2 则 http://192.168.4.2/test.php)

当看到php页面时表示成功!



前前后后查了2,3天的资料,把我搞的很惨,但是终于还是把它征服了^_^,乘空赶快把它整理整理。由于我的linux系统是最小化安装,所以你必须要安装gcc编译器,才能正常安装tar包。gcc编译器在linux自带的第一张光盘里有,按顺序安装下面的rpm包(你可以用tab键自动补全):
  binutils
  cpp
  glibc-kernheaders
  glibc-devel
  gcc(这个是在第二张)
  这几个装好之后要继续装这几个rpm包,它们在第二张盘里都可以找的到。不然在安装过程中还是会出错的:
  libtermcap-devel-2.0.8-35.i386.rpm
  gcc-c++-3.2.2-5.i386.rpm #这2个是安装mysql时必须的
  bison-1.35-6.i386.rpm
  flex-2.5.4a-29.i386.rpm
  zlib-devel-1.1.4-8.i386.rpm #这3个是安装php是必须的
  好的,这可以说是准备工作了,下面进入真正的实战啦:
  关于这3款软件的下载你可以去他们的官方网下载
  mysql:http://www.mysql.org/
  http://www.apache.org/
  http://www.php.net/
  一、先安装最简单的mysql

  1 mysql的官方网站建议在目前的版本中,最好直接以它们编译好的mysql的binary版本来进行安装,(因为在使用tarball的方式来编译,如果你的gcc版本高于2.96时,那么编译出来的mysql程序很有可能会有数据库突然死掉的情况发生)这样就变得很简单了。
  把下载来的tar包都放在/usr/local/src(这样可以方便集中管理)
  [root@weiming root]# groupadd mysql
  [root@weiming root]# useradd -g mysql mysql #创建mysql组和mysql用户,这很重要哦。
  [root@weiming root]# cd /usr/local
  [root@weiming local]# tar -zxvf /usr/local/src/mysql-3.23.57-pc-linux-i686.tar.gz
  [root@weiming local]# ln -s mysql-3.23.57-pc-linux-i686 mysql
  [root@weiming local]# cd mysql
  [root@weiming mysql]# scripts/mysql_install_db
  #这个步骤会在/usr/local/mysql/data里建立好mysql数据库
  [root@weiming mysql]# chown -R root .
  [root@weiming mysql]# chown -R mysql data
  [root@weiming mysql]# chgrp -R mysql .
  #设置一些目录的权限,一定要的
  [root@weiming mysql]# bin/safe_mysqld --user=mysql &
  starting mysqld daemon with databases from /usr/local/mysql/data
  #这个时候mysql会建立一个/tmp/mysql.sock,可以先等会儿不要急着按enter。这个socket file是动态生成的,不可以被移动,复制,没它mysql是启动不了的。

  2.[root@weiming mysql]# netstat -tl | grep mysql
  tcp 0 0 *:mysql *:* LISTEN
  #这样就搞定了,mysql已经在监听了。

  3.开机后立即启动:
  [root@weiming mysql]# vi /etc/rc.d/rc.local
  #将下面这一行加入到最后一行
  cd /usr/local/mysql; /usr/local/mysql/bin/safe_mysqld --user=mysql &
  #记得加上cd /usr/local/mysql;并在改句后面加个空格,不然会导致无法自动在开机的时候启动(让我郁闷了好久)。

  4.高级设置:
  由于mysql放置的位置在/usr/local/mysql中,而这个目录不在PATH当中,且man page也不在MANPATH里面,所以要手动加入。
  [root@weiming mysql]# vi /etc/profile
  找到export PATH...那一行,加入这么句:
  PATH="$PATH":/usr/local/mysql/bin
  #记得要logout,这个命令在下次开机也可以用了。
  [root@weiming mysql]# vi /etc/man.config
  #可以在这个文件的任何地方加入这么一行:
  MANPATH /usr/local/mysql/man

  5.建立mysql的root帐号密码:
  [root@weiming mysql]# /usr/local/mysql/bin/mysqladmin -u root password 'yourpassword'
  #为了安全

  二、安装需要编译的新版apache2.*

  1.因为目前有所谓的这个动态函数库,因此,在安装apache时,请特别要向apache声明php模块使用动态函数库的模式。
  [root@weiming root]# cd /usr/local/src
  [root@weiming src]# tar -zxvf httpd-2.0.55.tar.gz
  [root@weiming src]# cd httpd-2.0.55
  [root@weiming httpd-2.0.55]# ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite
  #--prefix=/安装的路径
  --enable-so 这是在宣告使用动态函数库,特别重要!
  --enable-rewrite 这是预防用的,先设置一下。

  2.开始编译与安装:
  [root@weiming httpd-2.0.55]#make; make install
  #应该不会有什么问题了

  3.简单的修改:
  [root@weiming httpd-2.0.55]# vi /usr/local/apache2/conf/httpd/conf
  #找到这2行:
  User nobody
  Group #-1
  #很奇怪,居然是#-1,查一下你的/etc/passwd与/etc/group是否有nobody存在,没有的话自行加。
  User nobody
  Group nobody
  #存储后推出。

  4.确定启动状态:
  [root@weiming httpd-2.0.55]# /usr/local/apache2/bin/apachectl start
  [root@weiming httpd-2.0.55]# netstat -utl
  tcp 0 0 *:http *:* LISTEN
  同样把/usr/local/apache2/bin/apachectl start放在/etc/rc.d/rc.local内,开机时启动apache。

  5.高级设置:
  跟mysql的一样的,在/etc/profile将安装mysql新增的那行该为:
  PATH="$PATH":/usr/local/mysql/bin:/usr/local/apache2/bin
  还有man参照mysql的设置。

  三、安装php

  1.
  [root@weiming root]#cd /usr/local/src
  [root@weiming src]# tar -zxvf php-4.4.1.tar.gz
  [root@weiming src]# cd php-4.4.1
  [root@weiming php-4.4.1]# ./configure --prefix=/usr/local/php4 --with-apxs2=/usr/local/apache2/bin/apxs --with-

  mysql=/usr/local/mysql
  #--with-apxs2=/usr/local/apache2/bin/apxs 这是apache2专用的选项,请针对你的主机设置
  --with-mysql 这是针对mysql的安装路径,这几个是同一行的.

  ...skipping
  +--------------------------------------------------------------------+
  | License: |
  | This software is subject to the PHP License, available in this |
  | distribution in the file LICENSE. By continuing this installation |
  | process, you are bound by the terms of this license agreement. |
  | If you do not agree with the terms of this license, you must abort |
  | the installation process at this point. |
  +--------------------------------------------------------------------+
  | *** NOTE *** |
  | The default for register_globals is now OFF! |
  | |
  | If your application relies on register_globals being ON, you |
  | should explicitly set it to on in your php.ini file. |
  | Note that you are strongly encouraged to read |
  | http://www.php.net/manual/en/security.globals.php |
  | about the implications of having register_globals set to on, and |
  | avoid using it if possible. |
  +--------------------------------------------------------------------+

  Thank you for using PHP.

  2.开始编译与安装:
  [root@weiming php-4.4.1]# make
  ...skipping
  Build complete.
  (It is safe to ignore warnings about tempnam and tmpnam).
  [root@weiming php-4.4.1]#make install

  [root@weiming php-4.4.1]# cp php.ini-dist /usr/local/lib/php.ini
  将主要的 php 设定档 php.ini-dist 拷贝成 /usr/local/lib/php.ini 这个档案,
  这是因为 apache 或其它程序执行 php 时需要到 usr/local/lib/ 中去使用这档案。

  3.启动apache当中的php选项:
  [root@weiming php-4.4.1]# vi /usr/local/apache2/conf/httpd.conf
  #找到下面2行
  LoadModule php4_module modules/libphp4.so #大约在231行
  AddType application/x-httpd-php .php #在847行自行增加

  4.重新启动apache:
  [root@weiming php-4.4.1]# /usr/local/apache2/bin/apachectl stop
  [root@weiming php-4.4.1]# /usr/local/apache2/bin/apachectl start

  5.测试php是否正常工作;
  [root@weiming php-4.4.1]# cd /usr/local/apache2/htdocs
  [root@weiming php-4.4.1]# vi test.php
  <?
  phpinfo();
  ?>
  #以我的测试主机为例,ip是192.168.3.1,我在虚拟机上也安装了2000,所以得同时启动windows2000,在2000地址栏中输入http://192.168.3.1/test.php
  呵呵,看到了那熟悉的php测试页了吧:-)

____________________________________________________________________________________

1 先来安装mysql  
# groupadd mysql
# useradd -g mysql -d /usr/local/mysql/data -M mysql
# tar -zxvf mysql-5.0.56.tar.gz
# cd mysql-5.0.56
./configure --prefix=/usr/local/mysql             \ 指定安装目录
> --sysconfdir=/etc                                          \ 配置文件的路径
> --localstatedir=/usr/local/mysql/data        \ 数据库存放的路径
> --enable-assembler                                       \ 使用一些字符函数的汇编版本
> --with-mysqld-ldflags=-all-static                \ 以纯静态方式编译服务端
> --with-charset=gbk                                       \ 添加GBK字符支持
> --with-extra-charsets=gbk                           \添加GBK字符集
> --with-extra-charsets=all                             \添加所有字符支持
# make
# make install
# /usr/local/mysql/bin/mysql_install_db --user=mysql  初始化数据库
# chown -R mysql:mysql /usr/local/mysql/data
# cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysql  
# chkconfig --add mysql                           添加服务
# cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
# /etc/rc.d/init.d/mysql start                    启动数据库
# /usr/local/mysql/bin/mysqladmin -u root password 123456   设置密码
# /usr/local/mysql/bin/mysql -u root -p123456     连接数据库
# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
这里是把mysql文件链接到默认位置,可以不做这步,在编译其他软件的时候自定义myslq的库文件路径。
安装过程中遇到一点小错误,就是gcc没有安装,大家不要犯这么弱的错误,呵呵。
____________________________________________________________________________________
2 安装apache
# tar -zxvf httpd-2.2.9.tar.gz
# cd httpd-2.2.9
# ./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so --enable-rewrite
(1)--prefix=/usr/local/apache2 指明安装路径
(2)--enable-mods-shared=most   动态加载大多数模块
(3)--enable-so     如果希望核心能够装载 DSO,而不实际编译任何动态模块,则要明确指定 --enable-modules=so 或者 --enable-so
(4)--enable-rewrite  模块则是用意实现地址重写的模块
# make
# make install
# /usr/local/apache2/bin/apachectl start     启动apache

3 安装php
# tar -zxvf php-5.2.6.tar.gz
# cd php-5.2.6
执行之前,请检查是否安装了libxml和libxml-devel和zlib  否则会报错。
# ./configure --prefix=/usr/local/php5
>--with-apxs2=/usr/local/apache2/bin/apxs
>--with-libxml --with-libxml-dir=/usr/local/lib
>--with-zlib --with-zlib-dir=/usr/locla/lib
>--with-mysql=/usr/local/mysql
>--with-mysqli=/usr/local/mysql/bin/mysql_config
>--with-gd --enable-soap --enable-sockets
执行之前,请检查是否安装了libxml和libxml-devel和zlib  否则会报错。
# make
# make install
安装结束了,然后
编辑Apache配置文件,即/usr/local/apache2/conf/httpd.conf,
并添加以下一行:AddType application/x-httpd-php .php
并在 DirectoryIndex 一行后面加上 index.php

4 测试
# vi /usr/local/apache2/htdocs/index.php
     <?
     phpinfo();
    ?>
然后启动apache,访问http://IP/index.php  如果能看到,恭喜你,安装结束。

来源:http://www.shz.net.cn/article.asp?id=46
原创粉丝点击