Complete Nginx On Ubuntu/Debian

Since Apache is most of the time a memory hungy process, people started to look for different ways to host their website. Apache is clearly not the only webserver available. A few good examples are lighttpd and nginx. In this tutorial I will show you how to install it on your Ubuntu server. This tutorial also applies to Debian, though. There is only a very small difference.

Ready? Let’s begin.

Step 0 – Preliminary Notes

In order to complete this tutorial, I assume you have installed a base system of Debian or Ubuntu. How this can be done, can be read in different tutorials. This tutorial only focusses on getting nginx+php running without much hassle.

Step 1 – Nginx

Installing nginx is the first step we have to do. This can be easily done by downloading it from the repository.

sudo apt-get install nginx

The default vhost has to be changed in order to work properly.

sudo vim /etc/nginx/sites-available/default

A nice starting point for your config is:

server {
listen 80;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;

## Default location
location / {
root /var/www;
index index.php;
}

## Images and static content is treated different
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 30d;
root /var/www;
}

## Parse all .php file in the /var/www directory
location ~ .php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}

## Disable viewing .htaccess & .htpassword
location ~ /\.ht {
deny all;
}
}
upstream backend {
server 127.0.0.1:9000;
}

Ok, we’re done here. Now we’ll install the needed files for PHP.

Step 3 – Now let’s install PHP with FPM:


apt-get install python-software-properties
add-apt-repository ppa:brianmercer/php
apt-get update
apt-get install php5-fpm php-apc php5-cgi php5-cli php5-mysql php5-common php-pear php5-curl php5-suhosin php5-gd php5-imagick imagemagick

echo "apc.shm_size = 64" >> /etc/php5/conf.d/apc.ini
echo "apc.rfc1867 = on" >> /etc/php5/conf.d/apc.ini
sed -i'.original' 's/^# configuration for php imagick module/; configuration for php imagick module/' /etc/php5/conf.d/imagick.ini
/etc/init.d/php5-fpm restart
/etc/init.d/nginx/restart

Step 4 – Installing MySql Server on Ubuntu is a very simple task:

sudo apt-get install mysql-server mysql-client

One useful utility is the mysql_secure_installation script, which limits access to the ‘root’ account, removes the test database, and removes anonymous accounts.

mysql_secure_installation

Restart the MySQL Server:

/etc/init.d/mysql restart

Step 5 -  Postfix

In order to use the mail function you should also install the Postfix server:

sudo apt-get install postfix

++++++++++++++++++++++++++++++++++++++++++++++++++++++
General type of mail configuration: <-- Internet Site
System mail name: <-- server.basoro.org

++++++++++++++++++++++++++++++++++++++++++++++++++++++

For a null client (a server that only sends emails), you replace the existing /etc/postfix/main.cf file with the following:

myorigin = $mydomain
relayhost =
inet_interfaces = loopback-only
local_transport = error:local delivery is disabled
smtpd_banner = $myhostname ESMTP $mail_name
alias_maps = hash:/etc/aliases
message_size_limit = 104857600

Edit also the /etc/aliases file accordingly:

admin: root
root: basoro@basoro.org

Make changes permanent with:

newaliases
/etc/init.d/postfix restart

Step 6 – Install DJBDNS

Asums:
Domain: basoro.org
Another domain: basoro.com
IP Server: 192.168.0.254

wget http://www.djbdnsrocks.org/downloads/djbdnsrocks.tar.gz
sudo aptitude install -R build-essential

i. Install Daemontools

# mkdir -p /var/package
# chmod 1755 /var/package
# cd /var/package
# tar zxvf daemontools-0.76.tar.gz
# cd admin
# cd daemontools-0.76
# patch -p1 < daemontools_errnopatch
# package/install

ii. Install ucspi-tcp

# cd /tmp
# tar zxvf ucspi-tcp-0.88.tar.gz
# cd ucspi-tcp-0.88
# patch -p1 &1 | \

Start svscan

sudo tee /etc/init/svscanstarter.conf <<-\EOA
# /etc/init/svscanstarter.conf
# svscanstarter - keep up daemontools 'svscan /var/service'
description "svscanstarter keep up daemontools"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /var/command/svscanboot
EOA

sudo start svscanstarter # to stop it use: sudo stop svscanstarter
sudo status svscanstarter # check status
ps -ef | sed '/!d/d;/svscan/!d' # check svscanboot/svscan processes

iv. Edit /etc/resolv.conf

– Add in –

domain basoro.org
nameserver 192.168.0.254

v. Preparing for djbdns

# mkdir /var/dns
# groupadd dns
# useradd dnscache -g dns -d /var/dns -s /bin/false
# useradd dnslog -g dns -d /var/dns -s /bin/false
# useradd dns -g dns -d /var/dns -s /bin/false

vi. Install djbdns

# cd /tmp
# tar xvzf djbdns-1.05.tar.gz
# cd djbdns-1.05
# patch -p1 /var/dns/dnscache/root/servers/basoro.org
# echo 127.0.0.1 > /var/dns/dnscache/root/servers/basoro.com
# echo 127.0.0.1 > /var/dns/dnscache/root/servers/1.0.0.127.in-addr.arpa
# echo 127.0.0.1 > /var/dns/dnscache/root/servers/0.168.192.in-addr.arpa

ix. Forwarding ISP external cache

# echo 202.134.1.10 > /var/dns/dnscache/root/servers/@
# echo 202.134.0.155 >> /var/dns/dnscache/root/servers/@
# echo 1 > /var/dns/dnscache/env/FORWARDONLY
# echo 1000000 > /var/dns/dnscache/env/CACHESIZE
# echo 3000000 > /var/dns/dnscache/env/DATALIMIT
# svc -t /var/service/dnscache

Testing :

# dnsqr a www.basoro.com
1 www.basoro.com:
54 bytes, 1+1+0+0 records, response, noerror
query: 1 www.basoro.com
answer: www.basoro.com 86168 A 192.168.0.254

Maintain SVC

Restart Service
# svc -t /var/dns/dnscache

Stop
# svc -d /var/dns/dnscache

Done…!!!

How To Share Dialup Internet Connection On Ubuntu Server

This article explain how to share your dialup internet connection on ubuntu linux. Just to share with the other. Here you are.

1. Change your statict network interface. In this example is eth1.
# vim /etc/network/interfaces

auto eth1
iface eth1 inet static
address 192.168.0.254
netmask 255.255.255.0
broadcast 192.168.0.255

where eth1 is the network card and ip is your desired server ip address. I used 192.168.0.254 as IP Address.

2. Configure the NAT:

# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

where ppp0 is the network card that the Internet is coming from. Use ppp0 for dialup connection.

# echo 1 > /proc/sys/net/ipv4/ip_forward

3. Install dnsmasq and ipmasq using apt-get:

# apt-get install dnsmasq ipmasq

4. Reconfigure ipmasq to start after networking has been started:

# dpkg-reconfigure ipmasq

5. Add the line “net.ipv4.ip_forward = 1″ to /etc/sysctl.conf

# vim /etc/sysctl.conf

6. Set your client DNS to 192.168.0.254

How to recover images from formatted memory card

A few days ago, My friend’s SD card accidentally formatted. While in the SD card is a memorable photographs of the birth of their first son. To restore these photos I recommend to use the recovery tool. To find the recovery tool, I told him to look for in google.

There are some recovery tools that are used. All are Windows programs. However, none of which succeeded. This is because the tool is a trial version. Meanwhile, to get the full version required to buy it. Fortunately I have a Ubuntu Linux machine which Ubuntu Lucid Lynx LTS upgrade from Ubuntu LTS Hardy Heron, minimal installation with LXDE. And finally my friend’s problem could be solved with the help of my Ubuntu Linux machine.

Here are some things you need to do with simple commands. This tutorial is written for Ubuntu GNU/Linux, but should be similar for most Linux machines.

1. Make a copy of the image of your SD card.
sudo dd if=/dev/sdb of=SDCARD-backup.img bs=1M

2. Install recoverjpeg package via apt-get
sudo apt-get install recoverjpeg

3. Run the command below.
$ recoverjpeg SDCARD-backup.img
Restored 398 pictures

The pictures that have been recovered will be stored in a folder. Please see the recovery that have been made. Good luck … Go Opensource .