1.为树莓派设置wifi静态ip
sudo vim /etc/dhcpcd.conf
加入
interface wlan0
inform 192.168.1.1
2.安装apache2和php
sudo apt-get install apache2
sudo apt-get install php5
3.apache默认的web目录为/var/www/html
把你写的html,php,js,css文件放入该目录
4.我主要是为了登陆树莓派设置一个静态IP,代码如下
setip.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>设置页面</title>
<link rel="stylesheet" type="text/css" href="config.css"/>
</head>
<body>
<div id="config_frame">
<p style="color:#0C5391;" id="image_logo">设置ip</p>
<form action="setip.php" method="get" id="form_control" enctype="multi-part/form-data">
<div id="login_control" style="text-align: center;" >
<input name="ip" type="text" id="ip" class="text_field" >
</div>
<br>
<br>
<br>
<div style="text-align: center;" >
<input type="submit">
</div>
<div style="text-align: center;" >
<p ><label id="log" class="label"></label></p>
</div>
</form>
</div>
</body>
</html>
setip.php
<?php
ini_set("display_errors", "On");
error_reporting(E_ALL | E_STRICT);
$arr = file("/etc/dhcpcd.conf");
//echo $arr[count($arr)-1];
$ip = $_GET['ip'];
//echo ("inform"." ".$ip);
$data="inform"." ".$ip;
$arr[count($arr)-1]=$data;
//echo $arr[count($arr)-1];
file_put_contents('/etc/dhcpcd.conf', $arr);
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="config.css"/>
</head>
<body>
<script>alert("设置成功,请重启");</script>
</body>
</html>