当前位置: 主页 > 日志 > Linux >

修改CentOS的yum源及安装配置PHP+MySQL环境

转自:http://www.cnblogs.com/integer/archive/2011/05/13/2045105.html

 

1. 换源,在这里我们使用搜狐的镜像源。 

 

1.1 备份CentOS-Base.repo 
cd /etc/yum.repos.d/ 
cp CentOS-Base.repo CentOS-Base.repo.bak 
 
1.2 替换源
用vi打开CentOS-Base.repo,并将内容清空,然后将下面的内容复制进去,并保存。 
# CentOS-Base.repo 
# This file uses a new mirrorlist system developed by Lance Davis for CentOS. 
# The mirror system uses the connecting IP address of the client and the 
# update status of each mirror to pick mirrors that are updated to and 
# geographically close to the client. You should use this for CentOS updates 
# unless you are manually picking other mirrors. 
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead. 
[base] 
name=CentOS-$releasever - Base 
baseurl=http://mirrors.sohu.com/centos/$releasever/os/$basearch/ 
gpgcheck=1 
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5 
#released updates 
[updates] 
name=CentOS-$releasever - Updates 
baseurl=http://mirrors.sohu.com/centos/$releasever/updates/$basearch/ 
gpgcheck=1 
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5 
#packages used/produced in the build but not released 
[addons] 
name=CentOS-$releasever - Addons 
baseurl=http://mirrors.sohu.com/centos/$releasever/addons/$basearch/ 
gpgcheck=1 
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5 
#additional packages that may be useful 
[extras] 
name=CentOS-$releasever - Extras 
baseurl=http://mirrors.sohu.com/centos/$releasever/extras/$basearch/ 
gpgcheck=1 
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5 
#additional packages that extend functionality of existing packages 
[centosplus] 
name=CentOS-$releasever - Plus 
baseurl=http://mirrors.sohu.com/centos/$releasever/centosplus/$basearch/ 
gpgcheck=1 
enabled=0 
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-5
 
1.3 更新一下 
yum -y update
 
2. 用yum升级安装Apache, Mysql, PHP.
Centos默认已安装相应的环境,但是版本可能达不到相关的要求。 
 
A. 安装部分
 
2.1 安装Apache 
yum install httpd httpd-devel
安装完成后,用/etc/init.d/httpd start 启动apache
设为开机启动:chkconfig httpd on
 
2.2 安装mysql 
 
2.2.1 yum install mysql mysql-server mysql-devel 
同样,完成后,用/etc/init.d/mysqld start 启动mysql
 
2.2.2设置mysql密码 
mysql -u root -p (提示输入密码时,直接回车即可。)
mysql>; USE mysql; 
mysql>; UPDATE user SET Password=PASSWORD('newpassword') WHERE user='root'; 
mysql>; FLUSH PRIVILEGES; 
 
2.2.3设为开机启动 
chkconfig mysqld on
 
3. 安装php 
 
yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml 
/etc/init.d/httpd start
 
4. 测试一下 
 
4.1 在/var/www/html/新建个test.php文件,将以下内容写入,然后保存。 
<? 
phpinfo(); 
?> 
 
4.2 防火墙配置 
a.添加.允许访问端口{21: ftp, 22:ssh, 80: http}.  vi /etc/sysconfig/iptables
 
iptables -I RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 21 -j ACCEPT
iptables -I RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT 
iptables -I RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
 
b.关闭防火墙{不推荐}. 
service iptables stop 
 
c.重启iptables 
service iptables restart 
 
4.3 然后在客户端浏览器里打开http://serverip/test.php,若能成功显示,则表示安装成功。 
 
至此,安装完毕。

 

[日志信息]

该日志于 2011-08-19 22:36 由 redice 发表在 redice's Blog ,你除了可以发表评论外,还可以转载 “修改CentOS的yum源及安装配置PHP+MySQL环境” 日志到你的网站或博客,但是请保留源地址及作者信息,谢谢!!    (尊重他人劳动,你我共同努力)
   
验证(必填):   点击我更换验证码

redice's Blog  is powered by DedeCms |  Theme by Monkeii.Lee |  网站地图 |  本服务器由西安鲲之鹏网络信息技术有限公司友情提供

返回顶部