当前位置:网站首页>大部分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]
这般如此,你的程序就加上了一层厚厚的盾了
边栏推荐
- JS simple code determines whether the device that opens the page is the PC end of the computer, the H5 end of the mobile phone, or the wechat end
- href与src的区别
- ClickHouse学习(七)表查询优化
- Pyqt5: Chapter 1, Section 1: creating a user interface using QT components - Introduction
- Day 1
- Installation steps and environment configuration of vs Code
- Solve the problem that the prompt information of form verification does not disappear and the assignment does not take effect
- 2022 mathematical modeling competition summer training lecture - optimization method: goal planning
- Dynamic sorting of DOM object element blocks in applets
- 弹性盒子flex
猜你喜欢
About local variables
Clickhouse learning (VII) table query optimization
DAY13:文件上传漏洞
Wechat applet - component parameter transmission, state management
Hcia-r & s self use notes (27) comprehensive experiment
On Paradigm
Question swiping Madness - leetcode's sword finger offer58 - ii Detailed explanation of left rotation string
B - identify floating point constant problems
虚拟增强与现实第二篇 (我是一只火鸟)
Selenium实战案例之爬取js加密数据
随机推荐
365 day challenge leetcode1000 question - day 036 binary tree pruning + subarray and sorted interval sum + delete the shortest subarray to order the remaining arrays
Database operation day 6
Related knowledge of elastic box
Day 5
Hcia-r & s self use notes (26) PPP
nmap是什么以及使用教程
[typescript] type reduction (including type protection) and type predicate in typescript
Day 3
DAY6:利用 PHP 编写文件上传页面
[C language series] - storage of deep anatomical data in memory (I) opening of summer vacation
Solve the problem that the prompt information of form verification does not disappear and the assignment does not take effect
ClickHouse学习(二)ClickHouse单机安装
Relationship between redrawing and reflow
365 day challenge leetcode 1000 questions - day 035 one question per day + two point search 13
HCIA-R&S自用笔记(26)PPP
ClickHouse学习(十一)clickhouseAPI操作
Clickhouse learning (VIII) materialized view
DAY15(DAY16拓展):文件包含漏洞
Win10 compiles ffmpeg (including ffplay)
Wechat applet video upload component is directly uploaded to Alibaba cloud OSS