The LAMP Stack (Linux, Apache, MySQL, and PHP) is the most popular web hosting environment for the PHP based application. Here Linux is an operating system, Apache is the popular web server developed by Apache Foundation, MySQL is relational database management system used for storing data and PHP is the widely used programming language.
This article will help you to Install Apache 2.4, MySQL 5.7 and PHP 7.2 on Ubuntu 18.04 (Bionic Beaver) LTS Systems. Let’s start with LAMP Stack setup on an Ubuntu machine.
You must have root or sudo privileged user access to your Ubuntu 18.04 system. Login to your Ubuntu system using GUI for Desktop and SSH for the server edition.
Now upgrade current packages to latest version.
sudo apt update sudo apt upgrade
2. PHP Installation
Ubuntu 18.04 has default PHP 7.2 for installation. But we suggest adding additional PPA for PHP installation which includes multiple other versions of PHP. Use the following commands to update apt cache and install PHP packages on your system.
sudo apt-get install python-software-properties sudo add-apt-repository ppa:ondrej/php sudo apt update sudo apt install -y php7.2
You may also need to install some additional PHP modules for supporting various tasks
sudo apt install php7.2-curl php7.2-gd php7.2-json php7.2-mbstring php7.2-xml
3. Apache2 Installation
After installing PHP on your system, let’s start the installation of Apache2 in your system. Your also required to install libapache2-mod-php module to work PHP with Apache2.
sudo apt install apache2 libapache2-mod-php7.2
To create additional virtual hosts visit this tutorial.
4. MySQL Installation
Finally, install mysql-server packages for MySQL database. Also, install php-mysql package to use MySQL support using php. Use the following command to install it.
sudo apt install mysql-server php7.2-mysql
The installer will prompt for root password, This password will work for your MySQL root user. After installing MySQL execute the following command for initial settings of MySQL server. You will see that script will prompt for more settings than earlier MySQL versions like password validation policy etc.
You can also install phpMyAdmin for the administration of MySQL using web interface.
sudo apt install phpmyadmin
5. Restart Services
After installing all the services on your system. Restart MySQL and Apache service to reload any changes done manually.
sudo systemctl restart apache2.service sudo systemctl restart mysql.service
6. Configure Firewall
The systems with iptables/ufw enabled, execute the following commands to open port 80 for public access of web server.
sudo iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
sudo ufw allow 80/tcp
7. Test Setup
After completing all setup. Let’s create a info.php file website document root with following content.
<?php phpinfo(); ?>
Now access this file in web browser. You will see the screen like below with all details of PHP on server.