หน้าเว็บ

แสดงบทความที่มีป้ายกำกับ apache แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ apache แสดงบทความทั้งหมด

วันพุธที่ 28 ตุลาคม พ.ศ. 2552

Installing PHP5 and Apache on Ubuntu

Installing PHP5 and Apache on Ubuntu

Easy way to get PHP and Apache for running on Ubuntu.


From a command shell, you will run the following commands:

sudo apt-get install apache2

sudo apt-get install php5

sudo apt-get install libapache2-mod-php5

sudo /etc/init.d/apache2 restart


Note that if apache is already installed you can omit the first line. Your web files will now be found in /var/www/

Thanks : howtogeek.com


วันจันทร์ที่ 26 ตุลาคม พ.ศ. 2552

Introduction to Wamp Server

Apache, MySQL, PHP on Windows


WampServer is a Windows web development environment. It allows you to create web applications with Apache, PHP and the MySQL database. It also comes with PHPMyAdmin to easily manage your databases.

WampServer installs automatically (installer), and its usage is very intuitive. You will be able to tune your server without even touching the setting files.

WampServer is the only packaged solution that will allow you to reproduce your production server. Once WampServer is installed, you have the possibility to add as many Apache, MySQL and PHP releases as you want.

WampServer also has a trayicon to manage your server and its settings.




Includes :
- Apache 2.2.11
- MySQL 5.1.36
- PHP 5.3.0



Installing


Double click on the downloaded file and just follow the instructions. Everything is automatic. The WampServer package is delivered whith the latest releases of Apache, MySQL and PHP.

Once WampServer is installed, you can add other releases by downloading them on this website. They will then appear in the WampServer menu and you will be able to switch releases with a simple click.
Each release of Apache, MySQL and PHP has its own settings and its own files (datas for MySQL).

Functionalities


WampServer's functionalities are very complete and easy to use so we won't explain here how to use them.

With a left click on WampServer's icon, you will be able to:
- manage your Apache and MySQL services
- switch online/offline (give access to everyone or only localhost)
- install and switch Apache, MySQL and PHP releases
- manage your servers settings
- access your logs
- access your settings files
- create alias

With a right click :
- change WampServer's menu language
- access this page

How to start


When you install WampServer, a "www" directory is created (generally c:\wamp\www). Create a directory inside for your project and put your PHP files in it.
Click on the link "Localhost" in the WampServer menu or open your browser and open the http://localhost address.




Add Apache, MySQL and PHP releases


WampServer allows you to install almost all the existing releases of Apache, PHP and MySQL so you can reproduce exactly the settings of your production server.
To add a new release, donwload it here and install it.

Then click on the WampServer menu and activate the release that you want to use.



Wait until the WampServer icon become white again and start to work.


Downloads


WampServer is an open source project, free to use (GPL licence). If you think our work deserves it and you want to help us, you can make a donation with paypal.



Apache 2.2.11
PHP 5.3.0
MySQL 5.1.36
Phpmyadmin

size: 16Mo

Thanks : wampserver.com

วันจันทร์ที่ 27 กรกฎาคม พ.ศ. 2552

Mod_Rewrite in apache

Mod_Rewrite คือ การแปลง URL ที่ดูยากและยาว ให้อยู่ในรูปแบบที่เราต้องการ เพื่อที่ให้ง่ายต่อการเข้าถึง และการทำ SEO
เช่น
http://tn-home.blogspot.com/?page=Mod_Rewrite&Se0=1

เมื่อทำการแปลงจะทำให้เหลือสั้นลง
เช่น
http://tn-home.blogspot.com/page/mod_rewrite

ในการทำนั้นต้องทำการตรวจสอบ Apache server ด้วยว่าทำการลง Mod_Rewrite แล้วหรือยัง
ต่อมาทำการ ตรวจสอบไฟล์ .htaccess ซึ่งเราจะใช้ในการกำหนด Rule ของการทำ Mod_Rewrite

RewriteEngine on

หากต้องการทำ Redirects ก็สามารถทำได้ เช่น

RewriteEngine on
RewriteRule ^old\.html$ new.html [R]

คือทำการแทนที่ เว็บ old.html ด้วย new.html โดย ใช้ Regular expressions ในการตรวจสอบ โดยเมื่อพิมพ์ old.html ก็จะส่งไปยัง new.html แล้ว URL ก็จะเปลี่ยนเป็น new.html จะเห็นว่าที่กล่าวมาประกอบไปด้วย 4 ส่วนด้วยกันคือ
1. Rewrite ทำการบอกว่านี้คือ Rule
2. ^old\.html$ ทำการบอกว่านี้คือการตรวจสอบ
3. new.html คือ URL ใหม่ที่เราจะแปลงเป็นอันใหม่
4. [R] คือ Command Flag เป็นคำสั่งพิเศษกำหนดเงื่อนไข

Thanks : plingkratok

Protect Hotlink with mod_rewrite

ป้องการการ Hotlink ใน Apache ด้วย mod_rewrite

ปัญหา การขโมยแบนด์วิดธ์จากเว็บไซท์อื่น โดยการทำการ hot-link มารูปในเว็บไซท์ที่เราทำนั้น เป็นการเพิ่มภาระและใช้ทรัพยากรของเรา โดยที่เราเป็นผู้เสียผลประโยชน์ การแก้ปัญหานี้ในระบบ *nix ที่ใช้งาน apache สามารถทำได้โดย

ความต้องการเพื่อใช้งาน
  • apache ที่ติดตั้ง mod_rewrite
  • apache อนุญาตใช้งาน AllowOverride
  • apache อนุญาตใช้งาน FollowSymLinks
การทำงานสามารถทำได้โดย การสร้างไฟล์ .htaccess โดยการเขียนคำสั่งดังนี้

HTACCESS
  1. RewriteEngine on
  2. RewriteCond %{HTTP_REFERER} !^$
  3. RewriteCond %{HTTP_REFERER} !^(http://|https://)(www.)?(modoeye.com).*$ [NC]
  4. RewriteRule \.(jpe?g|gif|bmp|png)$ - [F]

จากโค๊ดข้างต้นสามารถอธิบายได้ดังนี้

HTACCESS
  1. RewriteEngine on

เป็นการสั่งให้ module mod_rewrite เริ่มทำงาน

HTACCESS
  1. RewriteCond %{HTTP_REFERER} !^$

เป็นการตรวจสอบค่าใน HTTP_REFERER ว่ามีค่าว่าง

HTACCESS
  1. RewriteCond %{HTTP_REFERER} !^(http://|https://)(www.)?(modoeye.com).*$ [NC]

เป็น การตรวจสอบค่าใน HTTP_REFERER ว่ามีค่าไม่ตรงกับ http://www.modoeye.com, https://www.modoeye.com, http://modoeye.com, https://modoeye.com โดย NC เป็นการระบุว่าตรวจสอบแบบไม่สนใจตัวพิมพ์ใหญ่หรือพิมพ์เล็ก (non case-sensitive:case-insensitive)

HTACCESS
  1. RewriteRule \.(jpe?g|gif|bmp|png)$ - [F]

เป็น การบอกว่าถ้ามีการเรียกมายังไฟล์ที่มี extension เป็น jpg, jpeg, gif, bmp และ png ให้ไม่มีการส่งข้อมูลใดๆไป ส่วน F เป็นการส่งเพียง header รหัส 403 (Forbidden) ไปยัง browser

หากเราต้องการเตือนให้ปลายทางรูปว่า เรารู้นะว่าคุณขโมยรูปของเรา เราสามารถส่งรูปที่เราต้องการไปยังปลายทางได้โดยการระบุรูปที่ต้องการ โดยจะได้โค๊ดทั้งหมดดังนี้

HTACCESS
  1. RewriteEngine on
  2. RewriteCond %{HTTP_REFERER} !^$
  3. RewriteCond %{HTTP_REFERER} !^(http://|https://)(www.)?(modoeye.com).*$ [NC]
  4. RewriteRule \.(jpe?g|gif|bmp|png|wav)$ images/steal.jpg [L]

ส่วนที่เปลี่ยนแปลงคือ

HTACCESS
  1. RewriteRule \.(jpe?g|gif|bmp|png|wav)$ images/steal.jpg [L]

เป็น การบอกว่ามีการเรียกมายังไฟล์ที่มี extension เป็น jpg, jpeg, gif, bmp และ png ให้ทำการส่งภาพ images/steal.jpg ไปแทน โดย L เป็นการบอกว่าเป็นกฎข้อสุดท้าย (Last rule)

Thanks : Sheroku

วันศุกร์ที่ 24 กรกฎาคม พ.ศ. 2552

20 ways to Secure your Apache Configuration

First, make sure you've installed latest security patches

There is no sense in putting locks on the windows, if your door is wide open. As such, if you're not patched up there isn't really much point in continuing any longer on this list. Go ahead and bookmark this page so you can come back later, and patch your server.

Hide the Apache Version number, and other sensitive information.

By default many Apache installations tell the world what version of Apache you're running, what operating system/version you're running, and even what Apache Modules are installed on the server. Attackers can use this information to their advantage when performing an attack. It also sends the message that you have left most defaults alone.

There are two directives that you need to add, or edit in your httpd.conf file:

ServerSignature Off
ServerTokens Prod

The ServerSignature appears on the bottom of pages generated by apache such as 404 pages, directory listings, etc.

The ServerTokens directive is used to determine what Apache will put in the Server HTTP response header. By setting it to Prod it sets the HTTP response header as follows:

Server: Apache

If you're super paranoid you could change this to something other than "Apache" by editing the source code, or by using mod_security (see below).

Make sure apache is running under its own user account and group

Several apache installations have it run as the user nobody. So suppose both Apache, and your mail server were running as nobody an attack through Apache may allow the mail server to also be compromised, and vise versa.

User apache
Group apache

Ensure that files outside the web root are not served

We don't want apache to be able to access any files out side of its web root. So assuming all your web sites are placed under one directory (we will call this /web), you would set it up as follows:


Order Deny,Allow
Deny from all
Options None
AllowOverride None


Order Allow,Deny
Allow from all

Note that because we set Options None and AllowOverride None this will turn off all options and overrides for the server. You now have to add them explicitly for each directory that requires an Option or Override.

Turn off directory browsing

You can do this with an Options directive inside a Directory tag. Set Options to either None or -Indexes

Options -Indexes

Turn off server side includes

This is also done with the Options directive inside a Directory tag. Set Options to either None or -Includes

Options -Includes

Turn off CGI execution

If you're not using CGI turn it off with the Options directive inside a Directory tag. Set Options to either None or -ExecCGI

Options -ExecCGI

Don't allow apache to follow symbolic links

This can again can be done using the Options directive inside a Directory tag. Set Options to either None or -FollowSymLinks

Options -FollowSymLinks

Turning off multiple Options

If you want to turn off all Options simply use:

Options None

If you only want to turn off some separate each option with a space in your Options directive:

Options -ExecCGI -FollowSymLinks -Indexes

Turn off support for .htaccess files

This is done in a Directory tag but with the AllowOverride directive. Set it to None.

AllowOverride None

If you require Overrides ensure that they cannot be downloaded, and/or change the name to something other than .htaccess. For example we could change it to .httpdoverride, and block all files that start with .ht from being downloaded as follows:

AccessFileName .httpdoverride

Order allow,deny
Deny from all
Satisfy All

Run mod_security

mod_security is a super handy Apache module written by Ivan Ristic, the author of Apache Security from O'Reilly press.

You can do the following with mod_security:

  • Simple filtering
  • Regular Expression based filtering
  • URL Encoding Validation
  • Unicode Encoding Validation
  • Auditing
  • Null byte attack prevention
  • Upload memory limits
  • Server identity masking
  • Built in Chroot support
  • And more

Disable any unnecessary modules

Apache typically comes with several modules installed. Go through the apache module documentation and learn what each module you have enabled actually does. Many times you will find that you don't need to have the said module enabled.

Look for lines in your httpd.conf that contain LoadModule. To disable the module you can typically just add a # at the beginning of the line. To search for modules run:

grep LoadModule httpd.conf

Here are some modules that are typically enabled but often not needed: mod_imap, mod_include, mod_info, mod_userdir, mod_status, mod_cgi, mod_autoindex.

Make sure only root has read access to apache's config and binaries

This can be done assuming your apache installation is located at /usr/local/apache as follows:

chown -R root:root /usr/local/apache
chmod -R o-rwx /usr/local/apache

Lower the Timeout value

By default the Timeout directive is set to 300 seconds. You can decrease help mitigate the potential effects of a denial of service attack.

Timeout 45

Limiting large requests

Apache has several directives that allow you to limit the size of a request, this can also be useful for mitigating the effects of a denial of service attack.

A good place to start is the LimitRequestBody directive. This directive is set to unlimited by default. If you are allowing file uploads of no larger than 1MB, you could set this setting to something like:

LimitRequestBody 1048576

If you're not allowing file uploads you can set it even smaller.

Some other directives to look at are LimitRequestFields, LimitRequestFieldSize and LimitRequestLine. These directives are set to a reasonable defaults for most servers, but you may want to tweak them to best fit your needs. See the documentation for more info.

Limiting the size of an XML Body

If you're running mod_dav (typically used with subversion) then you may want to limit the max size of an XML request body. The LimitXMLRequestBody directive is only available on Apache 2, and its default value is 1 million bytes (approx 1mb). Many tutorials will have you set this value to 0 which means files of any size may be uploaded, which may be necessary if you're using WebDAV to upload large files, but if you're simply using it for source control, you can probably get away with setting an upper bound, such as 10mb:

LimitXMLRequestBody 10485760

Limiting Concurrency

Apache has several configuration settings that can be used to adjust handling of concurrent requests. The MaxClients is the maximum number of child processes that will be created to serve requests. This may be set too high if your server doesn't have enough memory to handle a large number of concurrent requests.

Other directives such as MaxSpareServers, MaxRequestsPerChild, and on Apache2 ThreadsPerChild, ServerLimit, and MaxSpareThreads are important to adjust to match your operating system, and hardware.

Restricting Access by IP

If you have a resource that should only by accessed by a certain network, or IP address you can enforce this in your apache configuration. For instance if you want to restrict access to your intranet to allow only the 176.16 network:


Order Deny,Allow
Deny from all
Allow from 176.16.0.0/16

Or by IP:

Order Deny,Allow
Deny from all
Allow from 127.0.0.1

Adjusting KeepAlive settings

According to the Apache documentation using HTTP Keep Alive's can improve client performance by as much as 50%, so be careful before changing these settings, you will be trading performance for a slight denial of service mitigation.

KeepAlive's are turned on by default and you should leave them on, but you may consider changing the MaxKeepAliveRequests which defaults to 100, and the KeepAliveTimeout which defaults to 15. Analyze your log files to determine the appropriate values.

Run Apache in a Chroot environment

chroot allows you to run a program in its own isolated jail. This prevents a break in on one service from being able to effect anything else on the server.

It can be fairly tricky to set this up using chroot due to library dependencies. I mentioned above that the mod_security module has built in chroot support. It makes the process as simple as adding a mod_security directive to your configuration:

SecChrootDir /chroot/apache

There are however some caveats however, so check out the docs for more info.

Thanks : www.petefreitag.com