我的lamp常用安装配置
写一下我使用lamp时的常用配置。apache:
./configure --prefix=${PREFIX} /
--enable-so /
--enable-rewrite /
--enable-deflate /
--enable-headers /
--enable-proxy /
--enable-proxy_balancer
so: 允许运行时加载DSO模块
rewrite: 一个基于一定规则的实时重写URL请求的引擎
deflate: 压缩发送给客户端的内容
headers: 允许通过配置文件控制任意的HTTP请求和应答头信息
proxy: 提供HTTP/1.1的代理/网关功能支持
mod_proxy的扩展,提供负载平衡支持
defalte的设置:
#deflate module
#默认使用deflate模块,如果你自己的VirtualHost里面不想使用该模块的话,请使用:
# RemoveOutputFilter? DEFLATE
#清除该filter
<IfModule mod_deflate.c>
<Location />
SetOutputFilter DEFLATE
#这个版本的gzip有问题, 只压缩html数据
BrowserMatch ^Mozilla/4 gzip-only-text/html
#这个版本更有问题, 什么都不压缩
BrowserMatch ^Mozilla/4/.0 no-gzip
BrowserMatch /bMSI no-gzip gzip-only-text/html
BrowserMatch /bMSIE/s no-gzip
#不压缩图片,音乐等格式的文件
SetEnvIfNoCase Request_URI /.(?:gif|jpg|cab|jpe?g|exe|bmp|mp3|rar|zip|swf|png|ico)$ no-gzip dont-vary
#不甚明白
Header append Vary User-Agent env=!dont-vary
</Location>
</IfModule>
日志记录:
ErrorLog "logs/error_log"
LogLevel warn
ErrorLog "|$ServerRoot/bin/cronolog $ServerRoot/logs/%w/error_log"
如下配置是在安装好cronolog之后的配置
<IfModule log_config_module>
LogFormat "%{X-Forwarded-For}i %l %u %t /"%r/" %>s %b /"%{Referer}i/" %{Cookie}i /"%{User-agent}i/"" deflate_combined
LogFormat "%h %l %u %t /"%r/" %>s %b /"%{Referer}i/" %{Cookie}i /"%{User-agent}i/"" combined
LogFormat "%h %l %u %t /"%r/" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
CustomLog "|$ServerRoot/bin/cronolog $ServerRoot/logs/%w/access_log.%H" deflate_combined
#<IfModule rewrite_module>
#RewriteLog "|$ServerRoot/bin/cronolog $ServerRoot/logs/%w/rewrite_log"
#RewriteLogLevel 1
#</IfModule>
</IfModule>
如下配置是默认配置,是直接写文件的,并没有自动的日志分割
<IfModule log_config_module>
LogFormat "%{X-Forwarded-For}i %l %u %t /"%r/" %>s %b /"%{Referer}i/" %{Cookie}i /"%{User-agent}i/"" combined
#LogFormat "%h %l %u %t /"%r/" %>s %b /"%{Referer}i/" %{Cookie}i /"%{User-agent}i/"" combined
#LogFormat "%h %l %u %t /"%r/" %>s %b" common
#LogFormat "%{Referer}i -> %U" referer
#LogFormat "%{User-agent}i" agent
CustomLog "logs/access_log" combined
#<IfModule rewrite_module>
#RewriteLog "logs/rewrite_log"
#RewriteLogLevel 1
#</IfModule>
</IfModule>
安全配置
# for safety
#不准返回由autoindex模块自动生成一个index页面返回给用户
#禁止使用内容协商的多重MultiView搜索
Options -Indexes -MultiViews
#不准访问这种特殊后缀的文件,也为了安全
<FilesMatch "/.(sql|bak|inc|old)">
Deny from all
</FilesMatch>
#将一些sql注入或者xss攻击所需要的字符给过滤掉,请确认是否自己的应用确实需要这样的字符串
#RewriteEngine On
#RewriteCond %{QUERY_STRING} [/"/'/<]
#RewriteCond %{QUERY_STRING} (/%00)+
#RewriteCond %{QUERY_STRING} (/%22)+
#RewriteCond %{QUERY_STRING} (/%27)+
#RewriteCond %{QUERY_STRING} (/%3e)+
#RewriteRule ^.*
#对于Mod_status开启时,对每个请求附加扩展属性。
ExtendedStatus Off
资源限制相关
LimitRequestBody 1024000
#限制接受客户端请求中HTTP请求头域的数量,使用默认值100
#LimitRequestFields 100
#限制Apache子进程派生的进程占用CPU的最大秒数,默认是采用操作系统默认值
RLimitCPU 600
#限制由Apache子进程派生的进程占用的最大内存字节数,默认采用操作系统默认值
#RLimitMEM 2147483647
prefork的设置:
#这里请根据不同的应用自己配置相应参数
<IfModule prefork.c>
#服务器启动时建立的子进程数,默认值就是5
StartServers 5
#空闲子进程的最小数量,默认值是5
MinSpareServers 20
#空闲子进程的最大数量,默认值是10
MaxSpareServers 50
#允许同时伺服的最大接入请求数量,默认值就是256,如果实际需求大于这个数值,请同时增加该值和ServerLimitServerLimit?">的值保证请求响应时间
MaxClients 256
#每个子进程在其生存期内允许伺服的最大请求数量,默认值是0,即永不过期,设置这个是为了避免一个子进程一直跑,出现内存泄露的情况就糟糕了
MaxRequestsPerChild10000
</IfModule>
header设置
<IfModule mod_header.c>
#这些文件缓存时间设置很长
<FilesMatch "/.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
#这些文件缓存时间稍短
<FilesMatch "/.(js|css)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
#这些文件缓存时间继续缩短
<FilesMatch "/.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=86400, public"
</FilesMatch>
#这些文件不得缓存
<FilesMatch "/.(html|htm|php|cgi|pl|xml)$">
Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
</FilesMatch>
</IfModule>
浏览器处理
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4/.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4/.0" force-response-1.0
BrowserMatch "Java/1/.0" force-response-1.0
BrowserMatch "JDK/1/.0" force-response-1.0
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage?" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1." redirect-carefully
BrowserMatch "^gnome-vfs" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully
虚拟主机配置目录
Include $ServerRoot/conf/vss/*
虚拟主机配置子文件:
Listen 8005
<VirtualHost *:8005>
DocumentRoot /home/wully/webtools/bin
<Directory "/home/wully/webtools/bin">
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride all
Allow from all
</Directory>
</VirtualHost>
mysql
./configure --prefix=${PREFIX} /
--with-charset=gbk /
--with-extra-charset=all /
--with-plugins=max /
--with-unix-socket-path=${PREFIX}/tmp/mysql.sock /
--enable-local-infile
说明:
#默认编码,我们默认使用gbk编码
--with-charset=gbk
#默认也支持所有编码
--with-extra-charset=all
# mysql的引擎都已plugins的形式存在,默认情况下,是不包含innodb的。我们的应用中需要使用事务,外键等。需要支持innodb。此外,
以后我们可能还会使用ndbcluster。因此编译时选择最大安装max。但目前不清楚all与max有什么区别。
--with-plugins=max
#不是用默认的/tmp/mysql.sock保证一台机器可以有多台同时提供服务
--with-unix-socket-path=${PREFIX}/tmp/mysql.sock
#使 LOAD DATA LOCAL INFILE语句生效
--with--enable-local-infile
配置
#严重错误日志记录地方
log-error = $MYSQL_PREFIX/log/mysql.err
#强制设置为2
log-warnings= 2
#慢查询日志记录
log-queries-not-using-indexes
long-query-time = 1
log-slow-queries = $MYSQL_PREFIX/log/slow.log
#全日志记录
log=$MYSQL_PREFIX/log/mysql.log
#每台server都需开启relay-log,为避免机器改名引起文件名变化,需在配置文件中指定如下文件名。
relay-log=mysql_relay
relay-log-info-file = mysql-relay.info
PHP
./configure --prefix=${PREFIX} /
--with-mysql=${MYSQL_PREFIX} /
--with-mysql-sock=${MYSQL_PREFIX}/tmp/mysql.sock /
--with-pdo-mysql=${MYSQL_PREFIX} /
--with-apxs2=${APACHE_PREFIX}/bin/apxs /
--with-config-file-path=${PREFIX} /
--with-libxml-dir /
--enable-force-cgi-redirect /
--enable-sockets /
--enable-soap /
--enable-bcmath /
--enable-shmop /
--enable-calendar /
--enable-pcntl /
--enable-ftp /
--enable-mbstring /
--with-zlib /
--with-xmlrpc /
--with-curl
说明:
--with-mysql,--with-mysql-sock,--with-pdo-mysql:
php默认是不安装mysql对应函数的,这里需要显式指明
--with-apxs2
这样是通过apxs工具生成php的apache模块,让apache通过libphp.so调用php相关程序
--with-config-file-path
这个很简单,将php.ini文件默认放置在什么位置
--with-libxml-dir
利用本机装的libxml提供simple_xml或者dom支持
--enable-force-cgi-redirect
对服务器内部跳转强制做安全跳转,推荐打开
--enable-sockets
使用socket通信
--enable-soap
使用soap相应函数
--enable-bcmath
使用bc工具类似的数据库函数
--enable-shmop
一个共享内存模块
--enable-calendar
使用日历函数
--enable-pcntl
作为后端程序,使用了多进程,提供fork等功能
--enable-ftp
使用ftp函数直接获取ftp文件,比使用wget更健壮和高效
--enable-mbstring
多字节字符串处理
--with-zlib
使用这个选项,有效减少ViewState的size,减少网络带宽占用
--with-xmlrpc
xmlrpc对应函数
--with-curl
curl相关函数
配置:
#从php.ini-recommed到目前配置有如下需要注意
#隐藏php信息
expose_php = Off
#最长执行时间,自己控制
max_execution_time = 600
#显示错误关闭
display_errors = Off
#将错误日志打开
log_errors = On
error_log = $PHP_PREFIX/php.err
#对$_GET,$_POST,$_COOKIE自动的做addslash的操作
magic_quotes_gpc = On
#不建议是用全局变量
register_globals=Off
#扩展路径修改为如下路径,是为了安装PECL包而留下的
extension_dir = "/home/wully/programs/php/extensions/no-debug-non-zts/
页:
[1]