標籤

4GL (1) 人才發展 (10) 人物 (3) 太陽能 (4) 心理 (3) 心靈 (10) 文學 (31) 生活常識 (14) 光學 (1) 名句 (10) 即時通訊軟體 (2) 奇狐 (2) 爬蟲 (1) 音樂 (2) 產業 (5) 郭語錄 (3) 無聊 (3) 統計 (4) 新聞 (1) 經濟學 (1) 經營管理 (42) 解析度 (1) 遊戲 (5) 電學 (1) 網管 (10) 廣告 (1) 數學 (1) 機率 (1) 雜趣 (1) 證券 (4) 證券期貨 (1) ABAP (15) AD (1) agentflow (4) AJAX (1) Android (1) AnyChart (1) Apache (14) BASIS (4) BDL (1) C# (1) Church (1) CIE (1) CO (38) Converter (1) cron (1) CSS (23) DMS (1) DVD (1) Eclipse (1) English (1) excel (5) Exchange (4) Failover (1) Fedora (1) FI (57) File Transfer (1) Firefox (3) FM (2) fourjs (1) Genero (1) gladiatus (1) google (1) Google Maps API (2) grep (1) Grub (1) HR (2) html (23) HTS (8) IE (1) IE 8 (1) IIS (1) IMAP (3) Internet Explorer (1) java (4) JavaScript (22) jQuery (6) JSON (1) K3b (1) ldd (1) LED (3) Linux (120) Linux Mint (4) Load Balance (1) Microsoft (2) MIS (2) MM (51) MSSQL (1) MySQL (27) Network (1) NFS (1) Office (1) OpenSSL (1) Oracle (131) Outlook (3) PDF (6) Perl (60) PHP (33) PL/SQL (1) PL/SQL Developer (1) PM (3) Postfix (2) postfwd (1) PostgreSQL (1) PP (50) python (5) QM (1) Red Hat (4) Reporting Service (28) ruby (11) SAP (234) scp (1) SD (16) sed (1) Selenium (3) Selenium-WebDriver (5) shell (5) SQL (4) SQL server (8) sqlplus (1) SQuirreL SQL Client (1) SSH (3) SWOT (3) Symantec (2) T-SQL (7) Tera Term (2) tip (1) tiptop (24) Tomcat (6) Trouble Shooting (1) Tuning (5) Ubuntu (37) ufw (1) utf-8 (1) VIM (11) Virtual Machine (2) VirtualBox (1) vnc (3) Web Service (2) wget (1) Windows (19) Windows (1) WM (6) Xvfb (2) youtube (1) yum (2)
顯示具有 Apache 標籤的文章。 顯示所有文章
顯示具有 Apache 標籤的文章。 顯示所有文章

2015年3月24日 星期二

在 Windows 7 上安裝 Apache + PHP + PostgreSQL

http://yuanfarn.blogspot.tw/2013/06/windows-7-apache-php-postgresql.html

前幾天寫了篇 "在 Debian 上安裝 Apache + PHP + PostgreSQL"。這兩天突然想到,也許有些讀者只是單純想試試 Apache 和 PostgreSQL,於是乾脆也在自己的 Windows 7 上來試試如何安裝 Apache + PHP + PostgreSQL 了。
其實,在 Windows 7 上安裝也非常簡單,其中 Apache 和 PHP 只是將下載回來的壓縮檔解開,然後修改幾個設定即可。
安裝 Apache HTTP Server
Apache 目前最新的版本為 2.4.4,不過讀者可能會發現在 Apache 的網站 http://httpd.apache.org/ 上找不到 Windows 版的安裝程式,必須在 Apache Lounge (http://www.apachelounge.com/) 下載 Windows 的版本。
下載取得 httpd-2.4.4-win32.zip 這個檔案,然後將它解壓縮到 C:\,基本上會得到 C:\Apache24 這個目錄。
安裝 PHP
從 PHP 的網站 http://php.net/ 下載取得 PHP 5.4 (5.4.16) 的 VC9 x86 Thread Safe 版本,將它解壓縮並變更目錄名稱為 C:\php。
設定 Apache HTTP Server 與 PHP
從 PHP 5.4.10 這個版本之後,基本的設定如下:
首先編輯 C:\Apache24\conf\httpd.conf 這個檔案,然後加入以下幾行:
LoadModule php5_module "c:/php/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"
接著找到 Directory index 的設定,並加入 index.php 這項:
DirectoryIndex index.html index.php
向 Windows 註冊 Apache HTTP Server
以系統管理員的身份執行命令提示字元 (Command prompt),然後執行以下這行:
C:\apache24\bin\httpd -k install
接著再執行將它指定為手動啟動:
sc config Apache2.4 start= demand
不過通常我會將 demand 改成 auto,讓 Apache HTTP Server 自動啟動。
最後,將 C:\Apache24、C:\Apache24\bin 及 C:\PHP 這幾個路徑加到環境變數的 PATH 裡。
修改 PHP 的設定
在 C:\PHP 找到 php.ini-development 這個檔案,複製一份並更名為 php.ini,然後修改如下:
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"

extension=php_pgsql.dll
基本上,要取消 PostgreSQL 這個 DLL extension 的註解。此外,也可以再取消幾個 extension 的註解,如下:
extension=php_bz2.dll
extension=php_fileinfo.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_gmp.dll
extension=php_mbstring.dll
命令提示字元 (Command prompt),執行以下這行確認載入的模組:
php -m
到這裡,基本上已經完成 Apache HTTP Server 與 PHP 的設定了,可以在 C:\Apache24\htdocs 編輯一個 info.php,填入以下內容:
<?php
phpinfo();
?>
然後,用瀏覽器開啟 http://localhost/info.php 查看。
安裝 PostgreSQL
從 PostgreSQL 的網站 http://www.postgresql.org/ 下載 Windows 版的安裝程式。根據網頁上的說明,將從 EnterpriseDB 的網站取得 9.2.4 版的安裝程式。
雙擊下載回來的 postgresql-9.2.4-1-windows.exe 安裝,並變更目錄到 C:\。因此,安裝完成會得到 C:\PostgreSQL\9.2 這個目錄。
在安裝過程依照說明設定資料庫管理員的密碼。
Windows 版本的 PostgreSQL 安裝程式會一併安裝圖形化的管理工具 pgAdmin III,在安裝後就可以直接用它來管理 PostgreSQL 了。

2014年12月10日 星期三

CentOS 6.2 安裝 Apache/2.2.15 and PHP/5.2.17

1. OS version

[root@EIP-API-AP php-5.2.17]# lsb_release -a
LSB Version:    :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.2 (Final)
Release:        6.2
Codename:       Final

2. Apache version

[root@EIP-API-AP php-5.2.17]# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built:   Oct 16 2014 14:48:21

3. PHP version

php-5.2.17

4. 拿掉/安裝 不要service

chkconfig iptables off
chkconfig postfix off
yum install vsftpd.x86_64 (vim /etc/vsftp/vsftpd.conf --> userlist_deny=NO)

5. OS command

yum install httpd-devel
yum install gcc
yum install libxml2-devel
yum install mysql-devel

yum install autoconf
cp -rp /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so
./configure --with-apxs2=/usr/sbin/apxs --with-mysql
make
make test
make install
cp php.ini-recommended /usr/local/lib/php.ini
 

6. vim httpd.conf

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

7. vim php.ini

short_open_tag=on (這樣<% 才認得,否則只能用 <?php)

8. OS command

service httpd restart

9. install oracle instant client

rpm -U oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
rpm -U oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm

10. download oci8

ln -s /usr/lib/oracle/12.1/client64/lib/libclntsh.so.12.1 /usr/lib/oracle/12.1/client64/lib/libclntsh.so
tar zxvf oci8-2.0.8.tgz
cd oci8-2.0.8
phpize
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/12.1/client64/lib
make
make install

11. vim /usr/local/lib/php.ini

extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613/"
extension=oci8.so

12. service httpd restart

13. mysqli installation

cd ~/Downloads/php-5.2.17/ext/mysqli/
phpize
./configure --prefix=/usr/local/mysqli --with-php-config=/usr/local/bin/php-config --with-mysqli=/usr/bin/mysql_config
make
make install
vim /usr/local/lib/php.ini (extension=mysqli.so)

14. phpinfo

check if oci8 installed

 

2014年6月12日 星期四

apache下设置不显示目录列表 Indexes FollowSymLinks

http://blog.sina.com.cn/s/blog_66c183b3010102ql.html

如果你的文件根目录里有 index.html,浏览器就会显示 index.html的内容,如果没有 index.html,浏览器就会显示文件根目录的目录列表,目录列表包括文件根目录下的文件和子目录。
同样你输入一个虚拟目录的地址:
http://localhost:8080/b/
如果该虚拟目录下没有 index.html,浏览器也会显示该虚拟目录的目录结构,列出该虚拟目录下的文件和子目录。
如何禁止 Apache 显示目录列表呢?
要禁止 Apache 显示目录结构列表,只需将 Option 中的 Indexes 去掉即可。
比如我们看看一个目录的目录配置:
<Directory "D:/Apa/blabla">
 Options Indexes FollowSymLinks #---------->Options FollowSymLinks
 AllowOverride None
 Order allow,deny
 Allow from all
</Directory>
你只需要将上面红色代码中的 Indexes 去掉,就可以禁止 Apache 显示该目录结构。用户就不会看到该目录下的文件和子目录列表了。
Indexes 的作用就是当该目录下没有 index.html 文件时,就显示目录结构,去掉 Indexes,Apache 就不会显示该目录的列表了。
第二种方法
解决办法:
        1、编辑httpd.conf文件
            vi ./conf/httpd.conf
   找到如下内容:
          ?BR>          <Directory “C:/Program Files/Apache2.2/htdocs”>
              #
              # Possible values for the Options directive are “None”, “All”,
              # or any combination of:
                 Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
              #
              # Note that “MultiViews” must be named *explicitly* — “Options All”
              # doesn’t give it to you.
              #
              # The Options directive is both complicated and important. Please see
              # http://httpd.apache.org/docs/2.2/mod/core.html#options
              # for more information.
              #
              Options Indexes FollowSymLinks
              #
              # AllowOverride controls what directives may be placed in .htaccess files.
              # It can be “All”, “None”, or any combination of the keywords:
              #   Options FileInfo AuthConfig Limit
              #
              AllowOverride None
              #
              # Controls who can get stuff from this server.
              #
              Order allow,deny
              Allow from all
          </Directory>
          ……
   在Options Indexes FollowSymLinks在Indexes前面加上 – 符号。
        即: Options -Indexes FollowSymLinks
   【备注:在Indexes前,加 + 代表允许目录浏览;加 – 代表禁止目录浏览。】
    这样的话就属于整个Apache禁止目录浏览了。
    如果是在虚拟主机中,只要增加如下信息就行:
           <Directory “D:test”>
             Options -Indexes FollowSymLinks
             AllowOverride None
             Order deny,allow
             Allow from all
         </Directory>
     这样的话就禁止在test工程下进行目录浏览。
备注: 切记莫把“Allow from all”改成 “Deny from all”,否则,整个网站都不能被打开。
   <Finished>
 还有一种方法:
可以在根目录的 .htaccess 文件中输入
<Files *> 
Options -Indexes 
</Files> 
就可以阻止Apache 将目录结构列表出来。

2014年5月15日 星期四

How do I set expiration headers for CSS, JS, and Images?

http://webmasters.stackexchange.com/questions/5265/how-do-i-set-expiration-headers-for-css-js-and-images

方法 1:
# 
# configure mod_expires
# 
# URL: http://httpd.apache.org/docs/2.2/mod/mod_expires.html
# 
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 seconds"
    ExpiresByType image/x-icon "access plus 2692000 seconds"
    ExpiresByType image/jpeg "access plus 2692000 seconds"
    ExpiresByType image/png "access plus 2692000 seconds"
    ExpiresByType image/gif "access plus 2692000 seconds"
    ExpiresByType application/x-shockwave-flash "access plus 2692000 seconds"
    ExpiresByType text/css "access plus 2692000 seconds"
    ExpiresByType text/javascript "access plus 2692000 seconds"
    ExpiresByType application/x-javascript "access plus 2692000 seconds"
    ExpiresByType text/html "access plus 600 seconds"
    ExpiresByType application/xhtml+xml "access plus 600 seconds"
</IfModule>

# 
# configure mod_headers
# 
# URL: http://httpd.apache.org/docs/2.2/mod/mod_headers.html
# 
<IfModule mod_headers.c>
    <FilesMatch "\\.(ico|jpe?g|png|gif|swf|css|js)$">
        Header set Cache-Control "max-age=2692000, public"
    </FilesMatch>
    <FilesMatch "\\.(x?html?|php)$">
        Header set Cache-Control "max-age=600, private, must-revalidate"
    </FilesMatch>
    Header unset ETag
    Header unset Last-Modified
</IfModule>
 
方法 2:
http://www.arefly.com/enable-website-cache-by-htaccess/ 
 
將下列代碼添加至網站根目錄的 .htaccess 文件中
#取消ETag功能
Header unset ETag
FileETag None
 
#設定檔案過期時間
<IfModule mod_expires.c>
#要設定的檔案類型
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|gz)$">
ExpiresActive On
#604800秒=1週
ExpiresDefault A604800
</FilesMatch>
</IfModule>
 
#設定檔案快取時間
<IfModule mod_headers.c>
#要設定的檔案類型
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|gz)$">
#604800秒=1週
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
</IfModule>
 
#壓縮JS和CSS檔
<IfModule mod_deflate.c>
<FilesMatch ".(js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
 
方法3:

http://zfly9.blogspot.tw/2014/01/htaccesscache.html

 使用.htaccess快取,提升網站速度

.htaccess 網頁 緩存 設定 設置 檢測教學


.htaccess 是 Apache HTTP Server 底下,對目錄及檔案的一個控制文件,也就是說web網頁伺服器,是用Apache HTTP Server這套軟體架設的,才能使用.htaccess。

.htaccess 能做的事很多,本篇主要是說明,如何用它來快取,提高網站速度。

其本原理:
像css js jpg png gif swf這些不常變更的檔案,在瀏覽器下載後,會附上過期時間,於下次下載前,會比對是否超過期限,如沒超過就不會下載,這樣可大幅提高網站瀏覽速度。

畢竟 圖檔 css js 也佔不少kb,重覆一直下載義意不大,而且會拖到網頁讀取時間,在能使用 .htaccess 來提速的情況下,還是設置一下,會比較好。

設置上也很簡單,開個文字檔,將下述代碼覆製貼上,由於windows,在命名時,是不接受沒有檔名的文件,所以先存成htaccess.txt,上傳至主機後,在用ftp更名為.htaccess即可。

如果根目錄下,已經有.htaccess文件,先下載回來,下述代碼copy貼至後面,存檔上傳覆蓋即可。

Header unset ETag
FileETag None

<ifmodule mod_expires.c>
<filesmatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresActive On
ExpiresDefault A2592000
</FilesMatch>
</IfModule>

<ifmodule mod_headers.c>
<filesmatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
</IfModule>

htaccess.txt內容參考圖:





將htaccess.txt上傳至主機後,更名為.htaccess參考圖:








要怎麼查看是否有在運作,十分簡單easy,因為現今瀏覽器都有內建網站檢查工具,開來看一下就知道了,下述用firefox做範例:

工具 → 網頁開發者 → 網頁工具箱

















如果http回傳值Date和Expires這之間的日期與你設的不同,Cache-Control的值也不同,原因有可能是:

a、不是使用Apache HTTP Server的主機,大部份跑php都是使用Apache,所以這問題不常見。

b、主機沒安裝mod_expires.c及mod_headers.c這2個模組,之前見過有些空間商,為了讓客戶的流量好看,沒加載 mod_expires.c、mod_headers.c此2模組,結果它的站用的花花綠綠圖片一堆,網頁開了有點慢,這時你可以反應,請他們掛上 mod_expires.c、mod_headers.c,如果沒辦法處理,那就自已換別的主機代理商。


大致說明就這樣了,未來如有什麼要補充的,到時在補上。


相關文章 → .htaccess 防盜連 轉址 用法
 

2014年5月8日 星期四

httpd.conf htpasswd 設定

在RedHat/CentOS

1. 透過.htaccess



2. 透過 httpd.conf
vi /etc/httpd/conf/httpd.conf

 # 測試使用的
 <VirtualHost *:80>
     ServerName demo.xxx.com
     ServerAdmin mis@xxx.com
     DocumentRoot /home/yyy/demo
     ErrorLog  logs/demo.error_log
     CustomLog logs/demo.access_log common
     <Directory "/home/yyy/demo">
       Options Indexes FollowSymLinks
       AllowOverride None
       Order allow,deny
       Allow from all

       AuthUserFile /home/yyy/.htpasswd
       AuthName "Password please"
       AuthType Basic
       Require valid-user
     </Directory>
 </VirtualHost>


Apache設定預設網頁名稱~PHP環境

http://www.dotblogs.com.tw/jerry710822/archive/2010/12/28/20428.aspx

我是將/etc/httpd/conf.d/php.conf DirectoryIndex 設為login.html

網站建立好後,會設定網頁預設首頁檔名,以便使用者只要輸入網址不必要去輸入類似index.html、index.php等檔名,畢竟這麼多首頁名稱使用這常常會輸入錯誤,不過以往若是php環境,Apache會以index.php為首頁,如下圖所示
Apache設定檔路徑:/etc/httpd/conf/httpd.conf
2010-12-28 下午 03-06-29
有一種情況就是若要使用index.htm或index.html就會有問題,若只是設定上述設定,將index.htm或index.html放入也不會去讀取,必須設定下列設定才可以使用,
編輯此檔案/etc/httpd/conf.d/php.conf ,裡面也會有設定首頁檔名的設定,筆者是要設定以index.html為首頁,設定如下,這樣就可以正常使用。
2010-12-28 下午 02-48-40

使用 .htaccess 網頁認證的方式

製作工具toolhttp://www.htaccesseditor.com/tc.shtml#a_fileList


http://sparc.nfu.edu.tw/teacher/htaccess/
  .htaccess 網頁認證的方式,是以目錄為一個驗證的節點,凡要經過此目錄才能瀏覽的網頁,
  皆需要透過 .htaccess 的驗證之後才可以存取。
 
   
舉例:
    
      我有一個學術單位的網頁,網址為 http://sparc.nfu.edu.tw/~test/
      是要讓大家都可以來瀏覽的;不過我有一些比較機密性的文件,僅可以提供某些特定的人來瀏覽,
      於是這些機密性的文件我都將它放置到網頁根目錄底下的 admin目錄當中,
      如今我要讓來存取網址為 http://sparc.nfu.edu.tw/~test/admin/(任何檔案)
      都需要透過驗證才能夠瀏覽,我可以這麼做:
    步驟1.建立 .htaccess
    
      在 admin 目錄中,建立一個 .htaccess 的檔案,
      .htaccess 的檔案內容為 :
               
       AuthName "Admin Login"
  AuthUserFile /home1/test/.passwd
  AuthType Basic
  require valid-user
 
 
   各欄位的意義:
 
    1. AuthName "Admin Login"   
       用來設定如下紅色方框內的文字
   
 
    2. AuthUserFile /home1/test/.passwd
     AuthUserFile 用來設定給 .htaccess 驗證時,要使用的帳號密碼資料檔的位置,
     需使用絕對路徑的方式來設定。
     而 /home1/test/.passwd 帳號密碼資料檔,是由我們自行產生的(在 步驟2 會說明)。
    3. AuthType Basic
       認證的類型;我們使用 Apache 預設的類型,Basic就可以了
    4. require valid-user
       讓密碼檔內的使用者都能夠登入(即上面AuthUserFile所指定的檔案) 
 
   步驟2. 產生帳號密碼檔
 
    利用 htpasswd 指令來幫我們產生帳號密碼檔
 
    語法:htpasswd [ 參數 ] < 帳號密碼檔 > < 要新建的登入帳號 >
 
 
    1. 若現在我要新建一個登入帳號 為 test,
    而這個時候 /home1/test/.passwd 帳號密碼檔
    還不存在,則我需要輸入下列指令:
   
       htpasswd –c /home1/test/.passwd test  
      (-c 參數用來產生帳號密碼檔 )
     *基於安全性上的考量,帳號密碼檔 請勿放置在WWW目錄內(含WWW以下目錄中),
       建議使用者可將帳號密碼檔放置在 使用者家目錄 即可。     
   
 
 
   輸入完之後,它會請您輸入此使用者 test 的密碼,輸入完,
   便會產生 /home1/test/.passwd 帳號密碼檔案,
   並且在 /home1/test/.passwd 檔案裡面您會看到 test 這個帳號,
   與其加密過後的密碼。
    (需特別注意的是,如果 /home1/test/.passwd 已經存在的話,
     請不要再使用 –c 參數,因為它會覆蓋掉原本/home1/test/.passwd
     的內容,只留下我們此次建立的帳號資料 )
    2. 如果現在我要再新建一個登入帳號 為 admin,
     而這個時候 /home1/test/.passwd 已經存在,
     則我只需要輸入下列指令,
       
       htpasswd  /home1/test/.passwd admin
 
     然後它依然會請您輸入此使用者的密碼,輸入完畢後,
     在 /home1/test/.passwd 就會看到,
     您剛剛新建的使用者帳號及密碼的資料了。
 
 
經過 步驟1 與 步驟2 的設定之後,
 
只要有人要來瀏覽我的 http://sparc.nfu.edu.tw/~test/admin/(任何檔案)
就必須要輸入帳號密碼,此時只要輸入在 步驟2 所建立的帳號密碼,就可以登入了。

2014年5月7日 星期三

PHP + Apache Web Service Example

serverSoap.php  

<?php
    //server端 serverSoap.php
    $soap = new SoapServer(null,array('uri'=>"http://localhost/"));//This uri is your SERVER ip.
    $soap->addFunction('minus_func');                                                 //Register the function
    $soap->addFunction(SOAP_FUNCTIONS_ALL);
    $soap->handle();

    function minus_func($i, $j){
        $res = $i + $j;
        return $res;
    }
?>

clientSoap.php <?php
    //client端 clientSoap.php
    try {
        $client = new SoapClient(null,
            array('location' =>"http://localhost/webservice/serverSoap.php",'uri' => "http://127.0.0.1/")
        );
        echo $client->minus_func(100,92);

    } catch (SoapFault $fault){
        echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;
    }
?>
      

2014年4月24日 星期四

Apache Log Files

http://www.cyberciti.biz/faq/apache-logs/

Apache Log Files

by on June 8, 2008 · 21 comments· LAST UPDATED June 8, 2008
Q. How do I find out Apache http server log files location? How do I change the location of Apache log file under Linux / UNIX operating system?

A. There are two type of apache httpd server log files:

Apache Error Log File

All apache errors / diagnostic information other errors found during serving requests are logged to this file. Location of error log is set using ErrorLog directive. If there is any problem, you should first take a look at this file using cat, grep or any other UNIX / Linux text utilities. This apache log file often contain details of what went wrong and how to fix it. Default error log file location:
  • RHEL / Red Hat / CentOS / Fedora Linux Apache error file location - /var/log/httpd/error_log
  • Debian / Ubuntu Linux Apache error log file location - /var/log/apache2/error.log
  • FreeBSD Apache error log file location - /var/log/httpd-error.log
To find exact apache log file location, you can use grep command:
# grep ErrorLog /usr/local/etc/apache22/httpd.conf
# grep ErrorLog /etc/apache2/apache2.conf
# grep ErrorLog /etc/httpd/conf/httpd.conf

Sample output:
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a 
ErrorLog "/var/log/httpd-error.log"

Apache Access Log File

Apache server records all incoming requests and all requests processed to a log file. The format of the access log is highly configurable. The location and content of the access log are controlled by the CustomLog directive. Default apache access log file location:
  • RHEL / Red Hat / CentOS / Fedora Linux Apache access file location - /var/log/httpd/access_log
  • Debian / Ubuntu Linux Apache access log file location - /var/log/apache2/access.log
  • FreeBSD Apache access log file location - /var/log/httpd-access.log
To find exact apache log file location, you can use grep command:
# grep CustomLog /usr/local/etc/apache22/httpd.conf
# grep CustomLog /etc/apache2/apache2.conf
# grep CustomLog /etc/httpd/conf/httpd.conf

Sample output:
  # a CustomLog directive (see below).
    #CustomLog "/var/log/httpd-access.log" common
    CustomLog "/var/log/httpd-access.log" combined

How do I change Apache log file location?

Simply edit apache configuration file and change the location. You need define new location using CustomLog or ErrorLog:
ErrorLog "/home/httpd/cyberciti.biz/rawlogs/httpd-error.log"
CustomLog "/home/httpd/cyberciti.biz/rawlogs/httpd-access.log" combined
Save and close the file. Restart httpd:
# service httpd restart

2014年4月20日 星期日

Apache : 設置Expires


通过mod_expires模块设置Expires

<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault "access plus 30 days"
    ExpiresByType css/html "access plus 30 days"
    ExpiresByType css/css  "access plus 30 days"
    ExpiresByType images/gif "access plus 30 days"
    ExpiresByType images/png "access plus 30 days"
    ExpiresByType images/jpeg "access plus 30 days"
    ExpiresByType images/ico "access plus 30 days"
</IfModule>

通过mod_headers模块来设置Expires

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    Header set Cache-Control “max-age=604800, public”
</FilesMatch>
<FilesMatch "\.(xml|txt)$">
    Header set Cache-Control “max-age=18000, public, must-revalidate”
</FilesMatch>
<FilesMatch "\.(html|htm|php)$">
    Header set Cache-Control “max-age=3600, must-revalidate”
</FilesMatch> 
 

2014年4月18日 星期五

啟用Apache2 的mod_deflate(gzip)來壓縮網頁提高傳輸效能

http://yblog.org/archive/index.php/5318

啟用Apache2 的mod_deflate(gzip)來壓縮網頁提高傳輸效能
今天為了讓Apache 2能夠啟用網頁壓縮,本來是找有經驗的朋友幫忙看用mod_gzip來壓縮會不會比較好,畢竟gzip壓縮網頁輸出是很多人都在採用的技術。

後來翻Apache 2 Module mod_deflate 資料才 發現,原來很多人用mod_gzip其實是因為Apache 1.x系列沒有內建網頁壓縮技術,所以才去用的。Apache 2官方在開發的時候,就把網頁壓縮考慮進去,內建了mod_deflate這個模組,所以Apache 2就不需要使用到mod_gzip,但2者運作的原理頗為類似。

啟用mod_deflate這個網頁壓縮的模組,功能和效率和mod_gzip是差不多的,甚至還好一些,且不需要再另外找mod_gzip模組,apache 2就有內建,將模組前面的註解拿掉就可以使用。

yblog.org啟用後,所消耗的頻寬流量便下降許多,可以同時提供給更多人瀏覽頁面的頻寬資源,考量本站使用的文件格式後,實作的方法如下:
在http.conf檔案裡有關載入模組的地方,加上這一行:
LoadModule deflate_module modules/mod_deflate.so
接著,在http.conf檔案後面,加上這一段:
<ifmodule mod_deflate.c>
DeflateCompressionLevel 9
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE js css
</ifmodule>
這 樣的作法可以壓縮一般網頁中會用到的html、xml、php、css、js等格式檔案輸出,雖然會佔用掉伺服器處理器的一點點處理器時間,瀏覽者在接收 網頁資料時也會消耗極短暫的一點點處理器時間(短到使用者不可能察覺),不過卻可以大幅減少資料傳輸量,減少網路頻寬被吃掉的情形。

DeflateCompressionLevel 9是指壓縮程度的等級,從1到9,9是最高等級。據了解,這樣做最高可以減少8成大小的傳輸量(看檔案內容而定),最少也能夠節省一半。

DeflateCompressionLevel 預設可以採用 6 這個數值,以維持耗用處理器效能與網頁壓縮品質的平衡。

至於已經是壓縮過的圖片格式如jpg,音樂檔案如mp3、壓縮檔如zip之類的,就可以不需要再壓縮了,因為這種檔案你一開放伺服器傳輸時壓縮,處理器時間會跑不完。

有關這個mod_deflate的效能,這篇文章Apache 2 mod_deflate Benchmark分析得很好,也值得參考。

要檢查加上模組的成果,可以馬上透過這個網站來看看壓縮效率如何Real-Time Compression Check(已經失聯),我們來改用這個網站Check HTTP Compression來檢查。

以優格網首頁為例,25445 bytes變成7828 bytes,壓縮後的比例約省下了70%。而以永遠的真田幸村為例,首頁從69045 bytes變成18001 bytes,節省了74%,傳輸速度快了的3.8倍,不過處理速度沒有變慢。

至於Lighttpd這套也很紅的網頁伺服器軟體平台,也支援mod_deflate來壓縮網頁提高傳輸效能。

而微軟Window伺服器的IIS平台,IIS5得搭配外掛的模組才能實現壓縮功能,IIS6、IIS7則有內建,但壓縮的效能都沒有Apache系列好就是了。XD

2014年4月4日 星期五

Install PHP5, Apache, MySQL on Ubuntu

 http://www.howtogeek.com/howto/ubuntu/installing-php5-and-apache-on-ubuntu/


Install PHP5 and Apache on Ubuntu

sudo apt-get install apache2
(Note that if apache is already installed you can omit the first line. Your web files will now be found in /var/www/)

sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
(這會讓/etc/apache2/mods-enabled 新增php5的link)

sudo apt-get install mysql
sudo apt-get install php5-mysql

sudo /etc/init.d/apache2 restart

Ubuntu 上的Apache (使用apt-get安裝)



如果大家和阿舍剛從 Windows 轉過到 Ubuntu 來用的時候一樣的話,大概都會和阿舍有一個相同的疑問,那就是 "為什麼在 Ubuntu 上找不到 httpd.conf 檔哩 ??" 是啊 ! 阿舍當時在安裝完 Apache2 伺服器之後,就一直找不到阿舍要的設定檔哩 ! 然後,後來才知道,原來是因為 Ubuntu 上根本就不用 httpd.conf 這個檔案名稱哩 ! .... = = !!

在裝好 Apache2 之後,Apache2 的設定檔會存放在 /etc/apache2 資料夾下,在這個資料夾裡面有一個 apache2.conf 的檔案,這個 apache2.conf 檔案是針對整個 Apache2 的設定檔, 一般來說是不用去動它的,如果要調設定的話,是要到 /etc/apache2/sites-available 裡去調的,預設的網站是調 /etc/apache2/sites-available/default 這個檔案,而這個檔案就等同是在 windows 上的 httpd.conf 檔,只是命名方式很不同哩 !!

另外,你可能會發現,在 /etc/apache2 資料夾裡,除了有 /etc/apache2/sites-available 資料夾之外,還有一個長的很像的 /etc/apache2/sites-enabled 資料夾,這二個資料夾有什麼不同嗎 ?
其實是有的,只要是在 sites-available 資料夾的設定檔有用 a2ensite 指令啟用過的虛擬主機,就會被在 sites-enabled 資料夾來建立一個連回到 sites-available 資料夾設定檔的連結,來讓 Apache 知道那些設定檔有啟用了哩 !  ....