樹莓派上配置伺服器

黃思喆發表於2015-06-02

樹莓派上配置伺服器

樹莓派上配置一個簡單的伺服器,這樣可以用來放個部落格或者測試靜態檔案

用python做一個最簡單的臨時伺服器

假設我希望我的靜態伺服器根目錄在~/workspace/web下

那麼,ssh到樹莓派上,cd到該目錄下直接輸入

$ nohup python -m SimpleHTTPServer

之後就可以關閉terminal了

這個方法的劣勢是如果按CTRL+c會自動結束程式,只能直接退出terminal.

那就用這條指令:

$ nohup python -m SimpleHTTPServer &  

要結束該程式可以用jobs命令檢視程式號碼

$jobs

用fg %number來把後臺的任務喚醒到前臺,然後正常退出.

搭建一個wordpress用伺服器

前面那種也只能應急,要搭建一個靠譜的伺服器還是得用專業的.我們安個wordpress順便把nginx,php環境,mysql一起裝了 參考這篇文章和這篇文章

開始安裝:

$sudo apt-get update
$sudo apt-get install nginx php5-fpm php5-cli php5-curl php5-gd php5-mcrypt php5-mysql php5-cgi mysql-server

期間會要求輸入mysql的密碼

將/etc/nginx/sites-available/和/etc/nginx/sites-enabled/資料夾下defalt檔案刪除.新增一個叫wordpress的檔案

$sudo touch wordpress
$sudo chmod ugo+w wordpress

檔案內容如下:

# Upstream to abstract backend connection(s) for php
upstream php {
server unix:/var/run/php5-fpm.sock;
}

server {
listen 8001;
server_name _;

## Your only path reference.
root /srv/www/wordpress/public_html;

## Your website name goes here. Change to domain.ltd in VPS


access_log /srv/www/wordpress/logs/access.log;
error_log /srv/www/wordpress/logs/error.log;

## This should be in your http block and if it is, it's not needed here.
index index.php;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location / {
# This is cool because no php is touched for static content
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass php;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}

下載wordpress

sudo mkdir -p /srv/www/wordpress/logs/
sudo mkdir -p /srv/www/wordpress/public_html
cd /srv/www/wordpress/public_html
sudo wget https://cn.wordpress.org/wordpress-4.2.2-zh_CN.tar.gz
sudo tar xzvf latest.tar.gz
sudo mv wordpress/* .

設定資料庫:

$mysql -u root -p
mysql> CREATE DATABASE wordpress;
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"localhost"IDENTIFIED BY "raspi";
mysql> FLUSH PRIVILEGES;
mysql> EXIT

將/srv/www/wordpress/public_html目錄下的wp-config-sample.php檔名改為wp-config.php.

sudo cp wp-config-sample.php wp-config.php

然後開啟修改其中的以下幾行

define('DB_NAME', 'wordpress');

define('DB_USER', 'wordpress');

define('DB_PASSWORD', 'raspi');

並在開頭MySQL 設定之前新增如下程式碼:

$home = 'http://'.$_SERVER['HTTP_HOST'];
$siteurl = 'http://'.$_SERVER['HTTP_HOST'];
define('WP_HOME', $home);
define('WP_SITEURL', $siteurl);

重啟nginx和php5-fpm

sudo service nginx restart
sudo service php5-fpm restart

ok,瀏覽器開啟http://你的ip:80/wp-admin/install.php就可以安裝wordpress了

注意:要讓外網可以訪問,一定要讓路由器的埠對映與小pi上設定的埠一致

相關文章