当前位置:网站首页>大部分PHP程序员,都搞不懂如何安全代码部署
大部分PHP程序员,都搞不懂如何安全代码部署
2022-07-29 05:19:00 【廖圣平】

如果你的网站还是以777 作为权限,那么你的服务器将开放给任何人,任何人可以在目录中执行脚本。
看过一些别人的外包项目,竟然整个项目的权限设置为777 ,其实是非常可怕的,黑客可以上传文件到任意目录,并执行该文件。
这样做是可怕的,一些程序员可以利用一些工具扫描漏洞,像很多php程序员在简历中说,破解过php,植入后门等,都是因为前期的php程序员的门槛低,对于安全意识薄弱,造成很多网站都可以 get Shell。
如何正确的设置php 运行目录?我这边总结一些方法,分享给大家。
设置目录的所有者
php程序一般是给nginx 或者 apche 调用的,所以系统会有一个 www(视情况而,有些是www-data) 的用户和用户组
sudo chown -R www-data:www-data /path/to/your/laravel/root/directory
但是我们如果使用 php artisan 命令,或者什么时候你想要用FTP传输文件到服务器,这样设置权限会报错的,因为这个目录的权限是属于www-data:www-data 用户和用户组的。你应该要添加到web 的用户组中。(ubantu叫ubantu,vagrant叫vagrant)
sudo usermod -a -G www-data ubuntu
设置权限
首先给自己的程序还原一下最初
给php框架所需要的读写权限。
Laravel:
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
如果是Tp框架:
sudo chgrp -R www-data runtime
sudo chmod -R ug+rwx runtime
这样你的php框架就相对安全了。
上传权限
我们的小体量的程序有些需要上传图片或文件到服务器(但是推荐上传到OSS或者七牛等第三方储存方案。)
防止上传的程序被恶意攻击程序,我们可以在Nginx或者Apache 拒绝运行php脚本
Nginx:
location ~ ^/(uploads|assets)/.*\.(php|php5|jsp)$ {
deny all;
}
Apache:
RewriteEngine on RewriteCond % !^$
RewriteRule uploads/(.*).(php)$ – [F]
这般如此,你的程序就加上了一层厚厚的盾了
边栏推荐
- 基础爬虫实战案例之获取游戏商品数据
- Detailed explanation of typical application code of C language array - master enters by mistake (step-by-step code explanation)
- [C language series] - print prime numbers between 100 and 200
- Masscan tutorial
- Build msys2 environment with win10
- Li Kou 994: rotten orange (BFS)
- [JS question solution] questions 1-10 in JS of niuke.com
- The function of using wechat applet to scan code to log in to the PC web of the system
- Camunda 1. Camunda workflow - Introduction
- rem与px与em异同点
猜你喜欢

HCIA-R&S自用笔记(26)PPP

Database operation day 6
![[typescript] type reduction (including type protection) and type predicate in typescript](/img/74/52fe769ed3850e01d97cb9fefb7373.png)
[typescript] type reduction (including type protection) and type predicate in typescript

QFrame类学习笔记

Wechat applet - screen height

Hcia-r & s self use notes (25) NAT technical background, NAT type and configuration

Masscan tutorial

Question swiping Madness - leetcode's sword finger offer58 - ii Detailed explanation of left rotation string

HCIA-R&S自用笔记(25)NAT技术背景、NAT类型及配置

QPalette学习笔记
随机推荐
[C language series] - storage of deep anatomical data in memory (I) opening of summer vacation
移动端-flex项目属性
[C language series] - string + partial escape character explanation + annotation tips
2022 mathematical modeling competition summer training lecture - optimization method: goal planning
Selection options of uniapp components (such as package selection)
解决表单校验提示信息不消失问题以及赋值不生效问题
Hcia-r & s self use notes (25) NAT technical background, NAT type and configuration
What is wapiti and how to use it
Do students in the science class really understand the future career planning?
Selenium实战案例之爬取js加密数据
Clickhouse learning (VI) grammar optimization
[C language series] - constants and variables that confuse students
Detailed explanation of typical application code of C language array - master enters by mistake (step-by-step code explanation)
uniapp组件之tab选项卡滑动切换
OpenAtom OpenHarmony分论坛圆满举办,生态与产业发展迈向新征程
微信小程序更改属性值-setData-双向绑定-model
Question swiping Madness - leetcode's sword finger offer58 - ii Detailed explanation of left rotation string
Thrift安装手册
·Let's introduce ourselves to the way of programming·
shell基本操作(上)