树莓 php mysql,树莓搭建Nginx+PHP7.0+mysql服务器

累的一批,试了3个小时才搭建出来,想想还是先记录下来,一是为了警醒后人,二是为了防止我忘记emmmmm…

相信搜到我这文章的朋友大多是因为树莓诡异的PHP5装不上,php+nginx配置不上的原因找来的,废话不多说,我就把这3小时的工作的经验分享给大家

如有问题,加我QQ 393720616 一起讨论共同进步!

by zhazhafang

一、软件环境搭建

安装Nginx

sudo apt-get install nginx

如提醒安装失败,90%是端口占用,如之前装了apache2请先删除此软件再进行其他操作。

sudo apt-get remove apache2

安装PHP+MYSQL

sudo apt-get install php7.0

sudo apt-get install php7.0-mysql

注:网络上的PHP5已经无法安装,这里要将PHP5换做php7.0

二、设置更改   (重点)

sudo nano /etc/nginx/sites-available/default

打开后整个文件更改为:

##

# You should look at the following URL's in order to grasp a solid understanding

# of Nginx configuration files in order to fully unleash the power of Nginx.

# https://www.nginx.com/resources/wiki/start/

# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/

# https://wiki.debian.org/Nginx/DirectoryStructure

#

# In most cases, administrators will remove this file from sites-enabled/ and

# leave it as reference inside of sites-available where it will continue to be

# updated by the nginx packaging team.

#

# This file will automatically load configuration files provided by other

# applications, such as Drupal or WordPress. These applications will be made

# available underneath a path with that package name, such as /drupal8.

#

# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.

##

# Default server configuration

#

server {

listen 80 default_server;

listen [::]:80 default_server;

# 这里改动了,也可以写你的域名

server_name localhost;

root /var/www/php; #网页保存地址

# Load configuration files for the default server block.

include /etc/nginx/default.d/*.conf;

location / {

# 这里改动了 定义首页索引文件的名称

index index.php index.html index.htm;

}

error_page 404 /404.html;

location = /40x.html {

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

}

# 这里新加的

# PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.

# Fastcgi服务器和程序(PHP,Python)沟通的协议.

location ~ \.php$ {

fastcgi_index index.php;

fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; #这里是关键老教程没有PHP7.0这段,不能正确引导

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #防止白屏

include fastcgi_params;

}

}

# Virtual Host configuration for example.com

#

# You can move that to a different file under sites-available/ and symlink that

# to sites-enabled/ to enable it.

#

#server {

# listen 80;

# listen [::]:80;

#

# server_name example.com;

#

# root /var/www/example.com;

# index index.html;

#

# location / {

# try_files $uri $uri/ =404;

# }

#}

保存配置存档,后运行一次

sudo /etc/init.d/nginx reload

三、测试

创建PHP文件

sudo nano /var/www/php/index.php

输入:

PHP 测试

<?php  echo '

Hello World

'; ?>

存档保存。后运行:

sudo /etc/init.d/nginx stop

sudo /etc/init.d/nginx start

最后试试看你的Nginx+PHP+sqlite搭建成功了没有吧!

转载最好注明出处哟!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值