RHEL4环境部署Linux+Apache+MySQL+PostgreSQL+PHP环境--原创
作 者:Flyinger
Email:flyingercn@gmail.com
QQ:46715422
--转载请注明出处http://fyzx77.cublog.cn!
系统环境:
[root@rhel4 soft]# uname -a
Linux rhel4 2.6.9-89.ELsmp #1 SMP Mon Apr 20 10:34:33 EDT 2009 i686 i686 i386 GNU/Linux
You have mail in /var/spool/mail/root
[root@rhel4 soft]# gcc --version
gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-11)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@rhel4 soft]# perl -v
This is perl, v5.8.5 built for i386-linux-thread-multi
Copyright 1987-2004, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at the Perl Home Page.
[root@rhel4 soft]# python
Python 2.3.4 (#1, Feb 18 2008, 17:17:04)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
一、MySQL-5.1.39的安装与配置
解压
[root@rhel4 soft]# tar zxvf mysql-5.1.39.tar.gz
[root@rhel4 soft]# cd mysql-5.1.39
编译并安装
[root@rhel4 mysql-5.1.39]# ./configure --prefix=/usr/local/mysql --enable-thread-safe-client --enable-local-infile --with-charset=utf8 --with-extra-charset=all --with-low-memory && make && make install
拷贝主配置文件到/etc目录
[root@rhel4 mysql-5.1.39]# cp support-files/my-medium.cnf /etc/my.cnf
初始化数据库,安装数据库系统自身必须的数据库和表,并修改相应的权限
[root@rhel4 mysql-5.1.39]# cd /usr/local/mysql
创建用户
[root@rhel4 mysql]# groupadd mysql
[root@rhel4 mysql]# useradd -g mysql mysql
[root@rhel4 mysql]# chown -R mysql .
[root@rhel4 mysql]# chgrp -R mysql .
[root@rhel4 mysql]# bin/mysql_install_db --user=mysql
[root@rhel4 mysql]# chown -R root .
[root@rhel4 mysql]# chown -R mysql var
启动mysql
[root@rhel4 mysql]# bin/mysqld_safe --user=mysql &
拷贝启动脚本到相应的目录,并修改其权限
[root@rhel4 ~]# cd /soft/mysql-5.1.39
[root@rhel4 mysql-5.1.39]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@rhel4 mysql-5.1.39]# chmod 700 /etc/rc.d/init.d/mysqld
使mysql能在系统启动时自动启动
[root@rhel4 mysql-5.1.39]# chkconfig --add mysqld
[root@rhel4 mysql-5.1.39]# chkconfig --level 2345 mysqld on
测试
[root@rhel4 mysql-5.1.39]# /usr/local/mysql/bin/mysqladmin ping
[root@rhel4 mysql-5.1.39]# /usr/local/mysql/bin/mysqladmin version
[root@rhel4 mysql-5.1.39]# /usr/local/mysql/bin/mysql
添加root密码
[root@rhel4 mysql-5.1.39]# /usr/local/mysql/bin/mysqladmin -u root password 'root'
说明:此root用户为mysql的root用户,默认密码为root
登录:
[root@rhel4 mysql-5.1.39]# /usr/local/mysql/bin/mysql -uroot -proot
查看有哪些数据库:
mysql> show databases;
创建数据库:
mysql> create database mydb;
使用某一数据库:
mysql> use mydb;
查看数据库中的表:
mysql> show tables;
退出数据库:
mysql> \q
=== MySQL配置完成 ===
二、postgresql-8.4.1的的安装与配置
解压
[root@rhel4 soft]# tar zxvf postgresql-8.4.1.tar.gz
[root@rhel4 soft]# cd postgresql-8.4.1
创建用户
[root@rhel4 postgresql-8.4.1]# groupadd postgres
[root@rhel4 postgresql-8.4.1]# useradd -g postgres postgres
编译并安装
[root@rhel4 postgresql-8.4.1]# ./configure --prefix=/usr/local/postgresql && make && make install
[root@rhel4 postgresql-8.4.1]# cd /usr/local
[root@rhel4 local]# ln -s postgresql pgsql
[root@rhel4 local]# mkdir /usr/local/pgsql/data
[root@rhel4 local]# cd /usr/local/pgsql
[root@rhel4 pgsql]# chown postgres.postgres data
初始化数据库目录(postgres)
[root@rhel4 pgsql]# su - postgres
[postgres@rhel4 ~]$ cd /usr/local/pgsql/bin
设置locale为C,并且template1编码为UNICODE,使数据库支持中文
[postgres@rhel4 bin]$ ./initdb --locale=C -E UNICODE -D ../data/
[postgres@rhel4 bin]$ ./postgres -D ../data
配置环境变量及日志文件(root)
[postgres@rhel4 bin]$ su - root
编辑/etc/profile文件
[root@rhel4 ~]# vi /etc/profile
PATH=/usr/local/pgsql/bin:$PATH
PGDATA=/usr/local/pgsql/data
使环境变量生效(或重启操作系统)
[root@rhel4 ~]# export PGDATA=/usr/local/pgsql/data
[root@rhel4 ~]# touch /var/log/pgsql.log
[root@rhel4 ~]# chown postgres.postgres /var/log/pgsql.log
修改配置文件(postgres)
[root@rhel4 ~]# su - postgres
[postgres@rhel4 ~]$ cd /usr/local/pgsql/data
修改配置使监听生效,取消以下两行的注释
[postgres@rhel4 data]$ vi postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost', '*' = all
# (change requires restart)
port = 5432 # (change requires restart)
启动数据库(postgres)
[postgres@rhel4 data]$ cd /usr/local/pgsql/bin
[postgres@rhel4 bin]$ ./postmaster -D /usr/local/pgsql/data > /var/log/pgsql.log 2>&1 &
[postgres@rhel4 bin]$ cat /var/log/pgsql.log
创建数据库mydb
[postgres@rhel4 bin]$ ./createdb mydb
创建用户
[postgres@rhel4 bin]$ ./createuser -h localhost -p 5432 -d -A -P -e root
Enter password for new role: root
Enter it again: root
Shall the new role be allowed to create more new roles? (y/n) y
使用psql
[postgres@rhel4 bin]$ ./psql -d mydb -U root
mydb=# help
You are using psql, the command-line interface to PostgreSQL.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
mydb=# \q
*在psql中若需要使用中文,先发送:
mydb=# set client_encoding to 'utf-8';
配置数据库自启动脚本(root)
[postgres@rhel4 bin]$ su - root
[root@rhel4 ~]# cd /etc/rc.d/init.d
[root@rhel4 init.d]# cp /soft/postgresql-8.4.2/contrib/start-scripts/linux postgresql
[root@rhel4 init.d]# chmod +x postgresql
[root@rhel4 init.d]# vi postgresql
prefix=/usr/local/pgsql
PGDATA="/usr/local/pgsql/data"
PGUSER=postgres
PGLOG="/var/log/pgsql.log"
[root@rhel4 init.d]# chkconfig --add postgresql
重启数据库
[root@rhel4 init.d]# /etc/rc.d/init.d/postgresql restart
=== PostgreSQL配置完成 ===
三、PHP安装配置
安装libiconv-1.13.1.tar.tar库
[root@rhel4 soft]# tar xzvf libiconv-1.13.1.tar.tar
[root@rhel4 soft]# cd libiconv-1.13.1
[root@rhel4 libiconv-1.13.1]# ./configure --prefix=/usr/local/libiconv && make && make install
安装freetype-2.3.11.tar.gz库
[root@rhel4 soft]# tar zxvf freetype-2.3.11.tar.gz
[root@rhel4 soft]# cd freetype-2.3.11
[root@rhel4 freetype-2.3.11]# ./configure && make && make install
安装libpng-1.2.40.tar.gz库
[root@rhel4 soft]# tar zxvf libpng-1.2.40.tar.gz
[root@rhel4 soft]# cd libpng-1.2.40
[root@rhel4 libpng-1.2.40]# cp scripts/makefile.linux makefile
[root@rhel4 libpng-1.2.40]# make && make install
安装jpegsrc.v6b.tar.gz库
[root@rhel4 soft]# tar zxvf jpegsrc.v6b.tar.gz
[root@rhel4 soft]# cd jpeg-6b
[root@rhel4 jpeg-6b]# mkdir -pv /usr/local/jpeg/{,bin,lib,include,man/man1,man1}
[root@rhel4 jpeg-6b]# ./configure --prefix=/usr/local/jpeg --enable-shared --enable-static && make && make install && make install-lib
安装libxml2-2.7.6.tar.gz库
[root@rhel4 soft]# tar zxvf libxml2-2.7.6.tar.gz
[root@rhel4 soft]# cd libxml2-2.7.6
[root@rhel4 libxml2-2.7.6]# ./configure && make && make install
安装libmcrypt-2.5.8.tar.gz库
[root@rhel4 soft]# tar zxvf libmcrypt-2.5.8.tar.gz
[root@rhel4 soft]# cd libmcrypt-2.5.8
[root@rhel4 libmcrypt-2.5.8]# ./configure && make && make install
[root@rhel4 libmcrypt-2.5.8]# /sbin/ldconfig
[root@rhel4 libmcrypt-2.5.8]# cd libltdl
[root@rhel4 libltdl]# ./configure --enable-ltdl-install && make && make install
安装mhash-0.9.9.9.tar.gz库
[root@rhel4 soft]# tar zxvf mhash-0.9.9.9.tar.gz
[root@rhel4 soft]# cd mhash-0.9.9.9
[root@rhel4 mhash-0.9.9.9]# ./configure && make && make install
安装mcrypt-2.6.8.tar.gz库
[root@rhel4 soft]# tar zxvf mcrypt-2.6.8.tar.gz
[root@rhel4 soft]# cd mcrypt-2.6.8
[root@rhel4 mcrypt-2.6.8]# cp /usr/local/lib/libmcrypt*.* /usr/lib
[root@rhel4 mcrypt-2.6.8]# ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
[root@rhel4 mcrypt-2.6.8]# ./configure && make && make install
安装curl-7.19.6.tar.tar库
[root@rhel4 soft]# tar xzvf curl-7.19.6.tar.tar
[root@rhel4 soft]# cd curl-7.19.6
[root@rhel4 curl-7.19.6]# ./configure && make && make install
安装zlib-1.2.3.tar.gz库
[root@rhel4 soft]# tar zxvf zlib-1.2.3.tar.gz
[root@rhel4 soft]# cd zlib/1.2.3/
[root@rhel4 1.2.3]# ./configure && make && make install
安装gd-2.0.33.tar.tar库
[root@rhel4 soft]# tar xzvf gd-2.0.33.tar.tar
[root@rhel4 soft]# cd gd-2.0.33
[root@rhel4 gd-2.0.33]# ./configure --with-libiconv-prefix --with-png --with-freetype --with-jpeg-dir=/usr/local/jpeg/
[root@rhel4 gd-2.0.33]# make && make install
安装apache
[root@rhel4 soft]# tar zxvf httpd-2.2.14.tar.gz
[root@rhel4 soft]# cd httpd-2.2.14
[root@rhel4 httpd-2.2.14]# ./configure --prefix=/usr/local/apache --enable-so && make && make install
设置linux启动时同时启动apache服务
[root@rhel4 httpd-2.2.14]# echo "/usr/local/apache/bin/apachectl start" >> /etc/rc.d/rc.local
安装imap
[root@rhel4 soft]# tar -zxvf imap-2007e.tar.gz
[root@rhel4 soft]# mv imap-2007e /usr/local/
[root@rhel4 soft]# cd /usr/local/imap-2007e
[root@rhel4 imap-2007e]# make lr5 SSLTYPE=unix.nopwd
[root@rhel4 imap-2007e]# mkdir include
[root@rhel4 imap-2007e]# mkdir lib
[root@rhel4 imap-2007e]# cp c-client/*.h include/
[root@rhel4 imap-2007e]# cp c-client/*.c lib/
[root@rhel4 imap-2007e]# cp c-client/c-client.a lib/libc-client.a
安装php-5.2.11.tar.gz
[root@rhel4 soft]# tar zxvf php-5.2.11.tar.gz
[root@rhel4 soft]# cd php-5.2.11
[root@rhel4 php-5.2.11]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-jpeg-dir=/usr/local/jpeg/ --with-imap=/usr/local/imap-2007e --with-imap-ssl --with-libxml-dir --with-curl --with-gd --with-zlib-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-ttf --with-mcrypt --with-mhash --with-libmcrypt --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pgsql=/usr/local/pgsql/ --enable-track-vars --enable-ftp --enable-soap --enable-mbstring=all
[root@rhel4 php-5.2.11]# make && make install
[root@rhel4 php-5.2.11]# cp php.ini-dist /usr/local/php/lib/php.ini
编辑/usr/local/php/lib/php.ini文件
[root@rhel4 php-5.2.11]# vi /usr/local/php/lib/php.ini
将“ ;default_charset = "iso-8859-1" ”改为“ default_charset = "utf-8" ”;将“ ;session.save_path = "/tmp" ”改为“ session.save_path = "/tmp" ”。
编辑apache配置文件httpd.conf
[root@rhel4 soft]# vi /usr/local/apache/conf/httpd.conf
要改的有如下几处:
找到LoadModule php5_module modules/libphp5.so,将前面的#号去掉;
找到#AddType application/x-gzip .gz .tgz
在下面加二行
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
还有找到
DirectoryIndex index.html
改为
DirectoryIndex index.html index.php index.htm index.phtml
找到DocumentRoot "/usr/local/apache/htdocs" 和
把/usr/local/apache/htdocs改为你存放网页文件的路径,比如DocumentRoot "/www"和
在/www目录下建立php测试文件如下:
[root@rhel4 soft]# mkdir /www
[root@rhel4 soft]# cd /www
[root@rhel4 www]# vi test.php
phpinfo();
?>
启动Apache
[root@rhel4 www]# /usr/local/apache/bin/apachectl start
然后在浏览器中输入:将会看见php和系统的相关信息。
阅读(1817) | 评论(0) | 转发(0) |