当前位置:网站首页>大部分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]
这般如此,你的程序就加上了一层厚厚的盾了
边栏推荐
- 【TypeScript】深入学习TypeScript函数
- 常见特征工程操作
- js简单代码判断打开页面的设备是电脑PC端或手机H5端或微信端
- Win10 compiles ffmpeg (including ffplay)
- [C language series] - print prime numbers between 100 and 200
- HCIA-R&S自用笔记(27)综合实验
- 【电子电路】ADC芯片如何选型
- Wechat applet change attribute value -setdata- bidirectional binding -model
- JS deep copy - Notes
- ClickHouse学习(七)表查询优化
猜你喜欢
随机推荐
Masscan tutorial
Relationship between redrawing and reflow
HCIA-R&S自用笔记(25)NAT技术背景、NAT类型及配置
[typescript] learn typescript object types in depth
How does the MD editor of CSDN input superscripts and subscripts? The input method of formula and non formula is different
ClickHouse学习(三)表引擎
Qt设置背景图片方法
Cmu15-213 shell lab experiment record
·Let's introduce ourselves to the way of programming·
[C language series] - detailed explanation of file operation (Part 1)
shell基本操作(下)
公众号不支持markdown格式文件编写怎么办?
Build msys2 environment with win10
365 day challenge leetcode 1000 questions - day 035 one question per day + two point search 13
rem与px与em异同点
table中同一列中合并相同项
[JS question solution] questions 1-10 in JS of niuke.com
DAY13:文件上传漏洞
Question swiping Madness - leetcode's sword finger offer58 - ii Detailed explanation of left rotation string
Selenium实战案例之爬取js加密数据









