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


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