PHP中的配置至关重要,包含php.ini的配置,还有系统权限的配置,一下是我总结的一些配置

一、PHP的模块

./configure    \
--with-libdir=lib64 \
--prefix=/usr/ \
--exec-prefix=/usr \
--bindir=/usr/bin \
--sbindir=/usr/sbin \
--sysconfdir=/etc \
--datadir=/usr/share \
--includedir=/usr/include \
--libexecdir=/usr/libexec \
--localstatedir=/var \
--sharedstatedir=/usr/com \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--cache-file=../config.cache \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-iconv-dir \
--with-freetype-dir=/usr/local/lib \
--with-jpeg-dir=/usr/local/lib \
--with-png-dir=/usr/local/lib \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt=/usr/local/lib \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-opcache \
--with-pdo-mysql \
--enable-embed=shared \
--enable-debug \
--enable-dtrace

上面是一些比较常用的配置选项

[root@localhost]# php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
ereg
fetch_url
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
memcached
mhash
mongo
mysql
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
tokenizer
trace
vld
xhprof
xml
xmlreader
xmlrpc
xmlwriter
Zend OPcache
zip
zlib [Zend Modules]
Zend OPcache

我们可以通过php -m 来查看,

1、有些不需要的模块,在我们编译的时候就不要启用了

2、有些默认启用的模块,在我们编译的时候要禁用

二、防止PHP版本泄漏

可以通过expose_php来关闭

[root@localhost ~]# curl -I  192.168.1.30
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 15 Jul 2015 19:16:10 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/5.5.23
[root@localhost ~]# vim /etc/php.ini
expose_php = Off

服务器的版本信息也更改,在编译nginx之前可以将nginx修改为apapche

三、记录PHP和Nginx的日志

display_errors = Off
display_startup_errors = On
log_errors = On
error_reporting = 0
error_log = /var/log/php_errors.log

另外还要记录apache或者Nginx的访问日志,这个要在web server中配置

四、限制文件上传

web程序最不安全的就在这个地方了,用户可以上传文件,比如图片、脚本,然后再通过其他方式,对网站做一些破坏性的工作,所以上传的时候,要严格检查文件的格式

file_uploads = On
upload_tmp_dir =/data/www/tmp
upload_max_filesize = 2M
max_file_uploads = 20

 五、关闭远程资源的访问

如果这个特性被启动,将会禁用file_get_contents()、include、require中获取诸如FTP或网页内容这些远程数据

 allow_url_fopen=Off

 六、POST的限制

post_max_size=2m

 七、dos控制

最大执行时间、用于处理请求数据的最大时间、以及最大可用内存数、防止hash构造

max_execution_time = 30
max_input_time = 30
memory_limit = 40M
max_input_vars = 1000

 八、权限以及安全模式的配置

[root@localhost ~]# vim /etc/php.ini
disable_functions =exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source
open_basedir=/var/www/html/
safe_mode_exec_dir = /usr/local/bin/ #确认以Apache或www这种非root用户运行Apache。/var/www/html目录下的owner也应是非root用户:
[root@localhost ~]# chown -R apache:apache /var/www/html/ #DocumentRoot下的文件应禁止运行或创建。设置该目录下的文件权限为0444(只读):
[root@localhost ~]# chmod -R 0444 /var/www/html/ #设置该目录下的所有文件夹权限为0445
[root@localhost ~]# find /var/www/html/ -type d -print0 | xargs -0 -I {} chmod 0445 {} #配置文件加上写保护
[root@localhost ~]# chattr +i /etc/php.ini /etc/php.d/* /etc/my.ini /etc/httpd/conf/httpd.conf

 九、使用防火墙限制传出连接

攻击者会使用wget之类的工具从你的Web服务器下载文件。使用iptables来阻挡Apache用户的传出连接。ipt_owner模块会为本地数据包的生成者分配不同角色。它只对OUTPUT chain有效。下面指令允许vivek用户通过80端口进行外部访问

/sbin/iptables -A OUTPUT -o eth0 -m owner --uid-owner vivek -p tcp --dport 80 -m state --state NEW,ESTABLISHED  -j ACCEPT

/sbin/iptables --new-chain apache_user
/sbin/iptables --append OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables --append OUTPUT -m owner --uid-owner apache -j apache_user # allow apache user to connec to our smtp server
/sbin/iptables --append apache_user -p tcp --syn -d 192.168.1.100 --dport 25 -j RETURN # Allow apache user to connec to api server for spam validation
/sbin/iptables --append apache_user -p tcp --syn -d 66.135.58.62 --dport 80 -j RETURN
/sbin/iptables --append apache_user -p tcp --syn -d 66.135.58.61 --dport 80 -j RETURN
/sbin/iptables --append apache_user -p tcp --syn -d 72.233.69.89 --dport 80 -j RETURN
/sbin/iptables --append apache_user -p tcp --syn -d 72.233.69.88 --dport 80 -j RETURN ######################### ## Add more rules here ## ######################### # No editing below # Drop everything for apache outgoing connection
/sbin/iptables --append apache_user -j REJECT

十、Auditing log

apache/nginx log

[root@localhost ~]# tail -f /var/log/httpd/error_log
[root@localhost ~]# grep 'login.php' /var/log/httpd/error_log
[root@localhost ~]# egrep -i "denied|error|warn" /var/log/httpd/error_log

php log

[root@localhost ~]# tail -f /var/log/httpd/php_scripts_error.log
[root@localhost ~]# grep "...etc/passwd" /var/log/httpd/php_scripts_error.log

php backdoors

[root@localhost ~]# grep -iR 'c99' /var/www/html/
[root@localhost ~]# grep -iR 'r57' /var/www/html/
[root@localhost ~]# find /var/www/html/ -name \*.php -type f -print0 | xargs -0 grep c99
[root@localhost ~]# grep -RPn "(passthru|shell_exec|system|base64_decode|fopen|fclose|eval)" /var/www/html/

 

其他的有些安全配置

1、安装Mod_security

ModSecurity是一个开源的入侵检测和防范的Web应用引擎。安装mod_security可以保护Apache和PHP应用免受XSS和其他攻击

2、安装防DDOS模块mod_evasive

可以限制在一定时间内的访问频率

英文原文

http://www.cyberciti.biz/tips/php-security-best-practices-tutorial.html

PHP中的一些安全配置的更多相关文章

  1. Ubuntu 14.04中Elasticsearch集群配置

    Ubuntu 14.04中Elasticsearch集群配置 前言:本文可用于elasticsearch集群搭建参考.细分为elasticsearch.yml配置和系统配置 达到的目的:各台机器配置成 ...

  2. angularjs中的directive scope配置

    angularjs中的directive scope配置 定义directive其中重要的一环就是定义scope,scope有三种形式: 默认的scope,DOM元素上原有的scope scope: ...

  3. Production环境中iptables常用参数配置

    production环境中iptables常用参数配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我相信在实际生产环境中有很多运维的兄弟跟我一样,很少用到iptables的这个 ...

  4. apache中虚拟主机的配置

    一.两种方式:基于域名的虚拟主机和基于IP地址的的虚拟主机 (这里基于前者) 二.作用:实现在同一个web服务器下,同时运行很多个站点(项目) 三.虚拟主机的配置 1.在核心配置文件中加载虚拟主机配置 ...

  5. Linux中vim的简单配置

    本文主要分享Linux中vim的简单配置 ★配置文件的位置     在目录/etc.下面,有个名为vimrc的文件,这就是系统中公共的vim配置文件,对所有用户都开放.而在每个用户的主目录下,都可以自 ...

  6. Entity Framework 实体框架的形成之旅--Code First模式中使用 Fluent API 配置(6)

    在前面的随笔<Entity Framework 实体框架的形成之旅--Code First的框架设计(5)>里介绍了基于Code First模式的实体框架的经验,这种方式自动处理出来的模式 ...

  7. Centos中jdk的环境配置

    在Centos中,进行配置jdk的环境,这个还是折腾了我听挺久的.特别是,在一次配置中,导致后来我的root用户无法登录,并且用其他普通用户登录,使用su - root切换到root用户,都无法使用l ...

  8. XAMPP中proftpd的简明配置方法

    XAMPP中proftpd的简明配置方法   用LAMPP的安装方法可以开一个默认的nobody用户,用lampp security就可以初始设置相应的默认用户密码.如果要有多用户,又怎样管理.目录怎 ...

  9. Tools下的mdscongiguer 文件中 43行 oracle 配置 发现需要连接库 -lclntsh libclntsh.so 库是个什么东西呢?

    Tools下的mdscongiguer     文件中 43行  oracle 配置      发现需要连接库 -lclntsh      libclntsh.so 库是个什么东西呢? 分想一个知乎网 ...

  10. VMware中安装CentOS7网络配置静态IP地址,常用配置和工具安装

    VMware中安装CentOS7网络配置静态IP地址,常用配置和工具安装在阿里云开源镜像地址下载镜像Index of /centos/7.2.1511/isos/x86_64/http://mirro ...

随机推荐

  1. SQL Server批量替换全部表中内容sql语句-清楚挂马

    有朋友常常会发现自己的数据库全部的内容给插入了一些代码,假设要一个个表一个个记录去删除.太麻烦了,以下我在在网上找到一个能够批量删除的方法,实际上是批量把那段恶意代码替换,很高速. declare @ ...

  2. HTTP 无状态啊无状态啊

    无状态的根本原因 根本原因是:因为,HTTP协议使用的是Socket套接字TCP连接的,每次监听到的套接字连接是不可能一个个保存起来的.(很消耗资源,假如一个人服务器只保存一个通信连接,一万个岂不是要 ...

  3. Javascript数组操作及索引

    1:清空数组最高效的做法 parentThis.PaperQuestionStrategiesList.length = 0;   2:push and pop parentThis.PaperQue ...

  4. ActiveMQ使用示例之Queue

    我们使用ActiveMQ为大家实现一种点对点的消息模型. 开发时候,要将apache-activemq-5.12.0-bin.zip解压缩后里面的activemq-all-5.12.0.jar包加入到 ...

  5. Objective-C:保留计数器思想的详解(对象的保留和所有权的释放)

    对象的保留和所有权的释放: int main(int agrs,char *argv[]) { @autoreleasepool{ Person *person = [[Person alloc]in ...

  6. python 抓取alexa数据

    要抓取http://www.alexa.cn/rank/baidu.com网站的排名信息:例如抓取以下信息: 需要微信扫描登录 因为这个网站抓取数据是收费,所以就利用网站提供API服务获取json信息 ...

  7. word图片自动编号与引用(转)

    http://blog.csdn.net/hunauchenym/article/details/5915616 用Word时,可能会遇到文中使用了大量的图片的情况,这时,若采用手动为图片编号的方法, ...

  8. 菜鸟运维笔记:小记编译安装Nginx所遇到的坑

    转载请注明出处:http://blog.csdn.net/guodongxiaren/article/details/40950249 谢谢合作 前言 无论是CentOS,或是Debian/Ubunt ...

  9. div css水平垂直居中

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. 关于LayoutInflater的错误用法

    转自:http://www.doubleencore.com/2013/05/layout-inflation-as-intended/ Layout inflation is the term us ...