標簽: 樹莓派 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"
===========================================================================
然後在你的路由器上開啟端口映射
開始享受你的網站