You are here

Install Apache, MySQL, and PHP 5 in Ubuntu 11.4 using the Ubuntu Software Centre

Submitted by Peter on Thu, 2011-05-12 00:28

Technology:

Install Apache 2.2, MySQL 5.1, and PHP 5 in Ubuntu Linux 11.4 desktop edition for local testing of your Web sites and for Webmin. This should work the same for Ubuntu 10.10 and 10.4.

This work is on Ubuntu 11.4 with the user interface set to Gnome classic with no effects. Gnome classic is way more popular than the new Unity interface and easier to use. The classic version with no effects has less distractions and a cleaner, easier to read layout.

Important decisions

Is Apache the right choice for you? Yes, almost always yes. For local use, Web development, and most other mixed uses, Apache gives you the flexibility to run every web site and web based application. Most of the Web development documentation and tutorials use Apache.

Lighttpd uses less memory, is faster for some Web sites, and has less flexibility. Start with Apache. If your Web site has a lot of activity, test Lighttpd along side Apache and consider changing. For regular Web development, they are close enough to use Apache on your development machine then lighttpd on your test server.

Nginx is another light weight alternative to Apache that reduces overheads for some Web sites. NginX is recommended over Lighttpd for maximum performance. The problem with Nginx is the different configuration. It is harder to switch from Apache to Nginx than it is to switch to Lighttpd. You need more experience with Web servers and software installation to produce a reliable maximum performance Web site using Nginx. Start with Apache then consider Nginx either when you have a dedicated Web server or when your Web hosting provider offers Nginx with support.

MySQL 5.1, MySQL 5.5, or MariaDB?. MySQL 5.1 is the safe stable version installed by Ubuntu in Ubuntu 11.4. You have to perform extra work to use something else.

PostgreSQL is an alternative to MySQL and is as easy to install as MySQL. The steps are almost the same. You search for postgresql instead of mysql. You can have both installed side by side. if you use both, remember to add both sets of databases to your backups.

PHP 5.3 or 5.2? PHP 5.3 has some significant differences to the previous 5.2. Some applications require 5.2 instead of 5.3. I install 5.3. I install a lot of web applications and all of them now work with 5.3. You could install both versions of PHP side by side but it is not easy and not covered by this page. It is easier to use a different computer for any projects stuck on 5.2.

Ubuntu Software Centre or Webmin? This page shows installation using the Ubuntu Software Centre. If you are installing Webmin as a Web based administrative tool, use Webmin to install then configure Apache, MySQL, and PHP.

Why Webmin? You can use Webmin to administer your Web server across the Internet using a web browser. If you are using Webmin on your other computers, consider using Webmin on your local computer to make the configuration of your local computer the same as your server. Webmin installation is shown on another page.

Ubuntu Software Centre

Select Applications then Ubuntu Software Centre.

Ubuntu applications menu showing the ubuntu software centre entry

Apache

Install Apache 2.2. Search for Apache2 as shown in the following screen shot from the Ubuntu Software Centre. Note the result, the package title, Apache HTTP Server metapackage, and the package name, Apache2. The search will pick up text from either the title or the name.

Ubuntu software centre showing the search box containing apache2 and the search result

Select the entry for Apache as shown in the following screen shot of the Ubuntu Software Centre.

Firefox showing the page from localhost

Select the More info button if you want to read details. There is only one installation option and it is one I have not used. In fact the option looks like it does something you should be doing in your Web browser, not in a Web server.

Select the install button to install Apache. Enter your password in the Authenticate pop up then select the Authenticate button to continue.

Ubuntu authenticate with a box to enter your password and an Authenticate button

Visit the Apache configuration directory to see what configuration files are installed. Select Places then Computer then Filesystem then etc then apache2.

Ubuntu places page for etc apache2

Apache is now installed and ready for use. Open a Web browser and browse localhost. You will get the following page from Apache.

It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.

If your browser does not expand localhost to http://localhost/, type in the full URL. Bookmark the page for later use in testing. If you had a previous installation of Apache, you may get the following page.

ubuntu_apache_localhost_in_firefox.png

MySQL

Install MySQL 5.1. Search for mysql in the Ubuntu Software Centre. The package title is MySQL Server and the package name is MySQL database server (metapackage depending on the latest version). Select Install. Enter your password in the Authenticate pop up then select the Authenticate button to continue.

ubuntu software centre showing mysql package

MySQL will pop up a screen asking for a new password for root, the administrative user. Enter your choice of password then enter the same password a second time to validate. We are installing MySQL on a local machine for testing and need enough security to stop someone else from logging in to our machine and stealing any data in the database. When developing new web sites, the data is usually only test data and of little value. If you are converting an existing database, you might be using a copy of your customer's production database with real data subject to privacy laws and the possibility of legal action if you let someone else access the data.

PHP

Install PHP 5.3. Search for php5 in the Ubuntu Software Centre. The package title is server-side, HTML-embedded scripting language (metapackage) and the package name is php5. Select Install.

ubuntu software centre showing php package

PHP will complain about the Apache MPM worker module not being thread safe. Select Install anyway.

Pop up screen showing message from php about removing the apache mpm worker module

Enter your password in the Authenticate pop up then select the Authenticate button to continue.

Where is PHP connected to Apache? Look in /etc/apache2/mods-enabled/php5.load to see the Apache configuration line that loads PHP. /etc/apache2/mods-enabled/php5.conf contains the default Apache configuration for PHP.

Apache is set to use PHP only for files with a suffix of .php3 or .phtml. I usually change it to also apply PHP to .php and .html. Replace <FilesMatch "\.ph(p3?|tml)$"> with <FilesMatch "\.(html|php|php3|phtml)$">.

There is a line, php_admin_value engine Off, making PHP default to off. I do not have any Web sites not using PHP and change the line to php_admin_value engine on.

You can test PHP by adding a page to the default Apache Web site or creating a new Web site and adding the configuration to Apache. I am battling the usual Linux permissions problem where you often have to resort to a 1950s style DOS/Linux/Unix command line to make trivial changes and will leave the test site for another day.