Transform your computer to a webserver with Apache, PHP, MySQL



Apache, PHP and MySQL is probably,if not definitely, the most common setup for a webserver on the entire Internet. Many popular website and blogging platforms such as Joomla and Wordpress are based on this setup. The good news is, that you use these totally free technologies yourself in order to transform you computer into a webserver on to which you will build your website. Without any further delays let's go to meet our key players.

Apache is the most popular web server and since its first release it has served more than 50% of all the websites out there. During the last years it has seen some decline due to heavy competition, especially from the likes of Microsoft IIS, but it is still a top player. Being many years in constant development is a feature-rich, stable and fast piece of software.

PHP is a computer language that was build for creating dynamic websites. PHP is used for the server-side code, handling all the requests made by your users on your webpages. So if you have a webpage that does any calculation (do some math, bring up information found on a database, store information provided by the user etc.) it is handled by the PHP code on your page. You might say the PHP acts as the common language between your HTML page and your server.

MySQL is one of the most popular database platforms in the world. As its name suggests it is a derivative of the SQL relational database language. You can call MySQL functions from all major programming languages so you can incorporate database functionality for your programs and websites to store and retrieve information. For example, you could have a MySQL database to store your users' information, such as username and password, and using PHP you could store that information when a user registers in your site and retrieve that information when a user wants to login in your site.

Download and install

All three technologies are freely available for all three major operating systems (Windows, Linux, Mac OSX). You can setup them individually and configure them to work together, or you can download, what is known as, AMP, that incorporates all them. In AMP everything is preconfigured and ready for use from one single package. If you are unfamiliar with these technologies I suggest you use the respective AMP package for your operating system.

  • WAMP for Windows users
  • LAMP for Linux users (Look into your distribution's repositories or software manager to download the LAMP package for your distribution)
  • MAMP for Mac OSX users
Read the documentation of your AMP package for installation instructions. In a few minutes you will be ready to host and develop your website.

Setup your website

Most freely available platforms that are based on AMP, such as Joomla or Wordpress, do not require anything more than a single database on your MySQL setup. You need to create a database for them to use adn then you place your platform on the root directory of Apache (See the documentation from you AMP package to find out where that is) and you are ready to use it.

Lets say that you want to install Wordpress on your computer. After you have downloaded and installed your AMP package you have to create the database that wordpress will use.

Login to mysql using the command line typing

commandline> mysql --user=root mysql (the default password for your root user is usually blank but check with your AMP's manual)


now that you are logged in, you have to create your database

mysql>create database wordpress;

You now need to create a database user for wordpress. Wordpress will use this user to access the database. You do not want your root user to handle this as it it is highly insecure. In addition, remember to change the default password of your root user. On the mysql promt you type

mysql>GRANT ALL PRIVILEGES ON wordpress.* TO 'username'@'localhost' IDENTIFIED BY
'agoodpassword' WITH GRANT OPTION;


Change the ”username” to something else like “wpuser” and a “agoodpasssword” to a difficult password and write them down. The above command creates a user and gives him permissions over the wordpress database that we created before and uses a certain password to access it. Now we are ready to use our new AMP setup to install wordpress on our computer.

Follow the installation notes of wordpress and when it says that you should state what is the database, user and password that will be used, fill in the information that you wrote down before. Congratulations! You just finished setting up your first AMP webserver with wordpress on it. Now, go make that website.

Further reading

Even though, in most case, you will not need to write anything yourself, using SQL or PHP, it is very useful to know a little programming with them. You might need to customize some ready-made plugin for your platform, or write additional functionality that cannot be found in a plugin, or you can just learn for fun.

A very good beginners tutorial for PHP programming can be found at W3Schools.
To learn the basics of SQL programming you can check the guide at databasejournal.com
A very good guide for using MySQL with PHP can be found at databasejournal.com