Category Archives: LAMP

Checklist for fresh Ubuntu installs

Now don’t bash me just for installing proprietary and restricted software on my computer. I have no other option for the time-being. I am too a free software evangelist.

Each time I (re)install Ubuntu on my laptop or home PC or on a friend’s laptop, I always forget some or the other software which I have to download at a later date. This is sometimes troublesome if I don’t have net working at my home and take the laptop to a wired workplace to download the packages. Here are the packages which I usually download and you would always find it as a part.

This includes many proprietary softwares as well, if you know a good replacement, please do take pains to inform me about it.

Runtimes

  • Adobe Integrated Runtime (proprietary)
  • Java 6 (free)

Applications

  • Twhirl (proprietary)
  • Terminator (free)
  • xChm (free)
  • Inkscape (free)
  • TweetDeck (?)
  • K3B (free)
  • Scribus (free)

Networking (incl Internet)

  • Thunderbird (free)
  • Epiphany (free)
  • FileZilla (free)
  • WireShark (free)
  • XChat (free)
  • Opera (?)
  • KTorrent (free)
  • Bluetooth OBEX Server (free)

System Tools and Softwares

  • Yakuake (free)
  • VirtualBox OSE (free)
  • Konsole (free)
  • QGRUBEditor (free)
  • APTonCD (free)
  • Wine (free)

Programming (Editors + SDK)

  • Geany (free)
  • Glade Interface Desinger (free)
  • Komodo (proprietary)
  • Netbeans (free)
  • Qt Designer + Qt Creator (free)
  • Qt SDK (free)
  • GTK+ Development Headers (free)
  • Leafpad (free)
  • Emacs (free)
  • Amaya (free)
  • QT4 Linguist and Assistant (free)
  • MySQL (free)
  • Apache (free)
  • PHP (free)
  • SQLiteman (free)

Multimedia

  • VLC Media PLayer (free)
  • Amarok (free)
  • Banshee (free)
  • Last.fm Scrobbler (free)
  • Miro Internet TV (free)
  • RealPlayer (proprietary)
  • Gstreamer Codecs (proprietary) (restricted)
  • Xine (proprietary) (restricted)

Configuration

  • Dust Theme (free)
  • Nautilus Action Configurations (free)
  • Nautilus Open Terminal (free)
  • Compiz Config Settings Manager (free)

5 Less Known PHP Functions

As all of you know that PHP has a large set of functions for the programmers. The list is so huge that we keep on learning each one of them day by day. There are some cases you would like to know them beforehand to use them in your app. These are those functions which may be famous for some, but largely people are ignorant about their existance. Here goes the list.

  1. highlight_string: When you want to give away some PHP code as example and want it syntax highlighted, what would be your next step? Get some highlighting plugin? Use this function, pass the string and the highlighted string is printed as the output. If you don’t want to print it, instead want to store in some variable, pass the second variable as true. Details
  2. htmlspecialchars: If you have a HTML code to show as an example and want to print it out on the page, simply echoing wont suffice, since the tags would be rendered by the browser as HTML tags. This function converts < to &lt; and > to &gt; and other such special chars into their respective representation. Details
  3. chr: It is used to convert a number to its ASCII character. The paramter of the function is the integer and output is the character from the ASCII table. Details
  4. ord: This is just the reverse of chr. It takes a single character as input and returns back the ASCII value of the character. It’s a reverse mapping of chr. Details
  5. xdiff_file_diff : Taking file differences is one of the oldest thing which existed on a computer. The *nix diffutils is a great source of diff for system admins. Let’s make it available on PHP too. this function takes 3 compulsory arguments – first is the old file, second is the new file and the third being the difference file where the diff is stored. You can use the xdiff_file_patch to patch the files. Details

Generating XML using PHP

Long back I was hunting the entire web for some tutorials for generating XML using PHP. To my surprise, there are only a handful of them, where half of them are not of any use. Since PHP Library is very large, finding the right library was also a vey dauntng task. I first encounted XMLWriter, but it echoed the generated XML right out on the page. It’s useless in case when you want to send the generated XML across a network over socket.

After googling, I found a library called DOMDocument which helped me a lot and cleared off all problems in matter of minutes. It looks similar to .NET’s XMLWriter library or maybe the way round.

To start with we create a new instance of XMLDocument using

$doc = new DOMDocument();

Now if you want to turn on the XML Formatting , you need this line

$doc->formatOutput = true;

Now if you want to create a new Node Element or Text Element, all of them have to be created from $doc using createElement and createTextNode methods of DOMDocument class. If you want to create a Node Element and attach it to its parent, then use this code

$operation = $doc->createElement("operation");
$doc->appendChild($operation);

where operation string passed in createElement is the name of the XML Node.

TextNode are also a kind of Node and is represented by a node below its outer Element.

$type = $doc->createTextNode("kill");
$operation->appendChild($type);

You can use arrays to store data temporarily and use the foreach construct to fetch the key value pairs.

$student = array( "name" => "Mike Ross" , "age" => 25 ,
     "dob" => "1980-10-12" , "post" => "CEO");

foreach ( $student as $key => $value )

{

    // Your processing here

}

Now if you want to retrieve the data stored inthe $doc object, use the saveXML method to fetch th String

$doc->saveXML();

Running PHP Applications on Linux

Overview:

I usually find that lots of poeple find it quite difficult to install any application made in PHP and MySQL on their Linux boxes. They find it a bit confusing how to configure the settings. How to install the LAMP stack. Where to put the PHP applications code. I was quite inspired to write to this after having I saw people facing problems on Ubuntu Forums. This is the one which I dealt with.

Sometimes spoon-feeding becomes important,but only for the first time.

Scenario:

A newbie who knows just the basics of Linux. He/She wants to run a PHP application like wordpress / phpBB / osCommerce on their computer.

The distro is assumed to be Ubuntu, though it doesn’t change much for others too.

Lets Start:

Step 1: Getting the LAMP stack on your system

You first need to install LAMP on your box, Installation is quite simple. Just get the following packages using the command on your terminal ( Applications> Accessories>Terminal)

sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server

While installing MySQL, it might ask for set up the root password,if it doesn’t ask, then continue.

For more information check this post here .

Step 2: Download the PHP application

You need to download the PHP application which you want to run over the webserver. Examples are WordPress, phpBB, osCommerce, MediaWiki etc

Get them and let it be in the folder where you have downloaded it.

Step 3: Moving these software to the Apache’s root directory

Apache’s root directory is /var/www (/var/www/html). This is owned by the user www-data which is a minimal user created just for running apache and web servers. A normal user cant write to this directory.

Now here is the solution of how to copy the data to this directory. This method can be used for any directory which the normal user does not have write access. The concept behind the method is to start an instance of nautilus ( explorer) with root (superuser) privileges. For this follow the isntructions

* Press Alt + F2

* A Run daialog box appears, over there type gksudo nautilus /var/www

* You will be asked for your password as you are elevating your privileges

* Nautilus opens up,now copy the tarball/zip file from the download location to /var/www

* Untar the archive by Right Click > Extract Archive

You may have the package in the folder say /var/www/wordpress. We are supposing wordpress as an example.

Step 4: Setting up username and accounts in database

Now you need to have a create a new database for the software you intent to work on. For this open MySQL from the terminal. If you had been asked to set up the password at time of MySQL installation then use this command

mysql -u root -p

and then enter the root password which you set up

if you were not asked to set up root password, then use this command at terminal

mysql -u root

After this is done you will be dropped to mysql prompt. Create a new database using this:

create database foo;

type quit to exit.

Step 5: Change the data in the config file.

Hunt for file which may have name such as config,settings etc etc. One you locate it,open to find the area for entering database settings. The settings should be:

Hostname: localhost

Username: root

Password: <the password you set up>

Database name: foo (or whatever you created)

Step 6: Access it via browser

Now point your browser to http://localhost/wordpress

You may get the basic installation thing or whatever stuff you need.

Additional Stuffs:

You can be asked to make some locations writable. There may be instances like the software cant write to a specific folder or file. It can be used for cache or any such temporary stuff. Then you need to change the permissions. Simply give write permissions to the user www-root. However this situation may be unlikely. e..g we have to change the permissions of folder /var/www/wordpress/cache

sudo chmod -cR u+w /var/www/wordpress/cache

Configuring Apache Webserver

This tutorial is for those people who want to start using PHP + MySQL on windows instead of Linux. This tutorial is written entirely from scratch and is based on my personal experience using WAMP. No guarantee is given on the working of WAMP if you make any changes.
The Apache Webserver’s configuration file is named as httpd.conf and is located in the directory C:\wamp\Apache2\conf if WAMP is installed in C:\Wamp directory.
The rules are simple; any line beginning with # is a comment and is simply ignored by Apache while reading its configuration. Line numbers are given for quick reference. They are the default values and can be different is you have changed your settings. Just look out up or down with reference to the line number for what you are searching for. The Apache version used in this tutorial is 2.2.4. For each change to take effect, you have to restart the server

Changing Server Root:
The directory of Apache where Apache is installed and all configuration files is kept. This includes all error and log files. This can be changed by changing them in line 42.
It reads as ServerRoot “c:/wamp/apache2″
You can change this to “c:/Program Fileswamp/apache2” if you had installed WAMP in program files directory. Note the front slashes as opposed to backslashes which is normally used on windows. All paths on Apache contain slashes no matter what is the Operating System.

Making Apache listen to specific IP address or none:
For this just uncomment out the line which reads out like #Listen 12.34.56.78:80 on line 52. If you want Apache to listen to some IP say 122.65.23.87, change 12.34.56.78 with the required IP address. Setting this to 0.0.0.0 blocks all incoming requests.

Making Apache listen on port other than 80:
By default Apache is made to listen on port 80, but sometimes other webservices are also running on the same port which may give rise to ambiguous situations, you can make Apache to listen to any other port other than 80, the best alternative is port 8080, which is the alternate HTTP port, if some other service is running on it then better try out 8180. To change it just change Listen 80 on line 53 with other port no eg Listen 8080 or Listen 8180

Loading Modules:
Its pretty easy to do so, just uncomment out the # before the LoadModule word. Its starts on line no 67 by default.
The general look for a loaded module looks like
LoadModule modulename_module modules/modulename.so
And that of an unloaded module
#LoadModule modulename_module modules/modulename.so

Changing the root directory of Apache where you keep your scripts:
You are provided with a folder where you have to keep your scripts and execute it via the Webserver. In Linux it is /var/www and /var/www/html in older versions of Apache. In windows it is C:\wamp\www\. This is given in line 150. It is written as
DocumentRoot “C:/wamp/www”
Change C:/wamp/www with any other location like C:/windows/myfolder or any other. Take care of slashes, they are not backslashes.

Configuring you server to be accessed remotely:
Go to line 178, under this are the features for the root directory which Apache accesses. In line 206 change Deny from all to Deny from none and Allow from 127.0.0.1 to Allow from all. You may even try appending a line Satisfy all after the Allow line.

Making your custom error pages:
It’s not much of a headache, just create the page in any file type e.g. html, php etc. Now in line 425 just see the format of adding files. An error code 404 is most famous. It means that the file you requested in not present. Append an extra line to the code and write
ErrorDocument 404 /error404.php

This file should be present in the root directory where Apache is installed. Similarly you can try out other errors by just replacing 404 with any that error’s code.

Setting up LAMP Stack on your UBUNTU System

This is to help people set up LAMP on their desktops. Ubuntu server edition comes with LAMP but desktop users must download all the necessary files. This tutorial owes its credits to Ubuntu Community Docs and lots of people around the world who enlightened me about LAMP and Ubuntu. Let’s start.We first need some important packages. These are:

apache2 php5-mysql libapache2-mod-php5 mysql-server

You can get these via apt-get or from your Synaptics Package Manager. For getting via apt-get you must have an active internet connection. Type this command in the terminal:

sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server

If you are in the Packages Manager, just search the packages and select them. This is the easiest method.

You may want to configure your LAMP, but before starting it is advisable to change the installation defaults. The default root user of MySQL has no password or a blank string as password. This should be changed. It is always advisable to create another user with full privileges as that as root. Use this alternate user instead as root. Root is the superuser.

Go to terminal: Type

mysql -u root

At MySQL console type

SET PASSWORD FOR ‘root’@'localhost’ = PASSWORD(‘yourpassword’);

Just put your password instead of yourpassword within single quotes as shown above.

After setting the password if you want to login as root,just enter this at the terminal:

mysql -u root -p

Create a new user and give all the privliges to it as explained above:

grant all privileges on *.* to ‘yourusername’@'localhost’

identified by ‘yourpassword’ with grant option;

Replace yourusername with the username you want and yourpassword with a proper password. If you want this user to deny Grant Option just remove WITH GRANT OPTION from the above statement.

Run, Stop, Test, And Restart Apache:

Start: sudo /usr/sbin/apache2ctl start

Stop: sudo /usr/sbin/apache2ctl stop

Test: sudo /usr/sbin/apache2ctl test

Retart: sudo /usr/sbin/apache2ctl restart