您的位置:首页 > 运维架构 > Apache

[学习Linux]Linux+Apache+Mysql+PHP典型配置

2006-12-29 16:56 701 查看
 

[学习Linux]Linux+Apache+Mysql+PHP典型配置

调试环境:Redhat9.0 Apache2.0.55 Mysql3.23.57 PHP4.4.1

记得安装Redhat9。0的时候不要安装系统默认的apache,mysql和php以及相关的软件。
不过记得装上gcc。
已经安装的请用rpm -e XXX(rpm包名字) 删除已经安装的包,不过我告诉你。一般装上了就很难去掉了,因为有其他软件依赖,唉,我就是这样重装了3次rh9。
看到这文章时应该可以用新的软件了,原理一样的。

一、先安装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
  #查一下你的/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();
  ?>
  #地址栏中输入http://127.0.0.1/test.php 没有意外的话.你已经能看到php的信息页面了.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息