树莓派3-搭建基于LNMP的Web服务器
概要
- LNMP,即是Linux + Nginx + Mysql + PHP的简称
- 是一套开源的Web服务器解决方案
安装
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
- 配置启动相关,是否启用压缩,缓存等,打开配置文件,/etc/nginx/nginx.conf ,配置为如下内容:
worker_processes 1;
worker_connections 256;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
- 配置访问端口,目录,PHP相关等,打开/etc/nginx/sites-available/default,配置为如下:
server {
listen 80;#Web服务端口号,大陆用户可能需要修改为81或8080等
server_name localhost;
root /home/pi/www/;
access_log /var/log/nginx/localhost.access.log;
#error_page 404 /404.html;
if (!-e $request_filename)
{
rewrite ^(.*)$ /index.php$1 last;
}
location / {
index index.html index.htm index.php default.html default.htm default.php;
}
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 1d;
}
location ~ .*\.php(\/.*)*$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
- 建立相应的目录和文件
pi@raspberrypi:~ $ cd ~
pi@raspberrypi:~ $ pwd
/home/pi
pi@raspberrypi:~ $ mkdir www
pi@raspberrypi:~ $ cd www
pi@raspberrypi:~/www $ echo "<?php echo 1; ?>" > index.php
pi@raspberrypi:~/www $ ls
index.php
pi@raspberrypi:~/www $ cat index.php
<?php echo 1; ?>
配置mysql
优化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 = MYISAM
配置PHP
配置php.ini,php-fpm,打开配置文件/etc/php5/fpm/php.ini和/etc/php5/fpm/php-fpm.conf。修改如下:
memory_limit=16M
process.max=4
nginx相关命令
sudo /usr/sbin/nginx -s start 启动
sudo /usr/sbin/nginx -s reload 重启
sudo /usr/sbin/nginx -s stop 停止
访问效果
浏览器打开http://localhost/index.php, 显示1
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号