Showing posts with label LAMP. Show all posts
Showing posts with label LAMP. Show all posts

HOWTO : Secure Socket Layer (SSL) for LAMP on Ubuntu 9.04 Server

Enable the mod_ssl module.

sudo a2enmod ssl


Edit the default or copy the default to another file for editing.

sudo nano /etc/apache2/sites-available/default

Add the following inside the mod_rewrite.c bracket.

RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}%{REQUEST_URI} [R]

Enable the default-ssl site.

sudo a2ensite default-ssl

Restart apache to reload the setting and make it active.

sudo /etc/init.d/apache2 restart

That's all. See you!

HOWTO : Performance tuning of LAMP and Ubuntu 9.04 Server

Performance tuning of LAMP

Step 1:

To control the bandwidth and allow faster cgi browsing, you should install the following modules.

sudo apt-get install libapache2-mod-bw libapache2-mod-fastcgi



Step 2 :

sudo a2enmod deflate

sudo nano /etc/apache2/conf.d/deflate.conf


Add the following lines at the file.


   DeflateCompressionLevel 6
   AddOutputFilterByType DEFLATE text/plain
   AddOutputFilterByType DEFLATE text/html
   AddOutputFilterByType DEFLATE text/xml
   AddOutputFilterByType DEFLATE text/css
   AddOutputFilterByType DEFLATE application/xhtml+xml
   AddOutputFilterByType DEFLATE application/xml
   AddOutputFilterByType DEFLATE application/rss+xml
   AddOutputFilterByType DEFLATE application/atom_xml
   AddOutputFilterByType DEFLATE application/x-javascript
   AddOutputFilterByType DEFLATE application/x-httpd-php
   AddOutputFilterByType DEFLATE application/x-httpd-fastphp
   AddOutputFilterByType DEFLATE application/x-httpd-eruby
   AddOutputFilterByType DEFLATE image/svg+xml
   AddOutputFilterByType DEFLATE application/postscript
   
      Header append Vary User-Agent
   

sudo /etc/init.d/apache2 restart

Step 3 :

wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2

tar xvf eaccelerator-0.9.5.3.tar.bz2

sudo apt-get install build-essential php5-dev

cd eaccelerator-0.9.5.3
phpize
./configure
make
sudo make install

sudo mkdir /tmp/eaccelerator
sudo chmod 0777 /tmp/eaccelerator

Step 4 :

sudo nano /etc/php5/apache2/php.ini

Append the following lines at the end of the file.

extension="eaccelerator.so"
; shm_size default is 16, you may change to 64 or 128 depends on your RAM
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

sudo /etc/init.d/apache2 restart


Performance tuning of Ubuntu 9.04 Server

Step 5 :

sudo nano /etc/sysctl.conf


Append the following lines at the end of the file.

kernel.sem = 250 32000 100 128
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
# If you have more than 512MB RAM, use this setting (uncomment it and comment the setting just below)
#fs.file-max = 262140
# If you have 512MB RAM or less, use this setting
fs.file-max = 65535
vm.swappiness = 1
vm.vfs_cache_pressure = 50
vm.min_free_kbytes = 65536

net.core.rmem_default = 33554432
net.core.rmem_max = 33554432
net.core.wmem_default = 33554432
net.core.wmem_max = 33554432
net.ipv4.tcp_rmem = 10240 87380 33554432
net.ipv4.tcp_wmem = 10240 87380 33554432
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_sack = 1
net.core.netdev_max_backlog = 5000
net.ipv4.tcp_mem = 786432 1048576 26777216
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_max_tw_buckets = 360000

sudo /sbin/sysctl -p


Step 6 :

sudo nano /etc/rc.local

Add the following lines before "exit 0".

echo 1024 > /sys/block/sda/queue/read_ahead_kb
echo 256 > /sys/block/sda/queue/nr_requests

*The captioned lines are for sda only.

Step 7 :

sudo nano /etc/fstab


Add "noatime" before "relatime". For example :

UUID=0e57987f-...... / ext3 noatime,relatime,errors=remount-ro 0 1

or

UUID=0e57987f-...... / ext4 noatime,relatime,errors=remount-ro 0 1


sudo mount -a


If there is no error message, you can now reboot your system.

That's all. See you!

HOWTO : Hardening your Apache and PHP on Ubuntu 9.04 Server

You have installed LAMP and OpenSSH on your Ubuntu 9.04 Server. The first thing to do is to harden it in order to avoid some kind of attacks.

You can do the following steps in front of your Ubuntu 9.04 Server or remote access it via OpenSSH.

For OpenSSH, your Ubuntu 9.04 Server is at 192.168.0.10 :

ssh 192.168.0.10 -l samiux


Step 1 :

The avoid someone to list your files on your Apache directory, you should do the following step.

sudo nano /etc/apache2/sites-available/default


Add a minus "-" in the front of "Indexes" and it will looking like this :


    Options -Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all


Step 2 :

To enable the rewrite module of Apache.

sudo a2enmod rewrite


To avoid Cross-Site-Tracing attack. Add the following lines within " " :


    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
    RewriteRule .* - [F]


Step 3 :

To avoid HTTP DoS, DDoS or Brute Force attack, you should install this module.

sudo apt-get install libapache2-mod-evasive


Step 4 :

To screen out bad URL requests, such as /etc/shadow or MySQL injection and etc. You should install mod_security module. If you installed a amd64 (64-bit) version of Ubuntu Server, please replaced i386 with amd64 for the following commands.

wget http://etc.inittab.org/~agi/debian/libapache-mod-security2/libapache-mod-security_2.5.9-1_i386.deb

wget http://etc.inittab.org/~agi/debian/libapache-mod-security2/mod-security-common_2.5.9-1_all.deb

sudo dpkg -i libapache-mod-security_2.5.9-1_i386.deb mod-security-common_2.5.9-1_all.deb

Step 5 :

Do not allow any Apache and Ubuntu Server information to be print on the error pages.

sudo nano /etc/apache2/conf.d/security


Change the following lines as the following :

ServerToken Prod
ServerSignature Off

Step 6 :

Now, it is time to harden the PHP.

sudo nano /etc/php5/apache2/php.ini


Change the following lines as the following :

display_errors = Off
log_errors = On
allow_url_fopen = Off
safe_mode = On
expose_php = Off
enable_dl = Off
disable_functions = system, show_source, symlink, exec, dl, shell_exec, passthru, phpinfo, escapeshellarg, escapeshellcmd


Step 7 :

Final step is to restart Apache server.

sudo /etc/init.d/apache2 restart

Step 8 :

sudo nano /etc/sysctl.conf
Uncomment the following line and make it look like this.

#Enable TCP SYN Cookie Protection
net.ipv4.tcp_syncookies = 1

Make the change active.

sudo /sbin/sysctl -p


That's all. See you!

HOWTO : Install Ubuntu 9.04 Server

Introduction

Ubuntu is one of the most user-friendly Linux in the world so far. Not only her Desktop edition is user-friendly but so her Server edition. The current version of Ubuntu Desktop and Server edition is 9.04 at the time of this writing.

9.04 stands for released on April 2009. The next version will be 9.10, that is October 2009. Normally, she will release new version on every April and October. However, there is an exceptional. It is 6.06 which is released on June 2006 due to delay of bugs fix.

Hardware requirements

I suggest you have at least a Pentium 4 CPU with 512MB RAM and 40GB hard drive. For the minimum hardware requirement, please see her official site.

You can also install it on VMWare, Linux KVM (Kernal based Virtual Machine) or VirtualBox. It is running flawlessly on them.

Installation of Ubuntu 9.04 Server

Now, I am going to talk about how to install Ubuntu Server 9.04. First of all, you should download Ubuntu 9.04 from her official site. Burn the .iso file as disk image with your disc burning software, such as Nero (in Windows) or K3b (in Linux). Please do not extract the files from the .iso or just burn the file directly on a CD-R.

I suggest to change the ext3 filesystem to ext4 as it is much faster and it will be the next generation of Linux default filesystem. Selects LVM on the entire disk when asking. You may ask for entering user name and password. Please use a more complicated password which should includes uppercase and lowercase letters, numbers and symbols. In addition, it should be longer than 8 characters.

At the end of installation, you may asked to select some servers to install, such as LAMP, mail server, OpenSSH, virtual machine and etc. If you want to build a web server, I suggest you select LAMP, mail server and OpenSSH. I assumed you install LAMP, mail server and OpenSSH as it will be discussed in future tutorials of mine.

Make sure you are connecting to the internet while you are installing Ubuntu. The system will be reboot after the install.

That's all. See you!