树莓派 搭建一个nginx+php+mysql+dnspod动态解析

这次要搭建一个nginx+php+mysql+dnspod动态解析

有路由器的么直接去路由器管理界面把树莓的mac绑定下,再映射这样会方便很多,不用担心ip变掉。

首先sudo su获得root权限后操作会方便很多

  1. apt-get update

  1. apt-get install nginx php5-fpm php5-cli php5-curl php5-gd php5-mcrypt php5-mysql php5-cgi mysql-server

安装期间会提示叫你输入数据库密码(这必须要记住..)

  • 环境配置

在root权限命令行输入命令

  1. nano /etc/nginx/nginx.conf

对照修改如下
开头部分

  1. user www-data;
  2. worker_processes 1;   修改这里
  3. pid /var/run/nginx.pid;
  4. events {
  5. worker_connections 64; 修改这里
  6. # multi_accept on;
  7. }

继续向后找到gzip  去掉前面的注释 修改如下

  1. gzip on;
  2. gzip_disable “msie6”;
  3. gzip_vary on;
  4. gzip_proxied any;
  5. gzip_comp_level 6;
  6. gzip_buffers 16 8k;
  7. gzip_http_version 1.1;
  8. gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

Ctrol+O保存 Ctrl+X退出
在root权限命令行输入命令

  1. nano /etc/php5/fpm/php.ini

找到这一段

  1. ; Maximum amount of memory a script may consume (128MB) ;
  2. <a href=”http://php.net/memory-limit” target=”_blank”>http://php.net/memory-limit </a>
  3. memory_limit = 32M  修改这里

找到这一段

  1. ; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP’s
  2. ; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
  3. ; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
  4. ; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting ; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
  5. ; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
  6. ;<a href=”http://php.net/cgi.fix-pathinfo” target=”_blank”>http://php.net/cgi.fix-pathinfo </a>
  7. cgi.fix_pathinfo=1  修改这里

在root权限命令行输入命令

  1. nano /etc/php5/fpm/php-fpm.conf

找到这一段

  1. ; The maximum number of processes FPM will fork. This has been design to control
  2. ; the global number of processes when using dynamic PM within a lot of pools.
  3. ; Use it with caution.
  4. ; Note: A value of 0 indicates no limit
  5. Default Value: 0 process.max = 4  修改这里

接着改nginx

  1. nano /etc/nginx/sites-enabled/default

找到这里 修改如下

  1. # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
  2. ##
  3. server {
  4. listen   80; ## listen for ipv4; this line is default and implied
  5. #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6root /home/pi/www;

#建议放在此文件夹内,以后管理更加方便

  1. # index index.html index.htm;
  2. index index.php index.html index.htm;
  3. root /home/pi/wwwroot;
  4. index index.html index.htm;
  5. # Make site accessible from http://localhost/
  6. server_name localhost;

在这句后面增加以下内容

  1.  if (!-e $request_filename) {
  2.     rewrite ^(.*)$ /index.php$1 last;
  3. }

找到这句
location ~ \.php$ {
连同后续内容修改如下

  1.    location ~ .*\.php(\/.*)*$
  2. {
  3. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  4.        # NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
  5.        # With php5-cgi alone:
  6.        #fastcgi_pass 127.0.0.1:9000;
  7.       With php5-fpm:fastcgi_pass unix:/var/run/php5-fpm.sock;
  8.       fastcgi_index index.php;
  9.       include fastcgi_params;
  10. }

完成之后重新加载服务

  1. service nginx reload
  2. service php5-fpm reload
  3. service mysql reload

接下来安装phpmyadmin

  1. mkdir /home/pi/wwwroot
  2. wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.5.7/phpMyAdmin-3.5.7-all-languages.zip
  3. punzip  phpMyAdmin-3.5.7-all-languages.zip

最后给文件夹权限

  1. chown www-data:www-data /home/pi/wwwroot -R
  2. chmod 755 /home/pi/wwwroot -R

最后是dnspod的设置

https://gist.github.com/chuangbo/833369

这里已有源代码
需要修改的地方如下

  1. params = dict(
  2. login_email=”email”, # dnspod的邮箱
  3. login_password=”password”, # 你的密码
  4. format=”json”,
  5. domain_id=100, #domain_id http://geekpi.cn/dnspod 域名编号去左边的连接获取
  6. record_id=100, # record_id 记录id同上,子域名前面的编号
  7. sub_domain=”www”, # 你想要解析的子域名
  8. record_line=”默认”,
  9. )

保存为dnspod.py
然后输入 nohup python main.py &
就已经在后台运行了按ctrl+c也不会退出,只有用kill才能删除进程

声明:本文采用 BY-NC-SA 协议进行授权,本文链接:树莓派 搭建一个nginx+php+mysql+dnspod动态解析

发表评论