Category Archives: Open Source

Robots.txt

Web site owners use the /robots.txt file to give instructions about their site to web robots; this is called The Robots Exclusion Protocol.

It works likes this: a robot wants to vists a Web site URL, say http://www.example.com/welcome.html. Before it does so, it firsts checks for http://www.example.com/robots.txt, and finds:

User-agent: *
Disallow: /

The “User-agent: *” means this section applies to all robots. The “Disallow: /” tells the robot that it should not visit any pages on the site.

There are two important considerations when using /robots.txt:

  • robots can ignore your /robots.txt. Especially malware robots that scan the web for security vulnerabilities, and email address harvesters used by spammers will pay no attention.
  • the /robots.txt file is a publicly available file. Anyone can see what sections of your server you don’t want robots to use.

So don’t try to use /robots.txt to hide information.

How to create a /robots.txt file

Where to put it

The short answer: in the top-level directory of your web server.

The longer answer:

When a robot looks for the “/robots.txt” file for URL, it strips the path component from the URL (everything from the first single slash), and puts “/robots.txt” in its place.

For example, for “http://www.example.com/shop/index.html, it will remove the “/shop/index.html“, and replace it with “/robots.txt“, and will end up with “http://www.example.com/robots.txt”.

So, as a web site owner you need to put it in the right place on your web server for that resulting URL to work. Usually that is the same place where you put your web site’s main “index.html” welcome page. Where exactly that is, and how to put the file there, depends on your web server software.

Remember to use all lower case for the filename: “robots.txt“, not “Robots.TXT.

What to put in it

The “/robots.txt” file is a text file, with one or more records. Usually contains a single record looking like this:

To exclude all robots from the entire server
User-agent: *
Disallow: /
To allow all robots complete access
User-agent: *
Disallow:

(or just create an empty “/robots.txt” file, or don’t use one at all)

To exclude all robots from part of the server
User-agent: *
Disallow: /cgi-bin/
Disallow: /tmp/
Disallow: /junk/
To exclude a single robot
User-agent: BadBot
Disallow: /
To allow a single robot
User-agent: Google
Disallow:

User-agent: *
Disallow: /
To exclude all files except one

This is currently a bit awkward, as there is no “Allow” field. The easy way is to put all files to be disallowed into a separate directory, say “stuff”, and leave the one file in the level above this directory:

User-agent: *
Disallow: /~joy/stuff/

Alternatively you can explicitly disallow all disallowed pages:

User-agent: *
Disallow: /~joy/junk.html
Disallow: /~joy/foo.html
Disallow: /~joy/bar.html.

How to protect file with HTAccess

Protection with htaccess is an important way to protect your files from unwanted access. Most people  protect an entire directory or website, you can also protect files with password.

Here’s How:

Example:

I want to protect file “password.ini”

path = /var/www/html/mydomain.com/password.ini

Go to cd /var/www/html/mydomain.com

Open a new text file called .htaccess

  1. .htaccess
  2. Add the following to the file:

<Files “password.ini”>
deny from all
</Files>

save it.

now go to your browser and type, http://mydomain.com/password.ini

Forbidden ,You don’t have permission to access /password.ini  on this server.!!!

How to install Java 6 Manually on ubuntu 12.04/12.10

There are many applications, which still require java 6, this tutorial is how to uninstall existing java  and install java 6.

You will find many methods to install java / jre/ jvm on web and thus it can be very much confusing to a user which method to use. Given there are many implementations of Java available, adds to the confusion. The different implementations of JDK available are:

  1. Java from Oracle (earlier provided by Sun which has been acquired by Oracle
  2. Java available from IBM
  3. OpenJDK
  4. GNU’s JDK

There is a possibility that already java may installed on your system,

Please check with the following commands,

Java –version

dpkg –list | grep jdk

dpkg –list | grep jre

Remove OpenJDK

Command: “sudo apt-get purge openjdk-\*

Download the jdk binary from oracles website and follow the steps below:

chmod u+x jdk-6u34-linux-i586.bin

./jdk-6u34-linux-i586.bin

sudo mkdir -p /usr/lib/jvm

sudo mv jdk1.6.0_34 /usr/lib/jvm/

sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/jre1.6.0_30/bin/java” 1

sudo update-alternatives –install “/usr/bin/javac” “javac” “/usr/lib/jvm/jre1.6.0_30/bin/javac” 1

sudo update-alternatives –install “/usr/lib/mozilla/plugins/libjavaplugin.so” “mozilla-javaplugin.so” “/usr/lib/jvm/jre1.6.0_30/lib/amd64/libnpjp2.so” 1

“sudo update-alternatives –install “/usr/bin/javaws” “javaws” “/usr/local/java/jdk1.6.0_45/bin/javaws” 1″

vim /etc/profile

JAVA_HOME=/usr/lib/jvm/jre1.6.0_30/
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
JRE_HOME=/usr/lib/jvm/jre1.6.0_30/
PATH=$PATH:$HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

Reload profile

./etc/profile

Now check

java -version
java version “1.6.0_30″
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)

Login to browser,

http://javatester.org/

check ur java version,

if u see error like browser has java disabled, then follow this,

For Firefox,
Open Tools/Add-ons/Plugins (Keyboard shortcut is Shift+Ctrl+A) and find it on the list. Click the ‘Disable’ button to the right of it to disable the plugin. (Note that I’ve never bothered installing it so it’s not present in my screenshot. If you have it installed you will see it here.)

FF plugins

 

 

CHAPTER 5 : ESSENTIAL LINUX COMMANDS : TAR

Syntax:

tar [options] [tar-archive-name] [other-file-names]

How can I create a single backup file of all files and
subdirectories under my home directory?
The following command creates a single archive backup file called
my_home_directory.tar under /tmp. This archive will contain all the files and subdirectories under /home/jsmith.

• Option c, stands for create an archive.
• Option v stands for verbose mode, displays additional
information while executing the command.
• Option f indicates the archive file name mentioned in the

command.

# tar cvf /tmp/my_home_directory.tar /home/jsmith

How do I view all the files inside the tar archive?
Option t will display all the files from the tar archive.# tar tvf /tmp/my_home_directory.tar

How do I extract all the files from a tar archive?
Option x will extract the files from the tar archive as shown below. This
will extract the content to the current directory location from where the
command is executed.
# tar xvf /tmp/my_home_directory.tar

How do I extract tar.gz files to a specific directory?
# tar xvfz /tmp/my_home_directory.tar.gz –C /home/ramesh

How to use gzip with tar?
Add option z to the tar command when dealing with tar.gz compressed
file.
# tar cvfz /tmp/my_home_directory.tar.gz /home/jsmith
# tar xvfz /tmp/my_home_directory.tar.gz
# tar tvfz /tmp/my_home_directory.tar.gz

Note: Using gzip is faster when compared to bzip2.

How to use bzip2 with tar?
Add option j to the tar command when dealing with tar.bz2 compressed
file.
# tar cvfj /tmp/my_home_directory.tar.bz2 /home/jsmith
# tar xvfj /tmp/my_home_directory.tar.bz2
# tar tvfj /tmp/my_home_directory.tar.bz2

Note: Using bizp2 gives higher level of compression when compared to gzip.

CHAPTER 4 : ESSENTIAL LINUX COMMANDS : DATE

Set System Date and Time

To change the system date use:
# date {mmddhhmiyyyy.ss}
• mm – Month
• dd – Date
• hh – 24 hour format
• mi – Minutes
• yyyy – Year
• ss – seconds
For example, to set system date to Jan 31st 2009, 10:19 p.m, 53
seconds
# date 013122192009.53
You can also change system date using set argument as shown below.
# date 013122192009.53
# date +%Y%m%d -s “20090131”
# date -s “01/31/2009 22:19:53″
# date -s “31 JAN 2009 22:19:53″
# date set=”31 JAN 2009 22:19:53″

To set the time only:
# date +%T -s “22:19:53″
# date +%T%p -s “10:19:53PM”

Display Date and Time in a Specific Format

The following are different ways of displaying the current date and time
in various formats:
$ date
Thu Jan 1 08:19:23 PST 2009
$ date –date=”now”
Thu Jan 1 08:20:05 PST 2009
$ date –date=”today”
Thu Jan 1 08:20:12 PST 2009
$ date –date=’1970-01-01 00:00:01 UTC +5 hours’ +%s
18001
$ date ‘+Current Date: %m/%d/%y%nCurrent Time:%H:%M:%S’
Current Date: 01/01/09
Current Time:08:21:41
$ date +”%d-%m-%Y”
01-01-2009

The following are the different format options you can pass to the date
command:
• %D date (mm/dd/yy)
• %d day of month (01..31)
• %m month (01..12)
• %y last two digits of year (00..99)
• %a locale’s abbreviated weekday name (Sun..Sat)
• %A locale’s full weekday name, variable length
(Sunday..Saturday)
• %b locale’s abbreviated month name (Jan..Dec)
• %B locale’s full month name, variable length
(January..December)
• %H hour (00..23)
• %I hour (01..12)
• %Y year (1970…)

Display Past Date and Time

The following are various ways to display a past date and time:
$ date –date=’3 seconds ago’
Thu Jan 1 08:27:00 PST 2009
$ date –date=”1 day ago”
Wed Dec 31 08:27:13 PST 2008
$ date –date=”1 days ago”
Wed Dec 31 08:27:18 PST 2008
$ date –date=”1 month ago”
Mon Dec 1 08:27:23 PST 2008

$ date –date=”1 year ago”
Tue Jan 1 08:27:28 PST 2008
$ date –date=”yesterday”
Wed Dec 31 08:27:34 PST 2008
$ date –date=”10 months 2 day ago”
Thu Feb 28 08:27:41 PST 2008

Display Future Date and Time

The following examples shows how to display a future date and time.
$ date
Thu Jan 1 08:30:07 PST 2009
$ date –date=’3 seconds’
Thu Jan 1 08:30:12 PST 2009
$ date –date=’4 hours’
Thu Jan 1 12:30:17 PST 2009
$ date –date=’tomorrow’
Fri Jan 2 08:30:25 PST 2009
$ date –date=”1 day”
Fri Jan 2 08:30:31 PST 2009
$ date –date=”1 days”
Fri Jan 2 08:30:38 PST 2009
$ date –date=”2 days”

Sat Jan 3 08:30:43 PST 2009
$ date –date=’1 month’
Sun Feb 1 08:30:48 PST 2009
$ date –date=’1 week’
Thu Jan 8 08:30:53 PST 2009
$ date –date=”2 months”
Sun Mar 1 08:30:58 PST 2009
$ date –date=”2 years”
Sat Jan 1 08:31:03 PST 2011
$ date –date=”next day”
Fri Jan 2 08:31:10 PST 2009
$ date –date=”-1 days ago”
Fri Jan 2 08:31:15 PST 2009
$ date –date=”this Wednesday”
Wed Jan 7 00:00:00 PST 2009.

CHAPTER 3 : ESSENTIAL LINUX COMMANDS : SORT : UNIQ : CUT

Sort Command
Sort command sorts the lines of a text file. Following are several
practical examples on how to use the sort command based on the
following sample text file that has employee information in the format:
employee_name:employee_id:department_name.
$ cat names.txt
Emma Thomas:100:Marketing
Alex Jason:200:Sales
Madison Randy:300:Product Development
Sanjay Gupta:400:Support
Nisha Singh:500:Sales
Sort a text file in ascending order
$ sort names.txt
Alex Jason:200:Sales
Emma Thomas:100:Marketing
Madison Randy:300:Product Development
Nisha Singh:500:Sales
Sanjay Gupta:400:Support
Sort a text file in descending order
$ sort -r names.txt
Sanjay Gupta:400:Support
Nisha Singh:500:Sales
Madison Randy:300:Product Development
Emma Thomas:100:Marketing
Alex Jason:200:Sales
Sort a colon delimited text file on 2nd field (employee_id)
$ sort -t: -k 2 names.txt
Emma Thomas:100:Marketing
Alex Jason:200:Sales
Madison Randy:300:Product Development
Sanjay Gupta:400:Support
Nisha Singh:500:Sales
Sort a tab delimited text file on 3rd field (department_name) and
suppress duplicates
$ sort -t: -u -k 3 names.txt
Emma Thomas:100:Marketing
Madison Randy:300:Product Development
Alex Jason:200:Sales
Sanjay Gupta:400:Support
Sort the passwd file by the 3rd field (numeric userid)
$ sort -t: -k 3n /etc/passwd | more
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin

lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
Sort /etc/hosts file by ip-address
$ sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n /etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.100.101 dev-db.thegeekstuff.com dev-db
192.168.100.102 prod-db.thegeekstuff.com prod-db
192.168.101.20 dev-web.thegeekstuff.com dev-web
192.168.101.21 prod-web.thegeekstuff.com prod-web
Combine sort with other commands
• ps –ef | sort : Sort the output of process list
• ls -al | sort +4n : List the files in the ascending order of the filesize.
i.e sorted by 5th filed and displaying smallest files first.
• ls -al | sort +4nr : List the files in the descending order of the
file-size. i.e sorted by 5th filed and displaying largest files first.

Uniq Command
Uniq command is mostly used in combination with sort command, as
uniq removes duplicates only from a sorted file. i.e In order for uniq to
work, all the duplicate entries should be in the adjacent lines. The
following are some common examples.
1. When you have an employee file with duplicate entries, you can do
the following to remove duplicates.
$ sort namesd.txt | uniq
$ sort –u namesd.txt

2. If you want to know how many lines are duplicates, do the following.
The first field in the following examples indicates how many duplicates
where found for that particular line. So, in this example the lines
beginning with Alex and Emma were found twice in the namesd.txt file.
$ sort namesd.txt | uniq –c
2 Alex Jason:200:Sales
2 Emma Thomas:100:Marketing
1 Madison Randy:300:Product Development
1 Nisha Singh:500:Sales
1 Sanjay Gupta:400:Support
3. The following displays only the entries that are duplicates.
$ sort namesd.txt | uniq –cd
2 Alex Jason:200:Sales
2 Emma Thomas:100:Marketing

Cut Command
Cut command can be used to display only specific columns from a text
file or other command outputs.
The following are some of the examples.
Display the 1st field (employee name) from a colon delimited file
$ cut -d: -f 1 names.txt
Emma Thomas
Alex Jason
Madison Randy
Sanjay Gupta
Nisha Singh

Display 1st and 3rd field from a colon delimited file
$ cut -d: -f 1,3 names.txt
Emma Thomas:Marketing
Alex Jason:Sales
Madison Randy:Product Development
Sanjay Gupta:Support
Nisha Singh:Sales
Display only the first 8 characters of every line in a file
$ cut -c 1-8 names.txt
Emma Tho
Alex Jas
Madison
Sanjay G
Nisha Si
Misc Cut command examples
• cut -d: -f1 /etc/passwd Displays the unix login names for all the
users in the system.
• free | tr -s ‘ ‘ | sed ‘/^Mem/!d’ | cut -d” ” -f2

Displays the total memory available on the system.

Chapter 2 : Essential Linux Commands : Find

Find Command

find is frequently used command to find files in the UNIX filesystem
based on numerous conditions. Let us review some practice examples of find command.

Syntax: find [pathnames] [conditions]

#How to find files containing a specific word in its name?
The following command looks for all the files under /etc directory with mail in the filename.

# find /etc -name “*mail*”

How to find all the files greater than certain size?
The following command will list all the files in the system greater than
100MB.
# find / -type f -size +100M

How to find files that are not modified in the last x
number of days?
The following command will list all the files that were modified more
than 60 days ago under the current directory.
# find . -mtime +60

How to find files that are modified in the last x number of
days?
The following command will list all the files that were modified in the last
two days under the current directory.
# find . –mtime -2
How to delete all the archive files with extension *.tar.gz
and greater than 100MB?

# find / -type f -name *.tar.gz -size +100M -exec ls -l {} \;
# find / -type f -name *.tar.gz -size +100M -exec rm -f {} \;

How to archive all the files that are not modified in the
last x number of days?
The following command finds all the files not modified in the last 60
days under /home/jsmith directory and creates an archive files under
/tmp in the format of ddmmyyyy_archive.tar.
# find /home/jsmith -type f -mtime +60 | xargs tar -cvf
/tmp/`date ‘+%d%m%Y’_archive.tar`

Chapter 1 : Essential Linux Commands : Grep

Chapter 1 : Essential Linux Commands : Grep

Grep Command:

grep command is used to search files for a specific text. This is
incredibly powerful command with lots of options.
Syntax:

grep 'word' filename
grep 'word' file1 file2 file3
grep 'string1 string2'  filename
cat otherfile | grep 'something'
command | grep 'something'
command option1 | grep 'data'
grep --color 'data' fileName

How can I find all lines matching a specific keyword on a
file?
In this example, grep looks for the text John inside /etc/passwd file and
displays all the matching lines.

# grep John /etc/passwd
jsmith:x:1082:1082:John Smith:/home/jsmith:/bin/bash
jdoe:x:1083:1083:John Doe:/home/jdoe:/bin/bash
Option -v, will display all the lines except the match. In the example
below, it displays all the records from /etc/password that doesn’t match
John.
Note: There are several lines in the /etc/password that doesn’t contain
the word John. Only the first line of the output is shown below.

# grep -v John /etc/passwd
jbourne:x:1084:1084:Jason Bourne:/home/jbourne:/bin/bash

How many lines matched the text pattern in a particular
file?
In the example below, it displays the total number of lines that contains
the text John in /etc/passwd file.

# grep -c John /etc/passwd
2
You can also get the total number of lines that did not match the specific
pattern by passing option -cv.

# grep -cv John /etc/passwd
39

How to search a text by ignoring the case?
Pass the option -i (ignore case), which will ignore the case while
searching.

# grep -i john /etc/passwd
jsmith:x:1082:1082:John Smith:/home/jsmith:/bin/bash
jdoe:x:1083:1083:John Doe:/home/jdoe:/bin/bash
How do I search all subdirectories for a text matching a
specific pattern?
Use option -r (recursive) for this purpose. In the example below, it will
search for the text “John” by ignoring the case inside all the
subdirectories under /home/users.
This will display the output in the format of “filename: line that matching
the pattern”. You can also pass the option -l, which will display only the
name of the file that matches the pattern.

grep “kernel: *.” *
messages.4:Jul 12 17:01:02 cloneme kernel: ACPI: PCI
interrupt for device 0000:00:11.0 disabled
messages.4:Oct 28 06:29:49 cloneme kernel: ACPI: PM-Timer
IO Port: 0x1008
messages.4:Oct 28 06:31:06 btovm871 kernel: sda: sda1
sda2 sda3
messages.4:Oct 28 06:31:06 btovm871 kernel: sd 0:0:0:0:
Attached scsi disk sda
.
.
In the above example it matches for kernel and colon symbol followed
by any number of spaces/no space and “.” matches any single
character.

# grep -ri john /home/users
/home/users/subdir1/letter.txt:John, Thanks for your
contribution.
/home/users/name_list.txt:John Smith
/home/users/name_list.txt:John Doe

# grep -ril john /root

/home/users/subdir1/letter.txt
/home/users/name_list.txt

Regular Expression in Grep
Regular expressions are used to search and manipulate the text, based
on the patterns. Most of the Linux commands and programming
languages use regular expression.
This hack explains how to use most frequently used reg-ex operators in
Grep command.
Beginning of line ( ^ )
In grep command, caret Symbol ^ matches the expression at the start of
a line. In the following example, it displays all the line which starts with
the Nov 10. i.e All the messages logged on November 10.
$ grep “^Nov 10″ messages.1
Nov 10 01:12:55 gs123 ntpd[2241]: time reset +0.177479 s
Nov 10 01:17:17 gs123 ntpd[2241]: synchronized to
LOCAL(0), stratum 10
Nov 10 01:18:49 gs123 ntpd[2241]: synchronized to
15.1.13.13, stratum 3
Nov 10 13:21:26 gs123 ntpd[2241]: time reset +0.146664 s

Nov 10 13:25:46 gs123 ntpd[2241]: synchronized to
LOCAL(0), stratum 10
Nov 10 13:26:27 gs123 ntpd[2241]: synchronized to
15.1.13.13, stratum 3
The ^ matches the expression in the beginning of a line, only if it is the
first character in a regular expression. ^N matches line beginning with
N.
End of the line ( $)
Character $ matches the expression at the end of a line. The following
command will help you to get all the lines which ends with the word
“terminating”.
$ grep “terminating.$” messages
Jul 12 17:01:09 cloneme kernel: Kernel log daemon
terminating.
Oct 28 06:29:54 cloneme kernel: Kernel log daemon
terminating.
From the above output you can come to know when all the kernel log
has got terminated. Just like ^ matches the beginning of the line only if
it is the first character, $ matches the end of the line only if it is the last
character in a regular expression.
Count of empty lines ( ^$ )
Using ^ and $ character you can find out the empty lines available in a
file. “^$” specifies empty line.
$ grep -c “^$” messages anaconda.log
messages:0
anaconda.log:3
The above commands displays the count of the empty lines available in
the messages and anaconda.log files.

Single Character (.)
The special meta-character “.” (dot) matches any character except the
end of the line character. Let us take the input file which has the content
as follows.
$ cat input
1. first line
2. hi hello
3. hi zello how are you
4. cello
5. aello
6. eello
7. last line
Now let us search for a word which has any single character followed by
ello. i.e hello, cello etc.,
$ grep “.ello” input
2. hi hello
3. hi zello how are you
4. cello
5. aello
6. eello
In case if you want to search for a word which has only 4 character you
can give grep -w “….” where single dot represents any single character.
Zero or more occurrence (*)
The special character “*” matches zero or more occurrence of the
previous character. For example, the pattern ’1*’ matches zero or more
’1′.
The following example searches for a pattern “kernel: *” i.e kernel: and
zero or more occurrence of space character.

grep “kernel: *.” *
messages.4:Jul 12 17:01:02 cloneme kernel: ACPI: PCI
interrupt for device 0000:00:11.0 disabled
messages.4:Oct 28 06:29:49 cloneme kernel: ACPI: PM-Timer
IO Port: 0x1008
messages.4:Oct 28 06:31:06 btovm871 kernel: sda: sda1
sda2 sda3
messages.4:Oct 28 06:31:06 btovm871 kernel: sd 0:0:0:0:
Attached scsi disk sda
.
.
In the above example it matches for kernel and colon symbol followed
by any number of spaces/no space and “.” matches any single
character.

How to Install LAMP on Ubuntu

The following tutorial presumes you understand what a LAMP Server is, how to work a website from the back end and how to install software using either the Software Centre or the Terminal. It also expect experience running other Basic Terminal Commands.

There is also an excellent article on Digital Ocean that may be of more relevance if you are working on a remote or public facing server.

Install Apache

To install Apache you must install the Metapackageapache2. This can be done by searching for and installing in the Software Centre, or by running the following command.

Install MySQL

To install MySQL you must install the Metapackagemysql-server. This can be done by searching for and installing in the Software Centre, or by running the following command.

Install PHP

To install PHP you must install the Metapackagesphp5 and libapache2-mod-php5. This can be done by searching for and installing in the Software Centre, or by running the following command.

Check Apache

Open a web browser and navigate to http://localhost/. You should see a message saying It works!

Restart Server

Your server should restart Apache automatically after the installation of both MySQL and PHP. If it doesn’t, execute this command.

Check PHP

You can check your PHP by executing any PHP file from within /var/www/. Alternatively you can execute the following command, which will make PHP run the code without the need for creating a file .

Congratulations, you have just Installed a Ubuntu LAMP Server!

WordPress Installation on Ubuntu Linux with Apache and MySQL

This article describes an installation of WordPress on a Ubuntu Linux system using Apache web-server and MySQL database. WordPress is an CMS ( Content Management System ), mostly used as a blog publishing web application. WordPress is written in PHP language and uses MySQL database to store data.

Preliminary notes about the system used for this WordPress installation:

  • Ubuntu Linux 10.04 – Worpress 3.1 ( Reinhardt )
  • Kernel 2.6.32-21-generic #32-Ubuntu SMP
  • mysql Ver 14.14 Distrib 5.1.41
  • Apache/2.2.14 (Ubuntu)
  • PHP 5

1. Step 1: Prerequisites installation

# apt-get install php5-mysql mysql-server

2. Step 2: Download and Decompress WordPress

We start by downloading a latest version of WordPress and decompressing it into /var/www/wordpress .

# cd /var/www
# wget http://wordpress.org/latest.zip
# unzip latest.zip

At this point all files should be within /var/www/wordpress directory.

3. Step 3: Apache Configuration

In this step we will create a new apache site called wordpress, enable it and disable default apache website.

# cd /etc/apache2/sites-available
# sed 's/www/www\/wordpress/g' default > wordpress
# a2ensite wordpress
# a2dissite default

Restart apache to apply all changes:

# /etc/init.d/apache2 restart

4. Step 4: Creating WordPress database

Next, we will need to create a MySQL database to be used with our WordPress installation:

  • Username: wordpress
  • Password: wordpress
  • Database name: wordpress
# mysql -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 39
Server version: 5.1.41-3ubuntu12.10 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'wordpress';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON wordpress.* to wordpress@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

5. Step 5: Creating wp-config.php

To continue a WordPress installation we need to create a wp-config.php file to accommodate all WordPress configuration needs. Use following lines to insert database name, database user and password into wp-config.php file.

# cd /var/www/wordpress/
# cp wp-config-sample.php wp-config.php
# sed -i 's/database_name_here/wordpress/' wp-config.php
# sed -i 's/username_here/wordpress/' wp-config.php
# sed -i 's/password_here/wordpress/' wp-config.php
# chmod 600 wp-config.php

OR use text editor of your choice to supply wp-config.php with correct information:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpress');

/** MySQL database password */
define('DB_PASSWORD', 'wordpress');

/** MySQL hostname */
define('DB_HOST', 'localhost');

Ensure that apache have access to wordpress installation files. If this is your local system make sure that www-data owns of all files:

# chown -R www-data.www-data /var/www/wordpress

NOTE: Although localhost as a MySQL hostname within wp-config.php file is a most common option, you may need to change this value according to your webhost needs.

Here are some possible MySQL host values:

Hosting Company MySQL hostname
1and1 db12345678
AN Hosting localhost
A Small Orange localhost
BlueHost localhost
DreamHost mysql.example.com
GoDaddy h41mysql52.secureserver.net
HostGator localhost
HostICan localhost
ICDSoft localhost:/tmp/mysql5.sock
LaughingSquid localhost
MediaTemple GridServer internal-db.s44441.gridserver.com
NearlyFreeSpeech.Net username.db
one.com localhost
pair Networks dbnnnx.pair.com
Rackspace Cloud mysql50-01.wc1.dfw1.stabletransit.com
Yahoo mysql
Hosts with cPanel localhost
Hosts with Plesk localhost
Hosts with DirectAdmin localhost
Tophost.it sql.your-domain-name.it

Optional ( recommended ) step:

Create slathash for wordpress. Visit https://api.wordpress.org/secret-key/1.1/salt/ and copy all lines into your wp-config.php file replacing current non-set values.

6. Step 6: Install WordPress

At this stage everything should be ready to install WordPress on your ubuntu Linux system. Open your browser and point it to your webserver’s IP / hostname . Follow WordPress installer instructions to finish WordPress installation.

7. Troubleshooting

WordPress blank page problem:

If you have created wp-config.php file and navigated to your WordPress installation page using your browser you may see a blank page. This is mostly a result of wp-config.php misconfiguration. Check all data you have filled in to your wp-config.php as well as check actual permissions of this file.

If worst comes to worst you may attempt to continue WordPress installation without wp-config.php where WordPress installer will offer you creation of new wp-config.php file.