For a project I've been working on, I wanted to get MySQL (5.x) working with PHP (5.2.x) in Ubuntu (Fiesty Fawn, haven't switched to Hardy Heron yet). I haven't worked with these software for quite some time. I tried to get it working by manual configurations (installing the required packages and editing the php.ini to have the mysql.so extension), but had little luck with it. Fortunately, I found the this reference. I first completely removed apache2, php5 and mysql from my distribution and apt-get installed the following.
sudo apt-get install apache2
sudo apt-get install mysql-server libmysqlclient15-dev
sudo apt-get install php5 php5-common libapache2-mod-php5 php5-gd php5-dev
You can set a root password for MySQL server with the following command (initially the root password is blank).
sudo /etc/init.d/mysql reset-password
Now php should work along with apache2. However, we still need to get it glued with MySQL. Installing phpmyadmin does the trick.
sudo apt-get install phpmyadmin
For PHP to work with MySQL, we need the php5-mysql package. Installing above phpmyadmin package automatically installs php5-mysql for you. Now you should see a section for MySQL in phpinfo(). If you go to http://localhost, you will see a folder called phpmyadmin which provides a web interface to your database server.
If you happen to forget the root password of your MySQL (which happened to me), you can do the following to reset.
First stop the already running MySQL server:
mysql server /etc/init.d/mysql stop
Start MySQL in safe mode with privilege checking switched off:
Log into MySQL as root user:
mysql --user=root mysql
Execute the following:
update user set Password=PASSWORD('new-password');
Now kill the MySQL daemon started in safe mode and you are all set to work in the regular mode.