apache mySqlphp-med-trans-light

To provide database web services to our application we will need to set up a test Apache webserver that will run PHP,  and a MySQL database server on a Linux host.

This is commonly referred to as a LAMP stack;





Although most of our development work on PHP can be run and debugged from inside Eclipse it’s also useful to set up a debugger for our test webserver, we will be using the XDebug debugger for this purpose (covered in the next page).

I’m using Linux Mint 17 to host my development/test environment, installation instructions will vary depending on your OS but any popular Linux distro or Windows should be fine, I don’t have a Mac so I can’t say how that would go but I’d imagine it’s just as possible.

Note: Depending on your OS and method of installation Apache may use varying file system layouts, take a look at http://wiki.apache.org/httpd/DistrosDefaultLayout  to see where Apache puts it’s files for your distro.

Step 1: Install Apache Webserver

I used the Synaptic Package Manager to install the debian package (I’ll generally be using this wherever possible), there are several different you could install Apache. Using the package manager just search for apache2 and install along with any required dependencies.

To verify your installation open a browser and type


the address bar, you should see a page like this:

It works!

This is the default web page for this server.

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

Apache runs on port 80 by default, if you don’t see this page try checking that port is free or changing Apache’s port number, you’ll need to edit ports.conf (/etc/apache2/ports.conf on my system) and the default Virtual Host file (assuming you haven’t configured another virtual host to use) /etc/apache2/default. You’ll see some 80s, change these to a suitable free port and restart Apache (you’ll need to be root for all of this).
In a console:

~ $ sudo /etc/init.d/apache2 restart

Step 2: Install PHP

Again I’ll be using the package manager to install PHP, just search for php5 (latest at the time of writing) and install.

Restart Apache as before:

~ $ sudo /etc/init.d/apache2 restart

To verify the PHP installation we can just write a test script and put it into under our webserver’s directory structure (in my case /var/www/html).

As a simple example I’ll create a new text file called testphp.php containing a single line of code to display some information about our PHP environment.


And, as root save this under /var/www/html (to make things a bit easier for myself I created a new group ‘www’, added myself to this group, then, as root set the group ownership of /var/www to www with Read and Write permissions).
In your browser go to the address http://localhost/testphp.php,
you should see a page with a long listing of details about your PHP environment.

Step 3: Install MySQL server

Once again using the package manager (see a pattern emerging here?) just search for mysql-server, install and follow the prompts for root password  and make a note of the password somewhere safe.

To see if MySQL is running we can search our running processes:

~ $ ps auxw | grep mysql

which should give something like:

mysql 1155 0.1 0.5 236420 26296 ? Ssl 08:55 0:08 /usr/sbin/mysqld

Which shows the MySQL daemon running as the user mysql.

We’ll only be accessing this database server locally so we don’t require any more configuration (setting a bind address, security etc).

Step 4: Install phpMyAdmin

To make database creation and management easier we’ll install a GUI based database admin tool phpmyadmin, all database mangement tasks could be accomplished from the command line if you so wish.

Back to the trusty package manager again to install phpmyadmin, the installer will ask you which webserver to configure, choose apache2, you should check the next option unless you want to configure phpmyadmin manually.

You’ll need your MySQL root password created in the previous step and you’ll create a ppassword for phpmyadmin.

To verify our MySQL and phpmyadmin installs go to http://localhost/phpmyadmin in your browser, if all has gone well then you’ll presented with a login, once logged in you should be able to see details of your Apach, PHP and MySQL configurations.

Congratulations! We now have a MySQL and PHP enabled Apache webserver on Linux (our LAMP stack).

In the next page we’ll be installing the XDebug debugger and PHP plugins for eclipse to aid our PHP development and putting everything so far together by creating a simple database and using some PHP to read from and write to it through a web page.

Next page: Setting up the dev/test environment – Part two

Back to: Introducing the app


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: