Install Linux,Apache,mysql,php (LAMP) in ubuntu 18.04
LAMP stands for Linux, Apache, MariaDB/MySQL and PHP, all of which are open source and free to use. and it is very popular, open source web development platform that can be used to run and deploy dynamic websites and web-based applications etc.
In this tutorial we are using below system details
OS: Ubuntu 18.04.3 LTS server Edition
you need to login with ubuntu user with sudo privileges or root user.Here i have loggedin with rot user.
Step 1: Install Apache web server
First we will update packages with following command
root@ubuntu18:~# apt update
Once it is done, install apache web server
root@ubuntu18:~# apt install apache2
After apache is installed,check service is started or not with following command
root@ubuntu18:~# systemctl status apache2
root@ubuntu18:~# systemctl status apache2 ● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: active (running) since Thu 2020-01-23 11:16:02 UTC; 5min ago Main PID: 2542 (apache2) Tasks: 55 (limit: 1670) CGroup: /system.slice/apache2.service ├─2542 /usr/sbin/apache2 -k start ├─2544 /usr/sbin/apache2 -k start └─2545 /usr/sbin/apache2 -k start Jan 23 11:16:01 ubuntu18 systemd: Starting The Apache HTTP Server... Jan 23 11:16:02 ubuntu18 apachectl: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' Jan 23 11:16:02 ubuntu18 systemd: Started The Apache HTTP Server.
you can check apache version and enable Apache to automatically start at system boot time.
root@ubuntu18:~# apache2 -v Server version: Apache/2.4.29 (Ubuntu) Server built: 2019-09-16T12:58:48 root@ubuntu18:~# systemctl enable apache2 Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable apache2
Now allow apache in firewall if it is running and enabled in your server.
root@ubuntu18:~# ufw app list Available applications: Apache Apache Full Apache Secure OpenSSH
Here if we look at Apache Full profile, it should show that it enables traffic to ports 80 and 443.
root@ubuntu18:~# ufw app info "Apache Full" Profile: Apache Full Title: Web Server (HTTP,HTTPS) Description: Apache v2 is the next generation of the omnipresent Apache web server. Ports: 80,443/tcp
Allow incoming HTTP and HTTPS traffic for this pofile with following command
root@ubuntu18:~# ufw allow in "Apache Full" Rule added Rule added (v6)
Step 2: Install mysql
root@ubuntu18:~# apt install mysql-server
once it is installed check mysql service is running or not with below command.
root@ubuntu18:~# systemctl status mysql ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2020-01-23 12:01:34 UTC; 1min 12s ago Main PID: 4100 (mysqld) Tasks: 27 (limit: 1670) CGroup: /system.slice/mysql.service └─4100 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid Jan 23 12:01:32 ubuntu18 systemd: Starting MySQL Community Server... Jan 23 12:01:34 ubuntu18 systemd: Started MySQL Community Server.
By default root password is empty.Now you need to set mysql root password to secure database.For that run below command.
It will ask you want to setup VALIDATE PASSWORD plugin or not.this allows users to set strong password as per password policy.If you press 'Y' it will ask you to choose level of password validation.
VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: Please set the password for root here.
If you want to disable that plugin and enter any other key and set strong password for security purpose.
and press Y or Enter for every prompt after root password is set.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : ... skipping. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : ... skipping. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : ... skipping. All done!
now you can check root password by below command
root@ubuntu18:~# mysql -u root -p Enter password:
if you are able to login to mysql shell then it success.
check mysql version with below command.
root@ubuntu18:~# mysql --version mysql Ver 14.14 Distrib 5.7.28, for Linux (x86_64) using EditLine wrapper
Step 3: Install php
To install php run following command.
root@ubuntu18:~# apt install php libapache2-mod-php php-mysql
we can check php version by using below command.
root@ubuntu18:~# php -v PHP 7.2.24-0ubuntu0.18.04.2 (cli) (built: Jan 13 2020 18:39:59) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.24-0ubuntu0.18.04.2, Copyright (c) 1999-2018, by Zend Technologies
you can also install php modules like php-gd,php-xml,php-json,php-pdo etc as per your requirement. After installing these modules restart apache service.
Step 4 : Test php in browser
once php is installed you can create info.php in apache document root folder.
Apache default document root is /var/www/html/ now we will create info.php
root@ubuntu18:~# vi /var/www/html/info.php
Add below lines to above file and save it.
<?php phpinfo(); ?>
After that restart apache service to effect changes.
root@ubuntu18:~# systemctl restart apache2
Now we can test in browser and type in your http://ip_address/info.php
you will see sample output like below.