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/p_w_upload/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=!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;
 }

























發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章