How to install LAMP on Ubuntu 17.04

How to install LAMP on Ubuntu 17.04

LAMP stack is a group of tools installed on a server to enable hosting dynamic websites and web apps. The acronym stands for: Linux, Apache, MySQL/ MariaDB, PHP, Perl, and Python. This tutorial covers the installation procedure of LAMP on Ubuntu 17.04.

Installation procedure

To start the installation procedure, install the Apache package by executing the following command and press y to continue with the installation procedure

root@linuxhelp1:~# apt-get install apache2 -y
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 linux-image-4.10.0-21-generic
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom fdutils linux-doc-4.10.0 | linux-source-4.10.0 linux-tools linux-headers-4.10.0-21-generic
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0
.
.
.
user.target.wants/apache-htcacheclean.service &rarr  /lib/systemd/system/apache-htcacheclean.service.
Processing triggers for libc-bin (2.24-9ubuntu2) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (232-21ubuntu2) ...
Processing triggers for ufw (0.35-4) ...

The Apache is successfully installed. Start and enable the Apache service by executing the following commands.

root@linuxhelp1:~# systemctl start apache2
root@linuxhelp1:~# 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

The Apache is running successfully. Install the MySQL server by executing the following command and press y to continue the installation procedure.

root@linuxhelp1:~# apt-get install mysql-server -y
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following additional packages will be installed:
  libaio1 libevent-core-2.0-5 libhtml-template-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
Suggested packages:
  libipc-sharedcache-perl mailx tinyca
The following NEW packages will be installed:
  libaio1 libevent-core-2.0-5 libhtml-template-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7 mysql-server-core-5.7
0 upgraded, 9 newly installed, 0 to remove and 42 not upgraded.
Need to get 21.5 MB of archives.
.
.
.
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service &rarr  /lib/systemd/system/mysql.service.
Setting up mysql-server (5.7.18-0ubuntu0.17.04.1) ...
Processing triggers for libc-bin (2.24-9ubuntu2) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (232-21ubuntu2) ...

The MySQL is installed successfully. Start and enable the MySQL service by running the following command.

root@linuxhelp1:~# systemctl start mysql
root@linuxhelp1:~# systemctl enable mysql
Synchronizing state of mysql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mysql

The MySQL service is running successfully. Install the PHP package with extensions and press y to continue with the installation procedure.

root@linuxhelp1:~# apt-get install php libapache2-mod-php php-mcrypt php-mysql -y
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following additional packages will be installed:
  libapache2-mod-php7.0 libmcrypt4 php-common php7.0 php7.0-cli php7.0-common php7.0-json php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-readline
Suggested packages:
  php-pear libmcrypt-dev mcrypt
The following NEW packages will be installed:
  libapache2-mod-php libapache2-mod-php7.0 libmcrypt4 php php-common php-mcrypt php-mysql php7.0 php7.0-cli php7.0-common php7.0-json php7.0-mcrypt php7.0-mysql php7.0-opcache
.
.
.
apache2_switch_mpm Switch to prefork
apache2_invoke: Enable module php7.0
Setting up libapache2-mod-php (1:7.0+49) ...
Setting up php7.0 (7.0.18-0ubuntu0.17.04.1) ...
Setting up php (1:7.0+49) ...
Processing triggers for libc-bin (2.24-9ubuntu2) ...

Create a sample info.php file under document root of Apache and enter the following lines of code in the file. Save and exit from the file.

root@linuxhelp1:~# vim /var/www/html/info.php
< ?php
phpinfo() 
?> 

Now open the browser and check Apache as well as PHP service by entering the target system ip address http://192.168.7.232 in the browser. The default page of Apache appears in the browser.

Type the target system IP address http://192.168.7.232/info.php along with the file name (info.php) that is created under the document root.

Wasn' t that an easy installation procedure? Now the LAMP stack can be used to host dynamic websites or web apps.

Tag : LAMP Ubuntu
FAQ
Q
how to check the version and module installed in php?
A
Execute the following command:
#php -v
#php -m
Q
How to Start and enable the Apache service?
A
executing the following commands:
# systemctl start apache2
# systemctl enable apache2
Q
In how many ways we can retrieve the data in the result set of MySQL using PHP?
A
You can do it by 4 Ways
1. mysql_fetch_row.
2. mysql_fetch_array
3. mysql_fetch_object
4. mysql_fetch_asso
Q
How do I start a LAMP server in Ubuntu?
A
Use the following steps to start the LAMP server in Ubuntu:
1. Install Ubuntu. ...
2. Open a terminal. ...
3. Installing additional tasks Inside your terminal, type: sudo taskbar and press enter.
4. Select the task Lamp Server, press tab, and then press enter to install.
5. Set the MySQL password for the root account It may ask you to set the password twice.
Q
What is the LAMP in Ubuntu?
A
LAMP stack is a group of tools installed on a server to enable hosting dynamic websites and web apps. The acronym stands for Linux, Apache, MySQL/ MariaDB, PHP, Perl, and Python.