树莓派+nginx+php建站

树莓派+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

关于php版本的问题,php5比php7更加稳定。
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

根据提示添加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;
    }    

现在你可以使用其他电脑访问http://<你的树莓派ip>来访问树莓派了。
Now we can browse the site from other computers via "http://".
It looks like this.

4.主页

Index.
主页存放目录为/var/www/html/,删除其他文件,创建一个php文件。
The index site is in the /var/www/html/,you can remove other documents and creat index.php.


现在访问树莓派的ip就能看到php的信息了。
Now go ahead to http:// or just input your raspberry ip in the adress in the browse.
Enjoy!

你可能感兴趣的:(树莓派+nginx+php建站)