CENTOS 5 安装LAMP (亲手实践)
我的centos是在VMware虚拟机上安装的,今天用yum方法搭建起了个LAMP环境,我从网上搜了一片别人的文档,照着搭建了下,以下是我修改后的搭建文档:
1. 换源,sohu的相当好用。(注意:一定要先测试下你的centos虚拟服务器能否上网,如果不能上网那么是不能换源成功的,因为换源需要从sohu上下载源码包,如果不能上网,就看下我的另一篇
“在vmware workstation7上安装centos5.5的一些问题” 学习总结,里面有说如何使本机和虚拟服务器共享上网的方法 )
1.1备份CentOS-Base.repo
cd /etc/yum.repos.d/ (解释:将切换路径到/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.
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>; USE mysql;
mysql>; UPDATE user SET Password=PASSWORD(‘newpassword’) WHERE user=’root’;
mysql>; FLUSH PRIVILEGES;
2.2.3 允许远程登录
mysql -u root -p
Enter Password: <your new password>
mysql>GRANT ALL PRIVILEGES ON *.* TO ‘用户名’@’%’ IDENTIFIED BY ‘密码’ WITH GRANT OPTION; (用户名和密码为你以后要远程登录的用户名和密码)
完成后就能用mysql-front远程管理mysql了。
2.2.4 设为开机启动
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文件,将以下内容写入,然后保存。
<?php
phpinfo();
?>
4.2 防火墙配置
a.添加.允许访问端口{21: ftp, 80: http}.
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT (打开80端口,当然如果你的apache侦听的是8080端口,那么你就要打开8080端口,在这里我的apache侦听的是80端口)
b.关闭防火墙{不推荐}.(我本人的centos是在虚拟机上安装的,关闭防火墙对本机没什么影响,故我选择的是关闭防火墙)
service iptables stop
c.重置加载防火墙
service iptables restart
4.3然后在客户端浏览器里打开http://serverip/test.php,若能成功显示,
![](https://pic002.cnblogs.com/images/2011/305884/2011061516281025.jpg)
则表示安装成功。
最后说一下自己的心得体会:现在网上的好些资料都是copy复制原创的,但是还是希望大家自己亲自实践过再发布。。我自己也一样。。。。