树莓 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
    评论
树莓派(Raspberry Pi)上安装iptables(Internet Protocol Table),这个防火墙工具,通常用于Linux系统中管理网络包过滤规则,可以按照以下步骤操作: 1. **更新系统**: 首先,你需要确保树莓派的操作系统是最新版本。打开终端并运行: ``` sudo apt update && sudo apt upgrade ``` 2. **安装iptables**: 在树莓派上,iptables通常是默认已安装的,但如果不确定或需要确认版本,你可以用`apt`命令检查: ``` sudo apt list iptables ``` 如果没有安装,输入: ``` sudo apt install iptables-persistent ``` 这将安装iptables及其持久化配置功能。 3. **启用iptables服务**: 为了让iptables在系统启动时自动运行,编辑`sysvinit`下的iptable脚本文件: ``` sudo nano /etc/init.d/iptables-persistent ``` 将`exit 0`行前的注释符号`#`去掉,使其生效。然后保存并关闭文件,使用以下命令使改动生效并启动服务: ``` sudo chmod +x /etc/init.d/iptables-persistent sudo update-rc.d iptables-persistent defaults sudo service iptables-persistent start ``` 4. **查看和设置规则**: 使用以下命令打开iptables的基本配置界面: ``` sudo iptables -L ``` 可以根据需要添加、修改规则,例如阻止某些IP访问等。记得在完成操作后保存规则以便下次开机生效: ``` sudo iptables-save > /etc/iptables/rules.v4 ``` 请注意,这只是基本的iptables安装和管理过程。对于高级的网络策略,可能需要学习更详细的iptables语法或其他防火墙工具如nftables。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值