2015-01-30

LAMP is an acronym that stands for Linux, Apache, MySQL, PHP - a stack of technologies that work together to shine light on your project by enabling your server to host dynamic websites and applications.

Linux is the operating system, and it powers the others which in turn handle specific tasks related to management of websites and apps.

Because we'll be working on an Ubuntu 14.04 Snapshot Linux is already taken care of for us. The Snapshot also has some other technologies already in place, and so all that's left to do is configure them, install some helper-packages, and make sure everything is up and running properly.

One of the major benefits that Terminal.com provides is the ability to work from root inside a container. However, as is discussed in our article 3 Tips for Superheroes and Superusers, performing tasks from root can leave the door open for accidental destruction. If you're new to linux, I suggest you begin there, create a non-root user on your server, and familiarize yourself with the concept of sudo usage.

Before we begin we'll want to run two quick commands:

sudo apt-get update

sudo apt-get install nano

The first runs a quick update and ensures you've got access to the most up-to-date software packages. The second downloads a great command line text editor called Nano, which will allow you to create the documents we'll be working with directly from your command line if you like.

The commands in this tutorial will work whether your operating from root or as a non-root user with sudo permissions. I'll leave the option open to you, but suggest that at the very least you create a snapshot of your server before you begin changing things, that way your past work is safe.

Apache

Apache is a web server. Its job is to hand over the proper files when someone requests them. It's open source, free to use, extremely powerful, and backed by a team of highly dedicated developers, all of which has led to it's current position as the most popular web server in the world.

It also comes pre-installed on Terminal's Ubuntu 14.04 Snapshot which enables you to share sites hosted on your Terminal with the world.

You can check to ensure Apache is up and running by navigating to port 80 of your Terminal in a web browser. There are two ways to do this quickly. You can either:

Use the Browser in Terminal's IDE, typing localhost:80 into the browser bar and pressing enter.



Or Open a New Tab in Your Browser and type the following into your URL Bar. Be sure to substitue the name of your Terminal for the highlighted text, which can be found in the URL bar of your IDE:

https://terminalIdentifier-80.terminal.com/

Your Terminal Identifier is the first part of the URL found in the URL bar inside your IDE.



Whichever method you choose you should see the Adobe Default page returned to the screen. This is for testing purposes, and it looks like this:



There's one adjustment we're going to make to Apache before we're done. LAMP is a stack for serving up dynamic web pages and apps, and by definition, that will generally mean pages are .php files, not strictly .html documents. We want to tell our Apach server to look for PHP files first, and we'll do this by altering one line in an important file.

Navigate to /etc/apache2/mods-enabled/dir.conf either by tracing your way through the directories in the file tree and opening the document in the IDE's text editor or by running sudo nano /etc/apache2/mods-enabled/dir.conf

You should see text that looks like this. The bit we're concerned with has been highlighted here for you.

Which we will move to the front of the line so that the new text looks like

Then save the file and close it.

MySQL

Installing MySQL is easy. Simply run

sudo apt-get install mysql-server

You'll be asked to set a new password for the root MySQL account. It's important to note that this is not your server's root account, but one specifically for accessing MySQL.

Follow the prompt to set a password (type carefully since no characters will appear on the screen) and then let MySQL finish installing.

Next you want to set up the database directory structure by running

sudo mysql_install_db

This is a good time to mention helper packages too. Helper packages are optional components you can install to extend the functionality of a given technology. In our case, we'll want to install some helper packages that enable PHP, MySQL, and Apache to work well together.

We're going to begin by installing a package called php5-mysql:

sudo apt-get install php5-mysql

If you ever want a detailed description of what a particular package does, you can look it up by name by typing apt-cache show package-name on the command line. For a list of all available helper packages and a brief description of what they do simply run apt-cache search mysql subbing in the name of the technology you'd like to extend.

Finally, we want to run the following security script, which will ask you a series of questions related to some default settings

sudo mysql_secure_installation

It will begin by asking for the password you set on the MySQL account. Go ahead and enter it.

It will then ask if you'd like to change the password, for which you can simply type "n" for no if you're happy with the password you set. Simply press 'Enter' for all of the remaining questions and the script will handle the rest.

PHP

PHP is a server side scripting language that helps to create dynamic content by running scripts and pulling information from a database like MySQL for use in webpages.

There's a very easy test you can use to check and see if you've already got PHP installed and running on your server.

Navigate through the IDE's file tree to the var/www/html/ directory and create a document called info.php.

Copy and paste the following into the document and save it.

Then go to your browser and navigate to the new info.php document by appending /info.php to the apache URL we used. Don't forget to include th port number -80 in the URL

https://terminalIdentifier-80.terminal.com/info.php

If PHP is installed you'll see a default page similar to the Apache Page we saw a moment ago.

If it's not you will simply see the contents of the info.php document written out.

PHP doesn't come installed on the Ubuntu 14.04 Snapshot, so if you're not seeing the Default Page, simply install PHP by running

sudo apt-get install php5

That 5 is not a typo. Be sure to include it when you run this command otherwise the computer will tell you very politely that it has no idea what you're talking about.

After you've run the install, simply refresh the browser page where you're trying to access info.php. Once you see that you've got the correct page you know PHP is up and running, it's important to delete the info.php file you created.

We're going to install two other helper packages that work with PHP.

sudo apt-get install libapache2-mod-php5 php5-mcrypt

Note how I've gone ahead and installed both using a single command. Using apt-get install you can install several packages at once by simply seperating them with a single space. This saves on time, reducing the number of commands you need to type.

sudo apt-get install package-name-1 package-name-2 ...

Conclusion

Now that you've configured and tested Apache, secured MySQL, enabled and checked PHP, and added some helper packages to ensure everything plays nicely together, you can officially consider yourself the proud owner of a LAMP stack server.

You're well on your way to building a dynamic website and sharing it with the world.

Show more