您的位置:首页 > 运维架构 > Nginx

使用树莓派(raspberry pi)搭建网站(nginx+php+mysql+ddclient)

2013-07-19 22:57 971 查看
标签: 树莓派 raspberrypi php 网站 mysql 分类: Linux技术

最近在研究学习PHP,有时候想随时就学习,所以就决定搭建一个网站,随时可以进行学习,因为要24小时在线,要低功耗和安静,所以选择了树莓派!我们开始吧(nginx+php+mysql)

1.安装网站系统

sudo apt-get install nginx php5-common php5-fpm php-apc php5-mysql php5-gd mysql-server

2、修改nginx配置文件

sudo vi /etc/nginx/sites-enabled/default

--------------------------------------------------------------------------------

把其中的:

代码:

location / {

root /var/www;

index index.html index.htm;

}

改为:

代码:

location / {

root /var/www/nginx-default;

index index.php index.html index.htm;

}

----------------------------------------------------------------------------------

其中的:

代码:

#location ~ \.php$ {

# fastcgi_pass 127.0.0.1:9000;

# fastcgi_index index.php;

# include fastcgi_params;

#}

改为:

location ~ \.php$ {

# fastcgi_split_path_info ^(.+\.php)(/.+)$;

# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

#

# # With php5-cgi alone:

# fastcgi_pass 127.0.0.1:9000;

fastcgi_pass unix:/var/run/php5-fpm.sock;

fastcgi_param SCRIPT_FILENAME /usr/share/nginx/www/nginx-default$fastcgi_script_name;

# # With php5-fpm:

# fastcgi_pass unix:/var/run/php5-fpm.sock;

fastcgi_index index.php;

include fastcgi_params;

}

3.测试

sudo vi /var/www/nginx-default/index.php

<?PHP

phpinfo();

?>
http://IP/index.php
4.由于我们用的是树莓派,所以要优化一下部分的性能

对mysql的调优,打开配置文件/etc/mysql/my.cnf修改以下几处。

[mysqld]

key_buffer = 16k

max_allowed_packet = 1M

thread_stack = 64K

thread_cache_size = 4

query_cache_limit = 1M

default-storage-engine = InnoDB

优化php.ini,php-fpm,打开配置文件/etc/php5/fpm/php.ini和/etc/php5/fpm/php-fpm.conf修改以下几处。

memory_limit=16M

process.max=4

5. 为了方便调试PHP代码,打开PHP的调试

(可能不同的平台文件的位置是不同的)

vim /usr/local/php5/lib/php.ini

找到

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Error handling and logging ;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

部分。开始配置

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Error handling and logging ;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

error_reporting = E_ALL

display_errors = On

display_startup_errors = Off

log_errors = On

log_errors_max_len = 1024

ignore_repeated_errors = Off

report_memleaks = On

track_errors = On

error_log = /var/log/php_errors.log

保存退出。

/etc/init.d/apache restart

查看日志:

tail -f /var/log/php_errors.log

6.使用ddclient进行域名的映射

我是在https://www.dnsdynamic.org/这个注册的一个账号,获得是DDNS

使用命令 sudo apt-get install ddclient,中间要设置很多东西,按照提示设置(也可以随便设置,等会用我的配置)

=============================================================================

修改配置文件

pi@raspberrypi ~ $ sudo cat /etc/ddclient.conf

daemon=30 # check every 60 seconds

syslog=yes # log update msgs to syslog

mail=root # mail all msgs to root

mail-failure=root # mail failed update msgs to root

pid=/var/run/ddclient.pid # record PID in file.

ssl=yes # use ssl-support. Works with

# ssl-library

use=web, web=myip.dnsdynamic.com # get ip from server.

server=www.dnsdynamic.org # default server

login=你的用户名 # default login

password=你的密码 # default password

server=www.dnsdynamic.org, \

protocol=dyndns2 \

你的网站域名 xxxx.dnsd.me

具体的配置选项可以参考 https://www.dnsdynamic.org/api.php
==========================================================================

pi@raspberrypi ~ $ sudo cat /etc/default/ddclient

# Configuration for ddclient scripts

# generated from debconf on Tue Apr 23 22:27:01 CST 2013

#

# /etc/default/ddclient

# Set to "true" if ddclient should be run every time a new ppp connection is

# established. This might be useful, if you are using dial-on-demand.

run_ipup="false"

# Set to "true" if ddclient should run in daemon mode

# If this is changed to true, run_ipup must be set to false.

run_daemon="true"

# Set the time interval between the updates of the dynamic DNS name in seconds.

# This option only takes effect if the ddclient runs in daemon mode.

daemon_interval="30"

===========================================================================

然后在你的路由器上开启端口映射

开始享受你的网站
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐