How to Easily Create PHP Web Project on Ubuntu

How to create a PHP web project on Ubuntu or Debian and derivatives using LAMP’s localhost server? Make sure you have installed the website development needs locally using Apache and PHP 8 through our previous article, namely: Install LAMP PHP 8 MariaDB 10 Composer Ubuntu

Please refer to the table of contents as follows to facilitate navigation of this article:

Web development requirements

Locally, we can construct websites on Linux by calling localhost from the website under development for testing reasons. There are numerous servers that can be used, including the LAMP stack, the LEMP stack, and the LNMP stack.

The distinction between the two stacks resides in the server type; LAMP stands for Linux Apache MySQL PHP. MySQL PHP requires the Apache server. While LEMP or LNMP stands for Linux Nginx MySQL PHP, employing the Nginx server signifies the use of PHP.

Which is superior: Apache versus Nginx?

There will be benefits and cons for both options. Compared to Intel or AMD processor is superior? Yes, it is identical when viewed from the perspective of the function, and 11-12 indicates that they perform similarly.

For the Apache-based development environment written here. Why? Since Apache came first, Nginx came second. There’s no other explanation. The requirements for a web application must therefore include Apache, MySQL or MariaDB, and PHP. Please utilize the following LAMP installation guide immediately:

Checking LAMP status

If you are not sure whether your Linux machine has Apache, MySQL, and PHP installed, please open a browser (whether it’s Chrome, Brave, Edge, Firefox, etc.) then visit localhost. If it cannot be accessed, please check the status with the following process management reference.

  • Apache: /etc/init.d/httpd (start|stop|status|restart)
  • MySQL/MariaDB: /etc/init.d/mysqld (start|stop|status|restart)
  • Memcached: /etc/init.d/memcached (start|stop|restart)
  • Redis-Server: /etc/init.d/redis-server (start|stop|restart)
See also  How to Install Microsoft Visual Studio Code (VS Code) for Ubuntu Linux

Example usage to check Apache, MySQL, and check our PHP version using the following command (type one by one):

sudo /etc/init.d/httpd status
sudo /etc/init.d/mysqld status


#result from Apache or httpd
httpd (pid 3106) is running

#result from MySQL status
SUCCESS! MariaDB running (2480)

#result from checking php version
PHP 8.1.10 (cli) (built: Sep  7 2022 17:36:31) (ZTS)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.10, Copyright (c), by Zend Technologies
    with Xdebug v3.1.3, Copyright (c) 2002-2022, by Derick Rethans

Change ownership

The thing that needs to be done when the installation is complete and making sure Apache, MySQL, and PHP are running is to change the ownership, which is the ownership of files on the Linux system. It’s easy like this: when on Windows, you use XAMPP to run Apache-MySQL-PHP and put the website files in the xampp/htdocs folder and create a folder name and then put the files there.

Now on Linux, my friend puts the website file in /data/www/default and creates a folder name for us to fill with website files. The problem is, on Linux we can’t directly copy and paste files or folders in the path/data/www/defaultwe need to change the ownership to be free to delete, make or other modifications in the path.

How to change ownership for the path is to open Terminal and type:

sudo chmod +777 -R /data/www/default

Next, please checks whether in the /data/www/default path you can create folders, files, rename and so on. If you can, then we have finished setting up the website development environment and are ready to be used to create the first project.

See also  How to Install Lazarus IDE (Delphi Qt5) on MX Linux

Creating a PHP web project on Linux

There are two steps to create php web project on Linux, namely creating a folder, and the second creating and editing website files.

Create a website project main folder

This project folder functions to store all website files so that they are neatly arranged in a folder. Buddy can create another folder in this main folder. In addition, this main folder serves to call our web project through the browser. For example, create a training folder in the path /data/www/default

The created folder in data/www/default

Creating website files

Because we are developing a PHP-based website, the extension used is .php

Please open your favorite text editor, it can be Sublime, Geany, if I’m Visual Studio Code . If the editor is already open, please write the following php web code:

<!DOCTYPE html>


echo "Welcome, I enjoy learning this PHP";

Save it in the training folder or the path /data/www/default/latihan with the name index.php . Then open the browser and call the name of the training folder via localhost/latihan from the browser. If successful, it will display:

Result of calling localhost/practice create php web
Result of calling localhost/latihan

Call to Action

Besides create php web project from stracth, you can also copy and paste the folder from the website project directly into the path /data/www/default then call the php web via the browser with localhost/folder_name ; here folder_name is the name of the folder in the data path.