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

Advertisements

Choosing a Linux distro

As all of you might be knowing that distro is a short name for Linux Distributions, here I list many distros which have gained a lot ground of late and can be truly called desktop OS. Some information are also appended along with them so that you can make a nice decision. All comments,suggestion and feedback are welcome.

Ubuntu: This is the best and the most usable Linux distro when it comes to general use. A Linux distribution should not just work properly, it should have a strong community, nice documentation, large number of HOWTOs and TIPS/TRICKS. This is the place where ubuntu beats all distros hands down. If you have problems downloading from the site or have slow connection, you can order its CD for free! Order Now

UbuntuForums: This is one of the most busiest forums and too exhaustive for any one to follow. In light mood its so vast that one needs to be unemployed to keep track of all the threads 😀 Its claims over 6,00,000 users on the community. Even if you post a n00b question, you should expect to get multiple instant replies. One thing special is the patience in community members. The same n00b question is asked again and again by different members and all of them are answered by the people in polite tone. Its a non-geek hangout

Ubuntu Wiki: This is one of the best documentation I have ever seen, one stop destination for all problems and tweaks. The wiki consists of two parts official and community. Official one is a bid narrow thing and to the point explanation whereas community section is highly exhaustive.

Download Now

Continue reading

What is GRUB or a bootloader?

GRUB is an abbreviation for GRand Unified Bootloader, its actually a product of the GNU project aimed at creating a bootloader which can boot nearly all operating systems. So now what is a bootloader? We shall now know this in nearly a layman’s approach.
When you switch on your computer, it fetches which operating system to boot from a special place on the hard disk called Master Boot Record(MBR). After that the required operating system is started. This does not need any complications if you have jus one operating system. Now if you have more than one operating system, the new circumstance are explained below.
Consider that there are two friends who got an internet connection and want to share it. What would they do? They will get a hub or a switch to split the line into two so that both of you can get a chance. In the same way consider a bootloader to be like a hub or a switch. It is placed in the MBR and gives you the option to boot any of the many OS which you might be having on your system. Now let u see how this happens.
Your computer is powered on. The contents of the MBR is checked for booting the OS. GRUB should be placed at the MBR so that it can be booted. Now you get a menu at the GRUB to boot your choice of OS. Just select the required and press Enter. That’s done.
Actually GRUB is not completely installed on the MBR. The size of MBR is very small- just 512 bytes. Actually on the MBR only a small portion of GRUB is placed whose function is the bring up the complete GRUB(bootloader). Thus we can say that MBR contains a pointer to the GRUB which is actually located on some other portion on the disk.

Troubles that can crop up:
If you have GRUB installed on some partition say on partition X and a pointer to this partition on MBR. Now if you by mistake delete that partition or format it, you  will lose you GRUB though a pointer may still be containing on the GRUB. So now even though GRUB is on your MBR, you still cant boot any of your OS and you would be greeted by some error message like GRUB error 15,GRUB error 17 or GRUB error 22 depending on the case.
If you have installed Windows after installing Windows you must have noticed that GRUB has vanished. Actually it does not vanish, what happens that Windows replaces itself to the GRUB unhooking GRUB from it. Now GRUB is installed on your computer but still its does not have pointer from the GRUB, its useless now. You need to put GRUB back to the MBR for restoring the original conditions.