LINUX挂载web网站
安装
# yum install -y httpd
启动服务器
# systemctl start httpd
发布网站
默认发布网站的目录:/var/www/html
操作:把网站代码放到发布网站的目录下即可
静态页面
# vim /var/www/html/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="链家.css">
</head>
<body>
<div>页面内容</div>
</body>
</html>
测试访问
浏览器输入地址: http://192.168.26.160
下载功能
默认处于开启状态
# mkdir /var/www/html/download
# touch /var/www/html/download/a.txt
# touch /var/www/html/download/a.txt
浏览器测试访问
浏览器输入地址: http://192.168.26.160/download
#yum install php mysql-server php-mysqlnd -y
# systemctl restart httpd mysqld
# vim /var/www/html/index.php
<?php
phpinfo();
?>
浏览器测试: http://192.168.26.160/index.php
数据库操作:
1.设置root密码
# mysqladmin -uroot password '123'
2.进入数据库创建库和表并且插入数据
# mysql -uroot -p123
> show databases;
> create database grade2405;
> use grade2405;
> create table student(id int,name varchar(10),age int);
> insert into student set id=1,name="lilie",age=27;
> insert into student set id=2,name="lili",age=26;
> select * from student;
> exit
编写php的网站代码:
# vim index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="链家.css">
</head>
<body>
<div>页面内容</div>
<?php
$servername = "localhost";
$username = "root";
$password = "123";
$dbname = "grade2405";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
echo "连接成功";
echo "<br>";
$sql = "SELECT id, name, age FROM student";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - 名字: " . $row["name"]. " " . $row["age"]. "<br>";
}
} else {
echo "0 结果";
}
$conn->close();
?>
</body>
</html>
浏览器测试:
http://192.168.26.160/index.php