- Step 1 [Install LAMP] – Install apache2
- Step 2 – Install mariadb
- Step 3 – Prepare Ubuntu For PHP Development with PHP and mod-php
- Step 4 – Prepare Ubuntu For PHP Development With Common PHP Extensions
- Step 5 – Prepare Ubuntu For PHP Development, Install Composer
- Step 6 – Install phpMyAdmin
- step 7 – Check If Lamp Is Working
- Start To Develop In PHP
In this tutorial, We see how to install LAMP and to prepare Ubuntu for PHP development.
First, what is LAMP? LAMP is a common and popular web service stack. You can use LAMP for building dynamic websites and web applications.
LAMP is an acronym, and it stands for:
- L stands for Linux operating system.
- A stands for Apache HTTP Server.
- M stands for MySQL relational database or its fork MariaDB.
- P stands for PHP PHP programming language.
Let’s see how to install each component in the LAMP stack on Ubuntu and integrate Apache, MySQL, and PHP.
Step 1 [Install LAMP] – Install apache2
Install the apache2 package by invoking apt – The Ubuntu package manager.
user@demo:~# sudo apt install -y apache2 ...
Step 2 – Install mariadb
Let’s install the mariadb package with the help of apt
user@demo:~# sudo apt install -y mariadb-server ...
Step 3 – Prepare Ubuntu For PHP Development with PHP and mod-php
Now, We install PHP and mod-php apache2 module. The mod-php apache2 module allows the apache server to execute and dynamically serve PHP scripts.
user@demo:~# sudo apt install -y php libapache2-mod-php ...
Step 4 – Prepare Ubuntu For PHP Development With Common PHP Extensions
he default php package is a basic package and does not include all the extensions of the PHP language. Now, It is time to install common extensions. We install the following PHP extensions:
- php-mysql allows PHP scripts to connect to MySQL server and fetch data from the database or store data in the database.
- php-dom enables PHP scripts to read or write XML documents through the DOM API.
- php-zip allows PHP scripts to access ZIP compressed archives and read or write files inside them.
user@demo:~# sudo apt install -y php-mysql php-dom php-zip ...
You can also install your favorite extension in this step. You can find here a list of PHP extensions here. To find the name of ubuntu package of the PHP extension, try to add the prefix php- . That is, suppose you want to install the PHP extension xsl , Try to install the package php-xsl.
Step 5 – Prepare Ubuntu For PHP Development, Install Composer
Composer is the defacto dependency management tool for PHP and has gain popularity with PHP developers. Let’s install it.
user@demo:~# sudo apt install -y composer
Step 6 – Install phpMyAdmin
While you can use mysql command-line client or MySQL workbench visual tool for database administration, I prefer to use the phpMyAdmin web application for this task. Let’s install it.
user@demo:~# sudo apt install -y phpmyadmin
Follow the install wizard:
| Please choose the web server that should be automatically configured to │ │ run phpMyAdmin. │ │ │ │ Web server to reconfigure automatically: │ │ │ │ [*] apache2 │ │ [ ] lighttpd │ │ │
Select apache2 and click OK
| The phpmyadmin package must have a database installed and configured │ │ before it can be used. This can be optionally handled with │ │ dbconfig-common. │ │ │ │ If you are an advanced database administrator and know that you want to │ │ perform this configuration manually, or if your database has already │ │ been installed and configured, you should refuse this option. Details on │ │ what needs to be done should most likely be provided in │ │ /usr/share/doc/phpmyadmin. │ │ │ │ Otherwise, you should probably choose this option. │ │ │ │ Configure database for phpmyadmin with dbconfig-common? |
Now provide the the password and verify
│ Please provide a password for phpmyadmin to register with the database │ │ server. If left blank, a random password will be generated. │ │ │ │ MySQL application password for phpmyadmin: |
| Password confirmation: |
We want to phpmyadmin to serve at port 8080. To do so, Edit
- Comment the exising directives at the begining of the file (alias and directory)
- Add the virtual host and Listen directives
Now restart apache2
user@demo:~# sudo service apache2 restart
Now you can connect to phpmyadmin at port 8080.
step 7 – Check If Lamp Is Working
Now , we can start develop our site in PHP.
Your document root is under /var/www/html.
Let’s check whether we successfully configure apache. Open /var/www/html/main.php in favorite editor and enter the following content:
Now, access http://demo/main.php in your webbrowser. You should see the familiar page:
Start To Develop In PHP
We see how to prepare Ubuntu for PHP development. With the help of apt package manager, we easily installed apache2, MySQL, PHP and common PHP extension such as php-mysql. We also install tools that make our PHP development easier such as composer and phpmyadmin.
Now you have all the tools to start to develop in PHP. Happy coding!!