yum网络源使用与lamp mysql应用

1.如何使用网络yum源?
2.使用rpm包搭建lamp并能够将数据库内容显示在网页上.

1.步骤:
常见yum源地址有:
网易yum源(http://mirrors.163.com)
http://mirrors.163.com/.help/CentOS-Base-163.repo
搜狐yum 源(http://mirrors.sohu.com)
http://mirrors.sohu.com/help/CentOS-Base-sohu.repo
中国科技大学yum 源 (http://centos.ustc.edu.cn)
http://centos.ustc.edu.cn/CentOS-Base.repo.5
上海交通大学(http://ftp.sjtu.edu.cn/centos)
SHLUG(http://www.shlug.org/)
泰安移动(http://mirrors.ta139.com/)
http://mirrors.ta139.com/CentOS-Base.repo.ta139
rpmforge yum源(http://dag.wieers.com/rpm/)


打开yum配置文件 路径为 /etc/yum.repos.d/rhel-debuginfo.repo
内容如下:
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///media/Server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
更改后为:
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=http://mirrors.163.com/.help/CentOS-Base-163.repo
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

以163的源为例,保存退出,现在即可使用网络yum源了.

2.步骤:
安装所需包有:httpd php php-mysql mysql mysql-server
安装流程:
1. 关闭selinx安装gcc配置yum
 setenforce 0
  mount /dev/cdrom /mnt
vim /etc/yum.repos.d/rhel-debuginfo.repo
内容如下:
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///mnt/Server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

  yum install gcc* -y
2.安装httpd
yum install httpd -y
编辑一个静态网页
echo hello! > /var/www/html/index.html
启动httpd
service httpd restart
测试结果:
elinks http://192.168.18.124
出现hello!界面即可
3.安装mysql
yum install mysql mysql-server -y
启动mysql
/etc/init.d/mysqld restart

登录mysql
mysql
show databases;

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)
use test
show tables;
Empty set (0.00 sec)
create table gya (name char(15), gender char(2), address char(50), description char(100));
show tables;
+----------------+
| Tables_in_test |
+----------------+
| gya            |
+----------------+
1 row in set (0.00 sec)
desc gya;
+-------------+-----------+------+-----+---------+-------+
| Field       | Type      | Null | Key | Default | Extra |
+-------------+-----------+------+-----+---------+-------+
| name        | char(15)  | YES  |     | NULL    |       |
| gender      | char(2)   | YES  |     | NULL    |       |
| address     | char(50)  | YES  |     | NULL    |       |
| description | char(100) | YES  |     | NULL    |       |
+-------------+-----------+------+-----+---------+-------+
4 rows in set (0.00 sec)
insert into gya values ('wb', 'F', 'bj', 'dananhai'),('wh', 'M', 'bd', 'xiaonvren');
select * from gya;
+------+--------+---------+-------------+
| name | gender | address | description |
+------+--------+---------+-------------+
| wb   | F      | bj      | dananhai    |
| wh   | M      | bd      | xiaonvren   |
+------+--------+---------+-------------+
2 rows in set (0.00 sec)


4.安装php
yum install php php-mysql -y
编辑php 路径/var/www/html/下
vim mysql.php
内容如下:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
        {
        die('Could not connect:' . mysql_error());
        }

mysql_select_db("test", $con);

$result = mysql_query("SELECT * FROM gya");

while($row = mysql_fetch_array($result))
        {
        echo $row['name'] . " " . $row['gender'] , $row['address'] , $row['description'];
        echo "<br />";
        }
mysql_close($con);
?>



重启httpd
service httpd restart
测试结果:
elinks http://192.168.18.124/mysql.php


 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章