Ubuntu - Install php5, mysql, apache2, ssl, pdo & pdo_mysql
General News, ubuntu July 1st, 2007
I recently tried SUSE enterprise 10 and although i found the GUI absoloutly excellent, wireless support and sound card support was such an effort to get working, i have come back to good ol’ ubuntu. The classic linux distro where stuff seems to ‘just work’.
The following is meant to be a tutorial for setting up a basic webserver on your ubuntu desktop.
Installation instructions / How to setup PHP5, Mysql, Apache2, SSL, Mod_rewrite, pdo and pdo_mysql
Overview / Index
The reason i have put this together, is so people don’t have to search for multiple things, and can find all the essentials here
- Install Apache2
- Install MySql 5
- Install PHP 5
- Install PHPmyadmin
- Install SSL certificate for apache
- Install PDO & PDO_Mysql
I am running Ubuntu 7.10 and fresh installation (about 10 mins ago).
I am going to setup Apache2, PHP5, MySQL, SSL, PDO loading the PDO_MySQL driver. This document is ment to help people who struggle with any of these and provide a bit more of a ‘one stop shop’ to anyone trying to set these services up.
ntom@localhost:~$ sudo apt-get install apache2
Incase you need to, you can find how to add extra repositories here
ntom@localhost:~$ sudo apt-get install mysql-server libmysqlclient15-dev
ntom@localhost:~$ sudo apt-get install php5 php5-common libapache2-mod-php5 php5-gd php5-dev curl libcurl3 libcurl3-dev php5-curl
ntom@localhost:~$ sudo aptitude install phpmyadmin
At this point, you should be able to go to http://localhost/ and see your webserver is now up and running.
You should also now see a folder called ‘phpmyadmin‘ which if you click on, and enter ‘root’ as the username, leave the password blank, and login, will give you access to your mysql db’s.
Step 5 > SSL certificate for Apache2
ntom@localhost:~$ sudo apache2-ssl-certificate
If you get back that it can’t find apache2-ssl-certificate .. then not to worry, this is a known bug, and please read my comment at the bottom.. direct link to the comment click here
Answer the questions
ntom@localhost:~$ sudo a2enmod ssl
This enables the ssl mod for apache2
ntom@localhost:~$ echo "Listen 443" | sudo tee -a /etc/apache2/ports.conf
ntom@localhost:~$ sudo ln -s /etc/apache2/sites-available/ssl /etc/apache2/sites-enabled/ssl
ntom@localhost:~$ sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/ssl
To understand more about sites-enabled, sites-available click here
ntom@localhost:~$ sudo gedit /etc/apache2/sites-available/ssl
Select All (crt+a), delete, then paste in this:
NameVirtualHost *:443
<virtualhost *:443>
ServerAdmin webmaster@localhost
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem
DocumentRoot /var/www/
<directory />
Options FollowSymLinks
AllowOverride None
</directory>
<directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
# Commented out for Ubuntu
#RedirectMatch ^/$ /apache2-default/
</directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</directory>
</virtualhost>
Then we need to change the default file, so…
ntom@localhost:~$ sudo gedit /etc/apache2/sites-available/default
and make sure the following lines say this:
NameVirtualHost *:80 <virtualhost *:80>
 
You may also want to enable mod_rewrite.. todo so, follow the following steps:
ntom@localhost:~$ sudo a2enmod rewrite
You will also need to edit sites-available default, and ssl:
sudo gedit /etc/apache2/sites-available/default
And the same again for the ssl file.
Here you will need to change the section which says ‘AllowOverride None’ to:
AllowOverride All
Now restart apache
ntom@localhost~: sudo apache2 -k restart
First, we need to install PEAR, so…
sudo apt-get install php-pear
If you get anything about warning, ‘phpize’, this means you need php-dev, or if your using sypantic package manager, ‘php5-dev’.
sudo pecl install pdo
This installs pdo.
The next thing you want todo is install the pdo_mysql drivers. Do this by doing the following:
sudo pecl install pdo_mysql
If however you get a error somthing along the lines of:
checking for MySQL support for PDO... yes, shared checking for mysql_config... not found configure: error: Cannot find MySQL header files under ERROR: `/tmp/tmpRiQ5ax/PDO_MYSQL-1.0.2/configure' failed
Then you should download and install the following packages:
sudo apt-get install libmysqlclient15-dev
and then try to re-install pdo_mysql.
Once this is finished and sucessful (it was for me), its best to then run the following code:
sudo updatedb sudo gedit /etc/php5/apache2/php.ini
Inside the php.ini, at the bottom, add the following lines:
extension=pdo.so extension=pdo_mysql.so
The end
I hope this has been helpfull to many people out there. I hope it has saved people endless hours looking at different sites for different aspects of this tutorial.
Please be sure to leave some comments

July 2nd, 2007 at 8:49 am
Jee willigers - this is like the fith guide I heave read and I have finally done it!
I had to go through twice though. Some screenshots would be helpfull for us Ubuntu babies.
July 18th, 2007 at 11:10 am
If I weren’t a man, and already married, I would have your child right now! Thank god for this blog. I’m so tired of scouring the internet for a simple explanation of how to get this going. Thank you so much.
August 1st, 2007 at 8:53 pm
Richard, is that your answer for ‘who would you turn gay for?’ LOL … just kidding … great article!
August 6th, 2007 at 10:53 am
Very nice tutorial, well explained, everything works (I haven’t tested the PEAR part)
Just 1 thing I noticed that was probably a typo:
“You will also need to edit sites-available default, and ssl:
sudo gedit /etc/apache2/sites-available default”
shoud be:
“You will also need to edit sites-available default, and ssl:
sudo gedit /etc/apache2/sites-available/default”
you put a space instead of a slash
Really Really great tutorial
Bruno
August 6th, 2007 at 6:01 pm
One more thing, although this is probably assumed. You will also need to make sure you have ‘make’ installed.
sudo updatedb
sudo aptitude update
sudo aptitude install build-essential
- j
August 6th, 2007 at 6:19 pm
Forgot to add that, if after executing this:
sudo apt-get install libmysqlclient15-dev
and you are still getting errors trying to install pdo_mysql, try this:
sudo PHP_PDO_SHARED=1 pecl install PDO_MYSQL
That worked for me.
- j
August 6th, 2007 at 11:00 pm
Thanks for the positive comments and leaving additional help. I have also fixed the type regarding the gedit of the default file in the sites-available directory.
I’m glad people are finding the article helpful in setting up the ubuntu dev environment and would like to thank, Swinger Guy, Richard, Sid, Bruno and Jack for taking the time to leave some comments.
Tom
August 14th, 2007 at 9:57 pm
apache2-ssl-certificate to generate SSL certificates. This script is missing in Ubuntu Feisty server edition.
how about this…
im still new to make ssl from apache..
this guide very nice… so easy…
but i stuck at
”
sudo apache2-ssl-certificate
”
so what i need to do..
August 24th, 2007 at 6:27 am
Hello shamsul, i also encountered this problem on another pc of mine.
It is a registered bug see here
I did a bit of researching, and a kind gentleman, mlind has come up with the fix for it, very simple.
His fix post can be found here
but for those who want to know now now now. . .
You need to download this file and then:
tar xzvf apache2-ssl.tar.gz
sudo mv ssleay.cnf /usr/share/apache2/
sudo mv apache2-ssl-certificate /usr/bin/
sudo mkdir /etc/apache2/ssl
sudo apache2-ssl-certificate
and that should work. Hope this helps others aswell.
September 27th, 2007 at 2:33 pm
Thank you! Wow I worked on getting https working on Ubuntu server for over 24 hours till I seen this post! It fixed it! When I 1st went to https it worked and said a bit WOW! to my self. I had to install the apache2-ssl.tar.gz too. Don’t they have this with some apt-get update? If it’s a error a update should fix it right?
Thanks again!
-Raymond Day
September 27th, 2007 at 5:30 pm
Because I did this I get this error now. How would I fix it?
apache2 -k restart
[Thu Sep 27 21:19:59 2007] [warn] NameVirtualHost *:443 has no VirtualHosts
[Thu Sep 27 21:19:59 2007] [warn] NameVirtualHost *:80 has no VirtualHosts
-Raymond Day
September 28th, 2007 at 12:19 am
Hi Raymond, Please paste the contents of your /etc/apache2/sites-enabled and sites-available file.
September 28th, 2007 at 2:03 am
root@small:/etc/apache2/sites-enabled# ls -l
total 4
lrwxrwxrwx 1 root root 36 2007-08-18 04:20 000-default -> /etc/apache2/sites-available/default
-rw-r–r– 1 root root 64 2007-09-27 07:30 local-host-names~
lrwxrwxrwx 1 root root 32 2007-09-27 01:37 ssl -> /etc/apache2/sites-available/ssl
lrwxrwxrwx 1 root root 51 2007-08-26 01:41 webmin.1188106870.conf -> /etc/apache2/sites-available/webmin.1188106870.conf
root@small:/etc/apache2/sites-enabled# cd ../sites-available/
root@small:/etc/apache2/sites-available# ls -l
total 24
-rw-r–r– 1 root root 1187 2007-09-27 17:03 default
-rw-r–r– 1 root root 1182 2007-09-26 23:32 default_original
-rw-r–r– 1 root root 33 2007-09-02 08:07 local-host-names~
-rw-r–r– 1 root root 1568 2007-09-27 20:18 ssl
-rw-r–r– 1 root root 1182 2007-09-27 17:57 ssl~
-rw-r–r– 1 root root 134 2007-08-26 01:41 webmin.1188106870.conf
root@small:/etc/apache2/sites-available#
I went to other web pages none got it working so I had some other files but I did not want to delete them so I put a ~ at the end of there names so it would not use them.
I thought it be the local-host-names~ that it needed I removed the ~ restarted apache but it error-ed, I renamed it back. Not sure what to do now. I hope you can help.
-Raymond Day
September 28th, 2007 at 5:40 am
[...] my e-mail and the board at http://www.theatons.com Said to paste my “/etc/apache2/sites-enabled and sites-available file” there. [...]
October 21st, 2007 at 6:52 pm
Please help me out i did step by step this blog instruction (’By the way is amaizing . thank you very much for it but’) after the certificate a received follow message:
Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
(98)Address already in use: make_sock: could not bind to address [::]:443
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:443
no listening sockets available, shutting down
Unable to open logs
October 31st, 2007 at 12:37 pm
sudo apache2 -k restart
apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
httpd not running, trying to start
(98)Address already in use: make_sock: could not bind to address [::]:443
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:443
no listening sockets available, shutting down
Unable to open logs
October 31st, 2007 at 12:52 pm
i have discovered:P you have to delete listen 443 from /etc/apache2/ports.conf … it is in the last line.. i saw it is written twice.. maybe helps someone:D
November 17th, 2007 at 4:18 pm
excellent tutorial
however… i have a question… i want to run from postgreSQL (I need the functions and view’s ability which aren’t available in mySQL).
I have looked around and although I have installed postgreSQL 8.2 and install pgAdmin3 I haven’t any idea how to add the extension values to php…
any ideas?
I’m a noobie to Ubuntu (gutsy) and I have to admit I’m having fun again (as i’ve become sick of windows as well as everyone else) and need to deal with this…
I’m also hoping that I’ll be able to deal with import/export ability with FileMaker Pro (though I understand v9 upgrade has that built into the FMP build)…
Loved your Toot!!
November 18th, 2007 at 3:22 am
Hi James,
First locate your php.ini file, “sudo updatedb” then “locate php.ini”
It will then show probably more than one php.ini
My default php.ini is in “/etc/php5/apache2/php.ini”
Anyway, just open that up in the vim “cd /etc/php5/apache2″ -> “vim php.ini” then search fro extensions, in the vim console just put “/extension” and you will find the section that tells you where to put the extension name.
Usually on ubuntu this goes @ the bottom of the php.ini, just put in
extension=somefile.so
Hope this helps, and thank you sir and others, for the kind remarks for the tutorial. My only aim is to help others. And if they in turn help others with anything thye do, then everyone wins
Tom
November 28th, 2007 at 3:15 am
I absolutely surprised, that your tutorial is worked good. So I can continue installing my CalemEAM again, after stopped cause doesn’t find the PEAR and PDO..
Once again, thanx alot bro….
November 28th, 2007 at 4:07 am
Tambahan / Just add FAQ if you guys have this problem:
1. Found error something like “PHP Fatal Error driver pgsql “in /var/log/apache2/error.log
Do : sudo pecl install pdo_pgsql
2. Found error like “libpq-fre.h please specify PostgreSQ ”
Do : sudo apt-get install libpq-dev
January 22nd, 2008 at 2:47 am
Great post and great blog as well. you have nicely written the tips for the web server thanks a lot for writing this very useful post. Great blog.
February 12th, 2008 at 8:36 am
i cant see the folder called phpmyadmin, i only get this folder up [DIR] apache2-default/ 20-Nov-2004 21:16.
i tried to do it all over agn, stil doesnt work.
any1 who can help me?
February 25th, 2008 at 5:54 pm
A great walk through, thank you.
On restarting apache2 it shut down and on checking the log saw it was because the socket for 443 was already in use. Alexandru’s comment here solved that one hitch for me and everything is working fine.
March 17th, 2008 at 1:12 am
[...] If you get back that it can’t find apache2-ssl-certificate .. then not to worry, this is a known bug, and please read my comment at the bottom.. direct link to the comment click here [...]
June 27th, 2008 at 5:50 am
hi, pls help me out. when i restart apache, i get this:
apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
help pls…
btw thanks for this great howto
June 27th, 2008 at 5:53 am
i’ve tried alexadrus’s fix, but it didn’t work..
July 12th, 2008 at 1:40 pm
Thanks! this was very very helpful
September 3rd, 2008 at 6:29 pm
thanx a lot!!!! it was very-very helpful!!!
September 24th, 2009 at 6:54 am
Great guide! I use it all the time!
One change though PHP install.
The package “libcurl3-dev” does not exsist in the repositories for Ubuntu 9.04. I’ve used “libcurl4-openssl-dev” instead and it works flawlessly.
October 1st, 2009 at 9:58 am
I am new to Ubuntu (and LAMP). This turned out a great guide for me, I wish I would have found this sooner…had to spend hours trying to work SSL. Thanks.
October 21st, 2009 at 10:17 am
Excellent guide, The SSL section saved me alot of time.
February 3rd, 2010 at 7:45 am
I’ve had a problem with the ssl.
$> /etc/init.d/apache2 restart
* Restarting web server apache2 Syntax error on line 7 of /etc/apache2/sites-enabled/ssl:
SSLCertificateFile: file ‘/etc/apache2/ssl/apache.pem’ does not exist or is empty
Any Ideas?