查看: 15238|回复: 0

[教程] 树莓派搭建网站服务器托管WordPress

[复制链接]
  • TA的每日心情
    开心
    2014-4-16 09:58
  • 签到天数: 4 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    发表于 2014-2-21 10:05:04 | 显示全部楼层 |阅读模式
    分享到:
    来自:发发这问答
    Raspberry Pi到手一周了,搭了个服务器,因为Raspberry Pi硬件配置不高,所有选择的是nginx+mysql+php,基本是按照如下参考网站弄的,但网站上的步骤有点问题,做了一些修改。如果你觉得自己搭服务器麻烦,也可以下载如下网站已经做好的固件,刷如sd卡,开机启动后找到树莓派的ip就可以了。
    Raspberry Pi的固件有很多,我安装的是官方的Raspbian.
    一切准备就绪后就可以开机了,开机后启动终端,输入如下代码,建议使用root权限
    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密码,下载安装好nginx和mysql后在/etc/nginx/sites-available/目录下创建文件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$ {
                    #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;
            }
    }
    然后将此文件复制到/etc/nginx/sites-sites-enabled/目录下,分别删除两个文件夹中的default文件。
    然后是下载和解压wordpress(代码已修改为下载最新中文版wordpress)
    sudo mkdir -p /srv/www/wordpress/logs/
    sudo mkdir -p /srv/www/wordpress/public_html
    cd /srv/www/wordpress/public_html
    sudo wget
    http://cn.wordpress.org/latest.tar.gz
    sudo tar xzvf latest.tar.gz
    sudo mv wordpress/* .
    设置mysql数据库(其中的raspi为wordpress数据库的密码)
    $ mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 5340 to server version: 3.23.54
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    mysql> CREATE DATABASE wordpress;
    Query OK, 1 row affected (0.00 sec)
    mysql> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"localhost"IDENTIFIED BY "raspi";
    Query OK, 0 rows affected (0.00 sec)
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.01 sec)
    mysql> EXIT
    Bye
    $
    将/srv/www/wordpress/public_html目录下的wp-config-sample.php文件名改为wp-config.php然后打开修改其中的以下几行
    define('DB_NAME', 'wordpress');
    define('DB_USER', 'wordpress');
    define('DB_PASSWORD', 'raspi');
    重启 nginx 和 php5-fpm
    sudo cp wp-config-sample.php wp-config.php
    sudo edit wp-config.php
    在浏览器中输入
    http://
    你的树莓派ip/wp-admin/install.php,就可以安装wordpress啦!
    我使用的是网通的1M ADSL,动态域名解析用的是花生壳和它提供的免费二级域名
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-3-29 09:17 , Processed in 0.101715 second(s), 15 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.