Setting Up a Web Development Server – Part 4 – Installing the L.A.M.P Stack
Image sourced from VPSHostingHero.com
In Part Three, we installed some helpful applications to use with development – SSH, SFTP, Vim, and Git. In Part Four, we will be installing the L.A.M.P stack – consisting of an Apache web server, MySQL database management system, and the popular open-source language PHP. Part Five will expand a little further, with the installation of Memcached and Varnish Caching.
We will start by installing Apache, followed by PHP and MySQL.
To install Apache on our L.A.M.P stack, run the following command: apt-get install apache2. Accept any prompts to continue by typing the letter y and pressing the Enter key. Apache should now be installed in our virtual machine. To see if Apache is working, navigate to your browser, type localhost:8888 into the browser’s address bar, and press Enter. If your installation worked, you will see something like the following image:
After successfully installing Apache on our L.A.M.P stack, we can now move on and install PHP. We will be installing PHP version 5.6.* (the latest sub-version under 5.6). To enable this, open up your sources.list file (vim /etc/apt/sources.list) and paste the following lines to the bottom of the file:
#To install the latest version of PHP deb http://packages.dotdeb.org wheezy-php56 all deb-src http://packages.dotdeb.org wheezy-php56 all
Save the changes to your sources.list file, then run apt-get update to update the repository. Run apt-get install php5 to install the latest version of PHP.
To see if our PHP installation has worked, we will need to create a small PHP file in our web root (located in the /var/www directory). To do this, run the following command: vim /var/www/phpinfo.php. Once you have the blank file opened, add the following code fragment to it:
&lt;?php phpinfo(); ?&gt;
The ‘phpinfo()’ method call outputs some information about our PHP installation. NOTE: Do not leave this file on a publically accessible website!
Save the changes to the file, then visit the following address in your browser: localhost:8888/phpinfo.php. You should see something like this in your browser:
If you are seeing something like below in the browser…
… run the following command: a2enmod php5. This enables PHP interaction with our Apache server. Once you have ran that command, you will need to restart the Apache server – run the command ‘service apache2 restart’, and refresh the browser. You should now have something resembling the first phpinfo image.
I also highly recommend installing the following extra tools with this command:
apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
This completes the initial PHP installation.
In Step Five, we will begin our MySQL installation on our L.A.M.P stack. Although there are many other types and flavours of databases (e.g. PostgreSQL, MongoDB, MariaDB), we will be installing MySQL for this guide. To begin installing MySQL, run the following command: apt-get install mysql-server. Accept any prompts to continue by typing the letter y and pressing the Enter key.
During the installation process, you will be shown a prompt to enter a new password for the root user. For this guide, we will be using ‘debian’ (without the single quote marks) as the password). You should see something similar to the image below:
Enter the password, then press the Enter key. You will then be asked to confirm the password – type in the password you entered previously, then press the Enter key.
To test our MySQL installation is working, we will be accessing it by using the root user, and we will show databases that have been installed by default. To do this, run the following command: mysql –u root –p. Enter the password when prompted, and press the Enter key. You should now see the following:
To see all the current database tables, run the following MySQL command: SHOW DATABASES;. Because this is a fresh MySQL installation, you should see the three tables as shown below:
To exit out of MySQL, type in the word ‘quit’, then press the Enter key.
To enable interaction between PHP and MySQL, run the following command after logging out from MySQL: apt-get install php5-mysql. After this installation process, run the following command: a2enmod php5-mysql.
This concludes the initial set-up for MySQL,and also Part Four.
Part Four Conclusion
In Part Four, we managed to install components associated with a L.A.M.P stack – Apache, MySQL, and PHP. We also installed and activated some extra PHP and Apache modules. Part Five will take us through the installation of Vanish Caching and Memcached.