欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

CentOS 5.5使用yum来安装LAMP(php运行环境)

程序员文章站 2023-11-09 16:24:16
1. 换源,sohu的相当好用。 1.1备份centos-base.repo cd /etc/yum.repos.d/ cp centos-base.repo centos...
1. 换源,sohu的相当好用。
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.
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文件,将以下内容写入,然后保存。
<?
phpinfo();
?>
4.2 防火墙配置
a.添加.允许访问端口{21: ftp, 80: http}.
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 80 -j accept
b.关闭防火墙{不推荐}.
service iptables stop
c.重置加载防火墙
service iptables restart
4.3然后在客户端浏览器里打开http://serverip/test.php,若能成功显示,则表示安装成功。
至此,安装完毕。感慨,yum真是太好用了。