Wednesday, 14 December 2011

How to Install Apache, PHP, MySQL and PHPMyAdmin in Ubuntu 11.04

If you are a PHP based web developer, you need all the software running and configured properly. Here I am talking about installing them One by One in your Ubuntu Desktop. We are installing all the applications from terminal.

How to Open Terminal:
So, to fire up the terminal follow any of these steps:

  1. If you are running Unity Desktop, click on the Ubuntu Logo at top left corner and type Terminal in the search application bar. Then click on the terminal icon.

  2. If you are running GNome Desktop, click on Applications->Accessories->Terminal

  3. For shortcut, you can also press Ctrl+Alt+T at once, to open the terminal.


How to install Apache:

1. Make sure you have the internet connection. To install apache execute the following command in the terminal:










1


sudo apt-get install apache2




It takes some time to download and install apache. After the setup completes, type http://localhost/ in your browser window to make sure apache is installed and running properly. If you see the page with It Works!, the setup of apache2 completes successfully.

How to Install PHP:

1. To install PHP 5, type following commands in the terminal one by one:










1

2


sudo apt-get install php5

sudo apt-get install libapache2-mod-php5




The first line installs PHP5 in the computer. The second one provides the PHP5 module for the Apache 2 webserver. If second one is not installed, then Apache cannot parse PHP codes in a web page.

2. After installing PHP5 and PHP module for apache, restart the apache with following code:










1


sudo /etc/init.d/apache2 restart




3. While restarting the apache server, if you see a warning as “Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName”, then you can fix this by creating a file with the Server name. To do this type the following command in the terminal:










1


sudo gedit /etc/apache2/conf.d/fqdn




When the text editor opens, type “ServerName localhost” inside the file and click Save. Then close it. Now restart again with the above code and you will see that the warning message has gone.

4. Now, we have successfully installed php and apache web server. However, still we don’t know if PHP is successfully installed. To check this, create a file inside /var/www/ folder named test.php as:










1


sudo gedit /var/www/test.php




and write following code in it










1


<?php   phpinfo();  ?>




Save the file and type this in browser: http://localhost/test.php

If you see the various information about PHP and installed modules there, then we can confirm that Apache is parsing PHP codes. Hence the installation is successful up to this point.

How to Install MySQL:

1. To install MySQL Server in ubuntu, type following code in terminal window:










1


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




This will install latest mysql server and other necessary PHP modules for recognizing mysql functions from PHP code. While installing MySQL server, you may require to enter the password for MySQL root user.

How to Install PHPMyAdmin:

1. To Install PHPMyAdmin, type the following codes in the terminal:










1


sudo apt-get install phpmyadmin




While installing PHPMyAdmin, you may require to select the web server. In such case, tick the Apache2 Server and proceed with the installation. You may also require to input MySQL root user password during installation.

Once the installation completes, type this in your browser window to confirm the successful installation of PHPMyAdmin: http://localhost/phpmyadmin/index.php.

Now, you are finished. Your environment is setup and you can enjoy using all these applications. Next, you can install other applications that may be necessary such as Eclipse, GIMP etc.

Tuesday, 29 November 2011

The Right Way to Get a File Extension in PHP

I made a recent search on retrieving file extensions in PHP.

I found out that a lot have been re-inventing the wheel. They have been creating code for functionality that PHP already has. This is one example of re-inventing the wheel

function get_file_extension($file_name)
{
return substr(strrchr($file_name,'.'),1);
}


Another example was this:

function file_extension($filename)
{
return end(explode(".", $filename));
}


PHP already has a function that does the same thing and more.

Welcome, pathinfo.

$file_path = pathinfo('/www/htdocs/your_image.jpg');
echo "$file_path ['dirname']\n";
echo "$file_path ['basename']\n";
echo "$file_path ['extension']\n";
echo "$file_path ['filename']\n"; // only in PHP 5.2+


// Output
/www/htdocs
your_image.jpg
jpg
your_image


A much easier way to use the constants:
[PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME]

PATHINFO_DIRNAME - the directory
PATHINFO_BASENAME - the file name
PATHINFO_EXTENSION - the extension
PATHINFO_FILENAME - the filename without the extension

echo pathinfo('/www/htdocs/your_image.jpg', PATHINFO_EXTENSION);

// Output

jpg

Friday, 21 October 2011

Building your house

An elderly carpenter was ready to retire. He told his employer-contractor of his plans to leave the house-building business to live a more leisurely life with his wife and enjoy his extended family. He would miss the paycheck each week, but he wanted to retire. They could get by.



The contractor was sorry to see his good worker go & asked if he could build just one more house as a personal favor. The carpenter said yes, but over time it was easy to see that his heart was not in his work. He resorted to shoddy workmanship and used inferior materials. It was an unfortunate way to end a dedicated career.



When the carpenter finished his work, his employer came to inspect the house. Then he handed the front-door key to the carpenter and said, “This is your house…my gift to you.



“The carpenter was shocked!



What a shame! If he had only known he was building his own house, he would have done it all so differently.

So it is with us. We build our lives, a day at a time, often putting less than our best into the building. Then, with a shock, we realize we have to live in the house we have built. If we could do it over, we would do it much differently.



But, you cannot go back. You are the carpenter, and every day you hammer a nail, place a board, or erect a wall. Someone once said, “Life is a do-it-yourself project. “Your attitude, and the choices you make today, help build the “house” you will live in tomorrow. Therefore, build wisely!

2 Monks and a Pretty Lady

Once upon a time a big monk and a little monk were traveling together. They came to the bank of a river and found the bridge was damaged. They had to wade across the river.

There was a pretty lady who was stuck at the damaged bridge and couldn’t cross the river.

The big monk offered to carry her across the river on his back to which the lady accepted.

The little monk was shocked by the move of the big monk and was thinking “How can big brother carry a lady when we are supposed to avoid all intimacy with females?” But he kept quiet.

The big monk carried the lady across the river and the small monk followed unhappily. When they crossed the river, the big monk let the lady down and they parted ways with her.

All along the way for several miles, the little monk was very unhappy with the act of the big monk. He was making up all kinds of accusations about big monk in his head. This got him madder and madder. But he still kept quiet. And the big monk had no inclination to explain his situation.

Finally, at a rest point many hours later, the little monk could not stand it any further, he burst out angrily at the big monk. “How can you claim yourself a devout monk, when you seize the first opportunity to touch a female, especially when she is very pretty?”

All your teachings to me make you a big hypocrite.

The big monk looked surprised and said, “I had put down the pretty lady at the river bank many hours ago, how come you are still carrying her along?”

Moral: This very old Chinese Zen story reflects the thinking of many people today. We encounter many unpleasant things in our life, they irritate us and they make us angry. But like the little monk, we are not willing to let them go away. There is no point in remaining hurt by the unpleasant event after it is over. Learn to move on in life!

Monday, 3 October 2011

True Love is an Acceptance

It was a busy morning, about 8:30, when an elderly gentleman in his 80′s arrived to have stitches removed from his thumb. He said he was in a hurry as he had an appointment at 9:00 am.

I took his vital signs and had him take a seat, knowing it would be over an hour before someone would to able to see him. I saw him looking at his watch and decided, since I was not busy with another patient, I would evaluate his wound.

On examining,I saw that it was well healed, so I talked to one of the doctors, got the needed supplies to remove his stitches and redress his wound. While taking care of his wound, I asked him if he had another doctor’s appointment this morning, as he was in such a hurry. The gentleman told me no, that he needed to go to the nursing home to eat breakfast with his wife. I inquired as to her health.

He told me that she had been therefor a while and that she was a victim of Alzheimer’s Disease. As we talked, I asked if she would be upset if he was a bit late. He replied that she no longer knew who he was, that she had not recognized him in five years now. I was surprised, and asked him, “And you still go every morning, even though she doesn’t know who you are?”

He smiled as he patted my hand and said, “She doesn’t know me, but I still know who she is.”

I had to hold back tears as he left, I had goose bumps on my arm, and thought, ‘That is the kind of love I want in my life.’

Moral:

True love is neither physical, nor romantic.

True love is an acceptance of all that is,

has been, will be, and will not be.