樹莓派+nginx+php建站
Setup a webpage on Raspberry by nginx and php.
1.更新軟件源
update the list of softwares
sudo apt update && sudo apt upgrade
2.安裝nginx和php
install nginx and php
sudo apt install nginx
sudo apt install php
也能使用以下命令
also,can use these commands
sudo apt install php5
關(guān)于php版本的問題,php5比php7更加穩(wěn)定。
It looks like that php5 is more stable than php7.
More information on this site: [php.net][]
[php.net]:http://php.net/manual/zh/index.php
3.配置nginx
Setup nginx.
nginx的配置文件存放在/etc/nginx/sites-available目錄下。
只需要修改該目錄下的default配置即可
The configurations of nginx are in /etc/nginx/sites-available.
Just need to edit the default to configure.
cd /etc/nginx/sites-available
sudo vim default
根據(jù)提示添加index.php,取消php配置前的注釋。
Add "index.php" to the below line and unmark the configurations of php.
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
現(xiàn)在你可以使用其他電腦訪問http://<你的樹莓派ip>來訪問樹莓派了。
Now we can browse the site from other computers via "http://<your raspberry ip>".
It looks like this.
4.主頁
Index.
主頁存放目錄為/var/www/html/,刪除其他文件,創(chuàng)建一個(gè)php文件。
The index site is in the /var/www/html/,you can remove other documents and creat index.php.
<?php
phpinfo();
?>
現(xiàn)在訪問樹莓派的ip就能看到php的信息了。
Now go ahead to http://<your raspberry ip> or just input your raspberry ip in the adress in the browse.
Enjoy!