Install LAMPby Stefan Kecskes on
LAMP stands for Linux - Apache - MySql - PHP. This is basically everything you need to have a fully working testing server on your machine. Some parts of LAMP may already be installed on your system. If so uninstall them. I will assume, that nothing is installed and we will install all parts of LAMP. The following steps should be same and compatible with all Debian based systems (Ubuntu is one of them). We will use Advanced Packing Tool (apt) to install these tools, rather than compiling them from code sources.
We already have Linux, so now we will install:
- Apache 2.4, the web server which will serve the requests and responses
- PHP 5.6, the engine which will process the request and return dynamic responses
- MySQL 5.6, the database to store and read data from.
Installing Apache 2.4
We will add Personal Package Archive (PPA) as the standard APT repository has some ancient version of Apache. I think they do this on purpose as having old but stable versions of tools in repository offers backwards some compatibility with other older tools. However we as webdevelopers understand that older versions has lot of bugs and are also slower, therefore we will try to use the newest tech. Type in terminal following three lines:
sudo add-apt-repository ppa:ondrej/apache2 sudo apt-get update sudo apt-get install apache2
The above code added repository from
ondrej/apache2 into our APT repository. This package contains usually the latest versions of apache2 and I use it for some years also in productions environments.
After adding this PPA to the list of repositories, we have to run
update, so that the system will pull down the latest list of software from each archive it knows about, including the PPA you just added . Finally, we can
install apache2 from the repository.
To check the version of installed Apache server, run in terminal:
At the time when I wrote this document (2.7.2015) the version in this repository is 2.4.12, see bellow
Server version: Apache/2.4.12 (Ubuntu) Server built: Feb 4 2015 14:20:03
Installing PHP 5.6
Installing the PHP is very similar to Apache. Again we will add the PPA from ondrej, who maintains these packages regularly and compiles the source, so that we don't have to compile. Currently there are different packages we could use. I would not develop for 5.4 as the support already ended and the security support will end in September 2015. I mention them just in case, somebody will need to work on some older project or wants to test the new PHP 7. PHP version is currently in alpha version and will be released only in October 2015, so don't use it on production environment yet. Check PHP Supported version for more details.
|PHP Version||Personal Package Archive|
|PHP 5.6 + 7.0||ppa:ondrej/php|
Today we will use the PHP in version 5.6, so type in terminal
sudo add-apt-repository ppa:ondrej/php5-5.6 sudo apt-get update sudo apt-get install php5
The above code will
add the repository to our system, then we
update the system with list of packages in repositories and finally
install php5 package. We are done with PHP and we can check the version of installed PHP with
Mine installed version is 5.6.10
PHP 5.6.10-1+deb.sury.org~trusty+1 (cli) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
In case you want to play with different versions and for example install version 5.4, you will need to:
- remove the php5 package
- remove the repository from your system
- add the new repository
- update the system with packages list of used repositories
- install the php 5.4
The above steps are here:
sudo apt-get remove php5 sudo ppa-purge ppa:ondrej/php5-5.6 sudo add-apt-repository ppa:ondrej/php5-oldstable sudo apt-get update sudo apt-get install php5
Installing MySQL 5.6
LAMP stack uses the MySQL server as the database. The database servers usually runs on different server as the apache webserver, because of the performance requirements, but for our development environment, we can have mySQL on same system.
|SQL Version||Personal Package Archive|
We will again
add one of the PPAs into our system, then
update the list of software in repository and then
install mysql-server. I will install mySQL 5.6:
sudo add-apt-repository ppa:ondrej/mysql-5.6 sudo apt-get update sudo apt-get install mysql-server
You will be asked to provide password for the root user during installation. I usually set something simple (like
toor), as this will be only database on your local machine.
To check the installed version type in terminal:
That will login you into mysql console and the welcome screen will show you the version. Mine mysql showed version 5.6.24:
stefan@freya:~/.ssh$ mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 47 Server version: 5.6.24-2+deb.sury.org~trusty+2 (Ubuntu) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
exit to exit the mysql console and go back to terminal.
The development environment
The development environement is now ready. If you visit http://localhost in your favourite browser now, you will see the Apache2 Default Page.