How to Run a PHP Application on Ubuntu

PHP, one of the popular server-side scripting language widely used for developing web backends is losing its magic. We know that Python and JavaScript are taking the positions of PHP nowadays because of Django, Flask, Nodejs etc. are easy to learn and trending. So the communities are also concentrating on these trending technologies. But we have to accept the reality that more than 60% of the web is powered by PHP. Here I am going to explain the steps in running a PHP application on the Ubuntu operating system.


Install PHP

To run a PHP application on Ubuntu, first, we have to install the latest version of PHP on our system. This can be done by the following step.

sudo apt-get install php

Install Apache2

Now we need to install a web server to run PHP because PHP runs in the backend. Apache2 is the popular web server for this. We can install apache2 using the below command.

sudo apt-get install apache2

After the installation, type


on your browser and it returns an “Apache2 Ubuntu Default Page“.

The apache2 installation will make /var/www/html folder structure on your system. This is our system’s localhost directory. We can see an index.html file inside this directory which contains the HTML we saw before(“Apache2 Ubuntu Default Page“).

We need to paste or clone our PHP application in this directory to run. But it requires one more step. Setting the permission to write to this directory. It can be done by the below command.

sudo chmod 777 -R /var/www/html

Note that, this permission gives all users to write to this directory and is not safe. Change it after all the steps are done.

Clone/Paste PHP our application inside /var/www/html

Now we need to clone or paste our PHP application inside /var/www/html directory.

If your project is in Git, cone it with the below command.

git clone [git_repository_url]

Or, if your project is in another directory, copy and paste it to /var/www/html.

Install packages/dependencies (optional)

If our PHP application using any packages/dependencies, we have to install it. The Composer is the most popular package manager for PHP. Running the below command from the root directory of our project install the packages in the package.json file.

composer install

Running our project

After everything is set, we can access our project from our browser window. I am assuming that my_php_app is the project directory we pasted/cloned in the previous step. Now we can start our PHP app using the URL.


This will open our PHP app on our browser.

Note that, it only works if our project’s root directory contains index.php or index.html. If not, use the below URL.


You May Also Like

About the Author: Syamlal CM

Hi, I'm Syamlal, the co-founder of Redmonark. I'm a developer, writer and also have a little bit of experience in graphic designing.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.