Install Apache MySQL PHP (LAMP Stack) on Ubuntu 16.04LAMP (Linux, Apache, MySQL and PHP ) Stack is the most popular environment in PHP website development and hosting. Linux is the 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 an development language.
Step 1: – Install PHP
PHP 7 is the default available packages in Ubuntu 16.04 repositories. Simply use the following commands to update apt cache and install PHP packages on your system.
$ sudo apt update $ sudo apt install -y phpVerify installed PHP version using following command.
root@hackthesec:~$ php -v PHP 7.0.4-7ubuntu2 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend TechnologiesStep 2: – Install Apache2
Installation of Apache2 in your system. Also required to install libapache2-mod-php module to work PHP with Apache2.
$ sudo apt install apache2 libapache2-mod-phpStep 3: – Install MySQL
Install mysql-server packages for MySQL database and install php-mysql package to use MySQL support using php.
$ sudo apt install mysql-server php-mysqlInstaller will prompt for root password, This password will work for your MySQL root user. After installing MySQL execute following command for initial settings of MySQL server. You will she that script will prompt about more settings than earlier mysql versions like password validation policy etc.
$ sudo mysql_secure_installationStep 4: – Restart Apache2, MySQL Services
After installing all services on your system, start all required services.
$ sudo systemctl restart apache2.service $ sudo systemctl restart mysql.serviceStep 5: – Open Access in Firewall
If you are using iptables, Use following commands to open port 80 for public access of webserver.
$ sudo iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPTAnd For UFW follow the bellow command
$ sudo ufw allow 80/tcpStep 6: – Test Setup
After completing all setup. Let's create a info.php file website document root with following content.
<?php phpinfo(); ?>