What is a LAMP Stack

LAMP stack is a popular open source web platform commonly used to run dynamic web sites and servers. It includes Linux, Apache, MySQL, and PHP and is considered by many the platform of choice for development and deployment of high performance web applications which require a solid and reliable foundation. It's easy to deploy and it's no coincidence that Wordpress and other web platforms are using it to power today's web.

Creating a simple PHP application

As usual, we'll start by creating a simple "Hello World" application, so let's start by opening the index.php file that already exists in your new SourceLair project. The file has the following contents:

Making the application dynamic

Hey, PHP is here for dynamic applications, not static websites like the one we just created. Let's make our little application dynamic. For example, let's make it load with a different colored text each time. Create a new php tag at the start of the document and create the needed functions there.

Speeding up development with Split View

Public URL is very handy in most cases, but there are times you want to test results right away without switching away from your project. This is why we have created Split View. Split View allows you to see changes right next to your code. To open Split View, just hit Ctrl + Enter (or Cmd on a Mac), or use the "Preview" button, which is above the editor.

Now, make any change you want - for example remove the dynamic color in the heading - and press save (Ctrl + S or Cmd on a Mac). Tada! Your website automatically refreshes.

Installing packages

We will use Composer to install packages in PHP. Composer is one of the most common dependency managers for PHP. In order to define which requirements your application has, you need to create a composer.json file and add packages in the following structure:

{
"require": {
"monolog/monolog": "1.0.*"
}
}

Create the file above, since we're going to use Monolog for a quick logging demo in the next step.

In order to install your composer dependencies in SourceLair, all you have to do is open the Command Palette, type "Composer" and press enter. After the installation finishes, just add the following code in the start of the first php tag and refresh your Public URL a couple of times.

Bonus: Adding a database to our project

When you created your project, there was a step about adding a MySQL database to it. If you chose not to, you can still add a database to your project from the Project Settings - accessible using the gear icon next to the project name - by pressing the "Connect a Database" button.

Notice: This is a paid feature, but within your first 30 days after signing up, your first database is free, so you can easily test this without spending a cent.

Now that you have created and connected a MySQL database to your project, let's add a simple visitor counter to our application.

First, let's create a new database and a new table in MySQL. In your Terminal, type the following to connect to your MySQL.

Next up

Now that you have learnt the basics of PHP, you can either go on and create your own dynamic website, or even better use a framework to make your life easier. There are plenty of them available and below are some links to help you get started: