当前位置:网站首页>大部分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]
这般如此,你的程序就加上了一层厚厚的盾了
边栏推荐
- What is sqlmap and how to use it
- 实现table某个单元格背景色设置
- 【TypeScript】深入学习TypeScript对象类型
- Provincial and urban three-level linkage (simple and perfect)
- What is nmap and how to use it
- [electronic circuit] how to select ADC chip
- Hcia-r & s self use notes (27) comprehensive experiment
- 365 day challenge leetcode1000 question - day 036 binary tree pruning + subarray and sorted interval sum + delete the shortest subarray to order the remaining arrays
- Talking about Servlet
- AR虚拟增强与现实
猜你喜欢
Wechat applet - component parameter transmission, state management
微信小程序-组件传参,状态管理
WIN10 编译ffmpeg(包含ffplay)
Sqlmap是什么以及使用方法
[typescript] learn typescript object types in depth
Playwright实战案例之爬取js加密数据
Detailed installation and use tutorial of MySQL (nanny installation with pictures and texts)
DAY6:利用 PHP 编写登陆页面
365 day challenge leetcode 1000 questions - day 035 one question per day + two point search 13
Summary of knowledge points related to forms and forms
随机推荐
第三课threejs全景预览房间案例
Wechat applet - component parameter transmission, state management
公众号不支持markdown格式文件编写怎么办?
shell基本操作(上)
shell基本操作(下)
The function of using wechat applet to scan code to log in to the PC web of the system
Day 3
[C language series] - storage of deep anatomical data in memory (II) - floating point type
HCIA-R&S自用笔记(26)PPP
ClickHouse学习(十一)clickhouseAPI操作
uniapp页面标题显示效果
Clickhouse learning (x) monitoring operation indicators
Wapiti是什么以及使用教程
移动端-flex项目属性
Summary of the first week
Masscan使用教程.
Clickhouse learning (VII) table query optimization
Selection options of uniapp components (such as package selection)
相对定位和绝对定位
解决表单校验提示信息不消失问题以及赋值不生效问题