码迷,mamicode.com
首页 > 其他好文 > 详细

lamp安装

时间:2016-07-11 01:24:25      阅读:183      评论:0      收藏:0      [点我收藏+]

标签: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-devel


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


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








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




缺少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-util


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


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.conf


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






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


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


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=!image-request
指定不记录文件类型:setenvif request_uri ".*\.jpg$" image-request
                    setenvif request_uri ".*\.png$" image-request
                    setenvif request_uri ".*\.gif$" image-request
                    setenvif request_uri ".*\.css$" image-request
                    setenvif request_uri ".*\.js$" image-request
                    setenvif request_uri ".*\.bmp$" image-request
                    setenvif request_uri ".*\.swf$" image-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 image/gif "access plus 1 days"
             expiresbytype image/jpeg "access plus 2 days"
             expiresbytype image/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;
 }

























本文出自 “10846468” 博客,谢绝转载!

lamp安装

标签:lamp

原文地址:http://10856468.blog.51cto.com/10846468/1818268

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!