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

關(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!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容