树莓派搭建wordpress站点 (nginx)

参考: http://www.guokr.com/post/332043/

安装 Nginx php Mysql

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

安装时会提示设置mysql的密码

创建 /etc/nginx/site-available/wordpress

$ cd /etc/nginx/sites-available/
$ sudo vim wordpress

在wordpress中输入一下内容

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

server {

        ## Your only path reference.
        root /srv/www/wordpress/public_html;
        listen          80;
        ## Your website name goes here. Change to domain.ltd in VPS
        server_name     _;

        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$ {
                include snippets/fastcgi-php.conf;

                # With php5-cgi alone:
                #fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass php;
        }
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
}                                  

然后做一个软连接,并删除default:

$ cd /etc/nginx/sites-enabled/
$ sudo ln -s /etc/nginx/sites-available/wordpress wordpress
$ sudo rm default

设置mysql数据库

$ 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

上面的操作创建了名字为“wordpress”的数据库,密码为“raspi”。

下载安装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.4-zh_CN.tar.gz
sudo tar xzf wordpress-4.4-zh_CN.tar.gz
sudo cp wordpress/* .

创建wp-config.php

$ cd /srv/www/wordpress/public_html/
$ sudo mv wp-config-sample.php wp-config.php
$ sudo vim wp-config.php

修改wp-config.php中的如下内容:

define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpress');
define('DB_PASSWORD', 'raspi');

大功告成

然后在浏览器输入 http://树莓派IP地址/wp-admin/install.php 验证是否成功

进一步改动

可以将mysql改成sqlite(降低开销) http://www.tuicool.com/articles/fuiyQb
申请免费域名等。

Reset password

WordPress use the bcrypt to save the users password in database. I use sqlite3 database.
How to Generate bcrypt password?
I am using online bcrypt generator. You can search in google/duckduckgo , will find many online generator.
http://bcrypthashgenerator.apphb.com/
I generated ‘password123’ its bcrypt formate is
$2a$10$UvclXkN3qwFqEj7nT2uGBedStIdt4rshca5JSzsj9bygk3U/IA7F6
Reset password to ‘password123’:

# cd /srv/www/wordpress/public_html/wp-content/database
# ls -a
# sqlite3 .ht.sqlite
# update wp_users set user_pass="$2a$10$n0Drn.0vlhSswKAu92uG1OZEV3b2M9nT10koa.FFmwgxt2ECr7f.i" where ID=yourId;

Now, you can login using ‘password123’

Get a global URL

You can use ngrok to get a global url for your local service.
https://ngrok.fengqi.me/index.html

你可能感兴趣的:(树莓派搭建wordpress站点 (nginx))