Setting up the environment | PHP Tutorial

As discussed earlier, PHP is a server-side scripting language and needs a server to execute. We can either purchase a server online to test our code or we can setup a local development environment for PHP on our Windows/Linux/Mac OS system for free.

Let’s start with setting up local development on Linux based systems, here I’m using an example of an Ubuntu system –

Install LAMP in Ubuntu (PHP Environment Setup)

We’ll be setting up a LAMP stack on our Ubuntu based system. LAMP is a basically a collection of Apache, PHP and MySQL which we’ll require to execute our dynamic PHP based websites.

– Open your terminal

– Execute the following command to make sure your index is upto date

Instead of installing each component separately, we can install complete LAMP stack using Tasksel.

– Install Tasksel if not already installed by default –

 Use the tasksel to install the LAMP stack:

In Ubuntu based systems, the default path of your files for your local server is –

/var/www/html/

Now open your browser to check weather everything is installed properly or not –

In the URL tab type

http://localhost

LAMP Server Ubuntu

If you can see the above page, it means your Apache server is working properly.

To check if your php is working

– Go to /var/www/html and create a new file with .php extension (test.php).

– Open the file and type in the following code in it.

 – Save the file and open it in your browser using following URL

http://localhost/test.php

– If you can see an output as mentioned below, your PHP has been installed properly.

Lamp Server PHP in Ubuntu

NOTE – When you type “localhost” in your browser it points to the /var/www/html/ directory, therefore your PHP Files and Folders needs to be placed in this directory.

Also Check – How to install phpmyadmin in Ubuntu

Author: Deepak Kumar

This is Deepak Kumar, founder of True Infosystems and of-course the chief content creator at CodingLessions.info. Started my carrier as a Freelancer and now a top-rated Freelancer at Upwork, delivered over 200 successful projects with highly positive user ratings and counting.