2008年6月28日 星期六

Fedora 7(Linux)下 Apache+PHP+MySQL+Subversion 開發測試環境配置過程收藏

新一篇: VI 編輯方法 文章來源

安裝Fedora 7

我是使用Fedora 7 Live在VMWare 6種安裝的,具體的安裝過程參見:http://0123.blog.163.com/blog/478831200751884210367.track

技巧:如果使用Live並且在VMWare中安裝,那麼在安裝的時候分配內存儘量的多,這樣可以加快安裝速度。安裝完後再分配給128M或者256M內存進行使用就可以了(視自己情況)。

注意:VMWare 5.5/VMWare Server 1.03以及更低的版本SCSI硬盤在Fedora 7中不被支持。建議升級到VMWare 6,如果由於其他原因不能升級的,可以把虛擬機中的SCSI硬盤換成IDE硬盤進行安裝。



關閉圖形界面

因為用於開發測試使用,所以沒有必要使用圖形環境,固將其關閉,以減少資源佔用。

編輯/etc/inittab文件:



[root@webapp ~]# cat /etc/inittab
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg,
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
#

# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault:

# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit

l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6

# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

# When our UPS tells us power has failed, assume we have a few minutes
# of power left. Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"


# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon



安裝所需軟件

裝完Fedora 7後默認已經安裝了Apache,所以我們需要安裝的是php和Mysql以及subversion:

安裝PHP

[root@webapp ~]# yum install php
Loading "installonlyn" plugin
Setting up Install Process
Parsing package install arguments
primary.sqlite.bz2 100% |=========================| 56 kB 00:44
http://fr2.rpmfind.net/linux/fedora/releases/7/Everything/i386/os/repodata/primary.sqlite.bz2: [Errno 4] Socket Error: timed out
Trying other mirror.
primary.sqlite.bz2 100% |=========================| 3.8 MB 12:26
updates 100% |=========================| 1.9 kB 00:00
primary.sqlite.bz2 100% |=========================| 770 kB 02:05
Resolving Dependencies
--> Running transaction check
---> Package php.i386 0:5.2.2-3 set to be updated
--> Processing Dependency: php-common = 5.2.2-3 for package: php
--> Processing Dependency: php-cli = 5.2.2-3 for package: php
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package php-common.i386 0:5.2.2-3 set to be updated
---> Package php-cli.i386 0:5.2.2-3 set to be updated

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
php i386 5.2.2-3 fedora 1.3 M
Installing for dependencies:
php-cli i386 5.2.2-3 fedora 2.5 M
php-common i386 5.2.2-3 fedora 205 k

Transaction Summary
=============================================================================
Install 3 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 4.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): php-cli-5.2.2-3.i3 100% |=========================| 2.5 MB 08:15
(2/3): php-common-5.2.2-3 100% |=========================| 205 kB 00:38
(3/3): php-5.2.2-3.i386.r 100% |=========================| 1.3 MB 04:44
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
Importing GPG key 0x4F2A6FD2 "Fedora Project " from /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora
Is this ok [y/N]: y
Importing GPG key 0xDB42A60E "Red Hat, Inc " from /etc/pki/rpm-gpg/RPM-GPG-KEY
Is this ok [y/N]: y
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: php-common ######################### [1/3]
Installing: php-cli ######################### [2/3]
Installing: php ######################### [3/3]

Installed: php.i386 0:5.2.2-3
Dependency Installed: php-cli.i386 0:5.2.2-3 php-common.i386 0:5.2.2-3
Complete!

安裝Mysql 5

[root@webapp ~]# yum install mysql-server
Loading "installonlyn" plugin
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package mysql-server.i386 0:5.0.37-2.fc7 set to be updated
--> Processing Dependency: libmysqlclient_r.so.15 for package: mysql-server
--> Processing Dependency: libmysqlclient.so.15 for package: mysql-server
--> Processing Dependency: libmysqlclient.so.15(libmysqlclient_15) for package: mysql-server
--> Processing Dependency: perl(DBI) for package: mysql-server
--> Processing Dependency: mysql = 5.0.37-2.fc7 for package: mysql-server
--> Processing Dependency: libmysqlclient_r.so.15(libmysqlclient_15) for package: mysql-server
--> Processing Dependency: perl-DBI for package: mysql-server
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package mysql.i386 0:5.0.37-2.fc7 set to be updated
---> Package perl-DBD-MySQL.i386 0:3.0008-1.fc7 set to be updated
---> Package perl-DBI.i386 0:1.53-2.fc7 set to be updated
---> Package mysql-libs.i386 0:5.0.37-2.fc7 set to be updated

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mysql-server i386 5.0.37-2.fc7 fedora 10 M
Installing for dependencies:
mysql i386 5.0.37-2.fc7 fedora 2.0 M
mysql-libs i386 5.0.37-2.fc7 fedora 1.5 M
perl-DBD-MySQL i386 3.0008-1.fc7 fedora 148 k
perl-DBI i386 1.53-2.fc7 fedora 611 k

Transaction Summary
=============================================================================
Install 5 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 14 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): mysql-libs-5.0.37- 100% |=========================| 0 B 00:57
http://ftp.hostrino.com/pub/fedora/linux/releases/7/Everything/i386/os/Fedora/mysql-libs-5.0.37-2.fc7.i386.rpm: [Errno 4] Socket Error: timed out
Trying other mirror.
(1/5): mysql-libs-5.0.37- 100% |=========================| 1.5 MB 06:52
(2/5): perl-DBI-1.53-2.fc 100% |=========================| 611 kB 02:17
(3/5): perl-DBD-MySQL-3.0 100% |=========================| 148 kB 00:45
(4/5): mysql-5.0.37-2.fc7 100% |=========================| 2.0 MB 07:47
(5/5): mysql-server-5.0.3 100% |=========================| 10 MB 31:09
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: mysql-libs ######################### [1/5]
Installing: perl-DBI ######################### [2/5]
Installing: mysql ######################### [3/5]
Installing: perl-DBD-MySQL ######################### [4/5]
Installing: mysql-server ######################### [5/5]

Installed: mysql-server.i386 0:5.0.37-2.fc7
Dependency Installed: mysql.i386 0:5.0.37-2.fc7 mysql-libs.i386 0:5.0.37-2.fc7 perl-DBD-MySQL.i386 0:3.0008-1.fc7 perl-DBI.i386 0:1.53-2.fc7
Complete!

安裝Subversion

[root@webapp ~]# yum install subversion
Loading "installonlyn" plugin
Setting up Install Process
Parsing package install arguments
fedora 100% |=========================| 2.1 kB 00:00
updates 100% |=========================| 1.9 kB 00:00
Resolving Dependencies
--> Running transaction check
---> Package subversion.i386 0:1.4.3-4 set to be updated
--> Processing Dependency: libneon.so.25 for package: subversion
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package neon.i386 0:0.25.5-6 set to be updated

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
subversion i386 1.4.3-4 fedora 2.3 M
Installing for dependencies:
neon i386 0.25.5-6 fedora 95 k

Transaction Summary
=============================================================================
Install 2 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 2.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): neon-0.25.5-6.i386 100% |=========================| 95 kB 00:22
(2/2): subversion-1.4.3-4 100% |=========================| 2.3 MB 07:27
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: neon ######################### [1/2]
Installing: subversion ######################### [2/2]

Installed: subversion.i386 0:1.4.3-4
Dependency Installed: neon.i386 0:0.25.5-6
Complete!

安裝php-mysql鏈接庫

[root@dev ~]# yum install php-mysql
Loading "installonlyn" plugin
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package php-mysql.i386 0:5.2.2-3 set to be updated
--> Processing Dependency: php-pdo for package: php-mysql
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package php-pdo.i386 0:5.2.2-3 set to be updated

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
php-mysql i386 5.2.2-3 fedora 78 k
Installing for dependencies:
php-pdo i386 5.2.2-3 fedora 58 k

Transaction Summary
=============================================================================
Install 2 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 136 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): php-mysql-5.2.2-3. 100% |=========================| 78 kB 00:02
(2/2): php-pdo-5.2.2-3.i3 100% |=========================| 58 kB 00:01
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: php-pdo ######################### [1/2]
Installing: php-mysql ######################### [2/2]

Installed: php-mysql.i386 0:5.2.2-3
Dependency Installed: php-pdo.i386 0:5.2.2-3
Complete!



配置mysql


編輯/etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
default-character-set=utf8

配置subversion

我的svn庫位置放在 /shanmin/svn,請根據自己保存的位置更改相應的命令

創建svn庫:svnadmin create /shanmin/svn/

編輯/shanmin/svn/conf/svnserve.conf,把匿名權限設置為none,驗證權限設置為write,並且使用passwd驗證用戶,修改完的代碼:

[root@dev conf]# cat svnserve.conf
### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository. (If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)

### Visit http://subversion.tigris.org/ for more information.

[general]
### These options control access to the repository for unauthenticated
### and authenticated users. Valid values are "write", "read",
### and "none". The sample settings below are the defaults.
anon-access = none
auth-access = write
### The password-db option controls the location of the password
### database file. Unless you specify a path starting with a /,
### the file's location is relative to the conf directory.
### Uncomment the line below to use the default password file.
password-db = passwd
### The authz-db option controls the location of the authorization
### rules for path-based access control. Unless you specify a path
### starting with a /, the file's location is relative to the conf
### directory. If you don't specify an authz-db, no path-based access
### control is done.
### Uncomment the line below to use the default authorization file.
# authz-db = authz
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa. The default realm
### is repository's uuid.
# realm = My First Repository

設置passwd文件

[root@dev conf]# cat passwd
### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.

[users]
harry = harryssecret
# sally = sallyssecret

passwd文件中,格式是 用戶名=密碼



設置自動發佈.這個是用於我們遠程提交到svn的代碼,自動的發布到apache的目錄下,這樣我們就可以把提交代碼和ftp合併成一個了(這也是我為什麼在整個安裝過程未提及FTP的原因)。

在/shanmin/svn/hooks下增加post-commit文件。(這裡我的web目錄為/var/www/html)

[root@dev hooks]# cat post-commit
#!/bin/sh

export LANG=en_US.UTF-8
/usr/bin/svn update /var/www/html

把這個文件設置成可執行文件。例如:chmod 777 post-commit



打開所需服務,關閉無用服務

根據我的習慣,我使用setup關閉和打開了幾個服務。(註:因為我把Fedora7放在VMWare裡面,所以我儘量的讓Fedora7少佔資源,把能關的服務都關掉)(從默認開始)

autofs 關閉。不使用移動存儲設備就關掉這個。

bluetooth 關閉。沒有藍牙設備,沒有任何用處。

cpuspeed 關閉。用於CPU降速的,如果CPU不支持降速就關掉這個。

httpd 打開

iptables 關閉。因為是在內網開發測試使用,所以防火牆基本上沒有什麼用途。

ip6tables 關閉。沒有使用ipv6

isdn 關閉。沒有使用ISDN

irqbalance 關閉。不在多CPU環境下,這個服務沒有什麼用處。

mysqld 打開

netfs 關閉。如果不使用網絡掛接就關掉。

yum-updatest 關閉。這個用於自動升級提醒,不進圖形界面就沒有用處。



運行Subversion服務

默認沒有給svn提供一個開啟的服務,所以我們得手動添加到rc.local文件中(其實完全可以不使用svn服務,而使用Apache。但是因為開發測試環境也在Apache下,我會影響開發,所以一直使用單獨的svn服務)。

編輯/etc/rc.local文件,加入svn服務器運行命令

[root@dev ~]# cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

svnserve -d -r /shanmin/svn



重起服務器,做最後設置和測試

把svn中的數據取到apache目錄下:

[root@dev ~]# svn checkout svn://127.0.0.1/ /var/www/html/

驗證是否正常取出

[root@dev ~]# ll /var/www/html/ -a
total 24
drwxr-xr-x 3 root root 4096 2007-06-24 17:08 .
drwxr-xr-x 6 root root 4096 2007-05-26 03:46 ..
drwxr-xr-x 6 root root 4096 2007-06-24 17:08 .svn

如果有.svn目錄證明正常取出。

配置mysql遠程管理,默認mysql的root在本機管理,簡單起見,我都是把localhost改為%

[root@dev ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.0.37 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host='%' where host='localhost' and user='root';
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql>



完成。

【下列文章您可能也有興趣】

沒有留言: