lamp安装


 LAMP(linux,apache,mysql,php)
下载镜像文件根据64位或32为的系统下载http://mirrors.sohu.com/mysql 
apache的编译参数:./configure --prefix=/usr/local/apache --enable-so  --enable-rewrite=shared --enable-expires=shared --enable-deflate=shared(支持静态文件压缩功能) --with-included-apr --with-pcre
yum -y install pcre pcre-devel apr apr-devel zlib-develjavascript


指定模块:--with-mem=prefork/worker/event
prefork非线程型的多协议模块
worker多进程多线程多模模块 高流量 内存低 如一个线程崩溃整个进程就会中止 全部线程共享一个空间
event
vi /usr/local/apache/conf/extra/httpd-mpm.conf文件
# StartServers:  数量的服务器进程开始
# MinSpareServers:  最小数量的服务器进程,保存备用
# MaxSpareServers:  最大数量的服务器进程,保存备用
# MaxRequestWorkers:  最大数量的服务器进程容许开始
# MaxConnectionsPerChild:  最大链接数的一个服务器进程服务php


在第一行#!/bin/sh下增长两行文字
 # chkconfig: 35 70 30
 # description: Apache
 chkconfig --level 35 httpd oncss








rpm -ivh "http://www.aminglinux.com/bbs/data/p_w_upload/forum/month_1211/epel-release-6-7.noarch.rpm"
yum install -y  libmcrypt-develhtml




缺乏apr和apr-util的
wget http://apache.fayea.com/apr/apr-1.5.2.tar.bz2
wget http://apache.fayea.com/apr/apr-util-1.5.4.tar.bz2
tar -jxvf apr-util-1.5.4.tar.bz2 /usr/local/src/http/script
./configure –prefix=/usr/local/web/apr-util –with-apr=/usr/local/apr
make  make install
tar -jxvf apr-1.5.2.tar.bz2
./configure –prefix=/usr/local/apr
make   make  install
tar zxvf /usr/local/src/apr-1.5.2.tar.gz
tar zxvf /usr/local/src/apr-util-1.5.4.tar.gz
mv /usr/loca/src/apr-1.5.2 /usr/loca/src/httpd-2.4.16/srclib/apr
mv /usr/local/src/apr-util-1.5.4 /usr/loca/src/httpd-2.4.16/srclib/apr-utiljava


用putty密钥登录出现server refused our key
打开sshd_config
找到StrictModes yes
修改成StrictModes no
/etc/init.d/sshd reload 从新加载下,登录成功mysql


php的编译参数:./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --with-libxml-dir --with-gd --with-openssl --with-zlib-dir --with-bz2 --with-pcre-dir --with-jpeg-dir --with-mcrypt --with-png-dir --with-freetype-dir --with-iconv-dir --enable-exif --enable-gd-native-ttf --enable-mbstring --enable-soap --with-iconv-dir --disable-ipv6
apache参数修改:index.html index.htm index.php ServerName localhost:80 AddType application/x-httpd-php .php
included conf/extra/httpd-vhost.conflinux


这是在没有安装mysql的状况下使用php自带的mysqlnd模块  --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlndweb






安装discuz论坛 wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GBK.zip
在http.conf 文件中打开keepalive 是客服端屡次链接避免重复链接
keepalivetimeout 应根据网站的流量来设定间隔sql


安装扩展模块:/usr/local/apache/bin/apxs -i -a -c /usr/local/src/源码包目录/modules/generators/模块名chrome


php_admin_value open_basedir "/data/www:/tmp"
能够本身定义标题 须要mode_headers.c模块
<IFModule mod_headers.c>
Header add MyHeader "Hello"
</IFModule>
默认虚拟主机配置 主要是防止其余域名
<virtualhost*:80>
documentroot /tmp/123 随便写
servername   www.cisco.com 随便写
</virtualhost>
目录加密:<dircetory 目录>
          allowoverride authconfig
          authtype basic
          authname 登陆提示名
          authuserfile "加密目录"
          require valid-user
          </directory>
htpasswd -c 加密目录 密码
php_admin_value open_basedir "/data/www:/tmp" 限定php解析的目录
short_open_tag on 开启短标签功能
php_admin_flag engine off 关闭php脚本的解析对某个目录
301跳转:<ifmodule mod_rewrite.c>
         rewriteengine on
         rewritecond %{http_host} ^跳转网站$ [or] 用于多个网站
         rewritecond %{http_host} ^跳转网站$
         rewriterule ^/(.*)$ http://主页/$1 [R=301,L]  301 永久重定向 302 临时重定向 500php脚本问题
         目录的访问控制
         rewritecond %{request_uri} ^.*/限制目录.*
         rewriterule .* - [f]
禁止user-agent
         rewritecond %{http_user_agent} ".*curl.*" [nc,or]   NC不区分大小写
         rewritecond %{http_user_agent} ".*chrome.*"
         rewriterule .* - [f]  
         </ifmodule>
日志割接: "|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/bin/logs/test_access_logs_%Y%m%d_log 86400" combined env=!p_w_picpath-request
指定不记录文件类型:setenvif request_uri ".*\.jpg$" p_w_picpath-request
                    setenvif request_uri ".*\.png$" p_w_picpath-request
                    setenvif request_uri ".*\.gif$" p_w_picpath-request
                    setenvif request_uri ".*\.css$" p_w_picpath-request
                    setenvif request_uri ".*\.js$" p_w_picpath-request
                    setenvif request_uri ".*\.bmp$" p_w_picpath-request
                    setenvif request_uri ".*\.swf$" p_w_picpath-request
日志中如出现:httpd not running, trying to start 多是你的bin下的rotatelogs等缘由
需注意双引号和反斜杠
扩展:
apache中记录代理ip及真实客服端ip :在httpd.conf中的主机格式后添加%{X-FORWARD-FOR}i 就能记录真实地址
apache中记录指定访问目录的日志:setenvif request_uri "^/目录/.*" 目录-request  并在日志格式中添加:env=目录-request
apache中记录客服端请求的域名:在配置文件中的浏览器格式中添加 %V
配置静态缓存:<ifmodule mod_expires.c>
             expiresactive on
             expiresbytype p_w_picpath/gif "access plus 1 days"
             expiresbytype p_w_picpath/jpeg "access plus 2 days"
             expiresbytype p_w_picpath/png "access plus 1 days"
             expiresbytype text/css "now plus 2 days"
             expiresbytype application/x-javascript "now plus 2 days"
             expiresbytupe application/x-shockwave-flash "now plus 2 days"
             expiresdefault "now plus 0 min"
             </ifmodule>
防盗连接: setenvifnocase referer "^http://.*\.swcaac\.com" local_ref
           setenvifnocase referer ".*\.cisco\.com" local_ref
           <filesmatch "\.(jpg|gif|jpeg|js|css|doc|mp3|png|bmp|txt|zip|rar)">
           order allow,deny
           allow from env=local_ref
           </filesmatch>
目录访问控制:1.<directory "/data/www">对怎个目录
             allowoverride none
             options none
              order allow,deny
              allow from all
              deny from 127.0.0.1
              </directory>
              2.<filesmatch "(.*)admin(.*)"> 目录访问控制对某个页面
               order deny,from       
               deny from all
               allow from 127.0.0.1
              </filesmatch>
         
禁止php解析:<directory /data/www/data>对某个目录
             php_admin_flag engine off
             <filesmatch "(.*)php">
             order deny,allow
             deny from all
             allow from ....              
             </filesmatch>
             </directory>
限制某些垃圾浏览器的访问:rewritecond %{http_user_agent} "^.*curl.*"[or,nc] nc表示不区分大小写
                           rewriteconf %{http_user_agent} "^.*chrome.*" [or,nc]
                           rewriteconf %{http_user_agent} "^.*firefox.*"
                           rewriterule .* - [F]
经过指定的目录进行uri如今:rewritecond %{http_uri} ".*/目录/*"[nc]  是对一个目录下的多个子页面进行限制
                           rewriterule .* - [F]


对目录uri如今防止出现死循环:RewriteCond   %{REQUEST_URI} !^/111
                             RewriteRule ^(.*) /111/$1 [R,L]


了解phpmyadmin工具:



curl -A "sdfsadsdfa"  -x192.168.11.160:80 www.test.com/forum.php -I
curl -x127.0.0.1:80 www.bt.com/mmm/a.php 测试结果


php的通常置:/etc/php.ini    关闭高风险函数                      
disable_function=phpinfo,eval,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,fsockopen


控制参数: short_open_tag = On
若是设置为Off,则不能正常解析相似于这样形式的php文件:
<?
phpinfo()
 ?>


而只能解析
<?php
 phpinfo()
 ?>
这样形式的php文件
 因此要想php支持短标签,须要咱们把short_open_tag  设置为On.


今天开发的同事,遇到问题。输入中文,老是显示不出来。
 他的程序编码定义为了gbk。因而想到了php.ini 的配置,打开php.ini 看到:
mbstring.internal_encoding = UTF-8
 mbstring.encoding_translation = On
 mbstring.http_input = UTF-8
 mbstring.http_output = UTF-8
 mbstring.detect_order = UTF-8


因而,把这些所有注释掉,就正常了。至于为何正常了,暂时没有搞明白


display_error=off  关闭错误显示
log_errors=on
error_log=/usr/local/php/logs/php_error.log  定义错误日志的路径
error_reporting=E_ALL & ~E_NOTICE
open_basedir=/data/www/:/tmp  如今网站的目录
php动态加载模块:练习
1.进入源码包
2.cd /ext
3.进入安装的模块目录
4./usr/local/php/bin/phpize  生成./configure的执行包
5../configure --with-php-config=/usr/local/php/bin/php-config 固定语句
6.make && make install
mysql: interactive_timeout = 10 空闲连接超时时间
       wait_timeout = 10
       long_query_time = 1
       log_slow_queries = /data/mysql/slow.log
       skip-name-resolve
        
mysql操做的基本命令:show databases;查询当前数据库 use+数据库名; 切换到指定数据库 show tables;查询数据库中的表 desc+表; show create table+表\G;显示数据库表的详细信息。select user();查看当前用户
create table db (`id` int(3),`name` char(20)) ENGINE=MYISAM DEFAULT CHARSET=gbk;建立一个表
desc db; select * from db; select user,id from db;insert into db values(1,'b');update db set id=1 where name='a'; show variables; show variables like 'max_connect%'; set global like max_connect_errors =100; delete from db id=1; drop table cisco; drop database mysql;truncate table cisco; mysqldump -uroot -pcisco mysql > /tmp/mysql.sql
--default-character-set=gbk 如出现乱码 修改此参数




LAMP的扩展:
                                隐藏apache版本信息
在 httpd.conf,加入如下两行:
ServerTokens ProductOnly
ServerSignature Off
                              隐藏php版本信息
 编辑php.ini
把expose_php = On 修改成  expose_php = Off


                               apache设置自定义header
1. 在设置自定义header前,须要先检测一下你的httpd是否加载了mod_headers
01./usr/local/apache2/bin/apachectl  -l
复制代码若是,显示有mode_headers.c  则是加载了这个模块,不然就须要从新编译一下了。
另外,若是你使用的是rpm安装的话,那确定是已经加载了mod_headers这个模块的。
2.  在httpd.conf 中加入
01.<IFModule mod_headers.c>
02. Header add MyHeader "Hello"
03.</IFModule>
复制代码保存后,重启apache就能够了。双引号中的内容为自定义内容。固然这里的"MyHeader"也是能够自定义的。
3. 测试curl  -I http://localhost   复制代码看是否显示有  MyHeader  "Hello"


Nginx 404 跳转至首页Errordocument 404 /404.php另外也能够经过rewrite规则实现 在 rewrite rule 的最后增长if (!-e $request_filename) {       rewrite ^(.*)$ /404.php last; }

相关文章
相关标签/搜索