• Home
  • DevOps
  • How To
  • Cloud
  • Security
  • Monitoring
  • Web
  • OS
tutorials-space.com
Menu
  • Home
  • DevOps
  • How To
  • Cloud
  • Security
  • Monitoring
  • Web
  • OS
Home  /  Apache • DevOps • Web  /  How To Install Apache, MySQL and PHP (LAMP) on Ubuntu 18.04
27 December 2018

How To Install Apache, MySQL and PHP (LAMP) on Ubuntu 18.04

Written by aghouchaf
Apache, DevOps, Web apache, web Leave a Comment

Table of Contents

  • 1. Introduction
  • 2. Prerequisites
  • 3. Installing MySQL
  • 4. Installing PHP
  • 5. Testing PHP Processing on your Web Server

1. Introduction

The LAMP stack is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps, Apache, MySQL and PHP (LAMP) software stack.

  • Linux: The operating system (OS) makes up our first layer.
  • Apache: The second layer consists of web server software.
  • MySQL: Third layer is server hhere databases stored.
  • PHP: The scripting layer consists of PHP and other similar web programming languages. Websites and Web Applications run within php.

2. Prerequisites

In order to complete this tutorial, you will need :

  1. you will need to have an Ubuntu 18.04 server.
  2. Update your system: sudo apt update && sudo apt upgrade

Install Apache using Ubuntu’s package manager, apt:

sudo apt update sudo apt install apache2 

to verify that everything went as planned by visiting your server’s public IP address in your web browser http://your_server_ip

And you can use curl utility to verify that apache is up:

sudo apt install curl 
curl http://your_server_ip

3. Installing MySQL

Now that you have your web server up and running, use apt to acquire and install this software:

sudo apt install mysql-server 

When the installation is complete, run a simple security script that comes pre-installed with MySQL which will remove some dangerous defaults and lock down access to your database system:

sudo mysql_secure_installation 

4. Installing PHP

PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free

to install php run the following command :

sudo apt install php libapache2-mod-php php-mysql 

This should install PHP without any problems. We’ll test this in a moment.

In most cases, you will want to modify the way that Apache serves files when a directory is requested. Currently, if a user requests a directory from the server, Apache will first look for a file called index.html. We want to tell the web server to prefer PHP files over others, so make Apache look for an index.php file first.

To do this, type this command to open the dir.conf file in a text editor with root privileges:

sudo nano /etc/apache2/mods-enabled/dir.conf 

It will look like this: /etc/apache2/mods-enabled/dir.conf

<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

Move the PHP index file (highlighted above) to the first position after the DirectoryIndex specification, like this: /etc/apache2/mods-enabled/dir.conf

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

When you are finished, save and close the file by pressing CTRL+X. Confirm the save by typing Y and then hit ENTER to verify the file save location.

After this, restart the Apache web server in order for your changes to be recognized. Do this by typing this:

sudo systemctl restart apache2 

You can also check on the status of the apache2 service using systemctl:

sudo systemctl status apache2 

5. Testing PHP Processing on your Web Server

In order to test that your system is configured properly for PHP, create a very basic PHP script called info.php. In order for Apache to find this file and serve it correctly, it must be saved to a very specific directory, which is called the “web root”.

In Ubuntu 18.04, this directory is located at /var/www/html/. Create the file at that location by running:

sudo nano /var/www/html/info.php

This will open a blank file. Add the following text, which is valid PHP code, inside the file: info.php

<?php
phpinfo();
?>

When you are finished, save and close the file.

Now you can test whether your web server is able to correctly display content generated by this PHP script. To try this out, visit this page in your web browser. You’ll need your server’s public IP address again.

The address you will want to visit in your browser is:

http://your_server_ip/info.php


aghouchaf

 Previous Article DevOps practices that you must implement in 2019
Next Article   How To Install Apache2 on Ubuntu 18.04

Leave a Reply

Cancel reply

Recent Posts

  • Install ELK On Ubuntu 18.04
  • Create a Self-Signed SSL Certificate using Apache2 in Ubuntu 18.04
  • How to install Google Chrome browser on Ubuntu 18.04
  • (no title)
  • Setup Nginx HTTP Server Self-Signed SSL/TLS Certificates on Ubuntu16.04 or 18.04

Recent Comments

    Archives

    • March 2019
    • January 2019
    • December 2018
    • March 2014

    Categories

    • Apache
    • Browser
    • centos
    • couchbase
    • Databases
    • debian
    • DevOps
    • ELK
    • How To
    • linux
    • network
    • nginx
    • Security
    • ssh
    • ssl
    • tls
    • Web

    Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
    Advertisement
    • Popular Posts
    • Recent Posts
    • Install ELK On Ubuntu 18.04 March 24, 2019
    • Blog Post with Right Sidebar March 16, 2014
    • What DevOps Means? December 26, 2018
    • DevOps practices that you must implement in 2019 December 26, 2018
    • Install ELK On Ubuntu 18.04 March 24, 2019
    • Create a Self-Signed SSL Certificate using Apache2 in Ubuntu 18.04 January 13, 2019
    • How to install Google Chrome browser on Ubuntu 18.04 January 4, 2019
    • December 31, 2018

    Categories

    • Apache (6)
    • Browser (1)
    • centos (1)
    • couchbase (1)
    • Databases (1)
    • debian (2)
    • DevOps (3)
    • ELK (1)
    • How To (8)
    • linux (5)
    • network (1)
    • nginx (2)
    • Security (9)
    • ssh (1)
    • ssl (3)
    • tls (2)
    • Web (6)
    January 2021
    M T W T F S S
    « Mar    
     123
    45678910
    11121314151617
    18192021222324
    25262728293031

    Tags

    apache web

    Social Media

    • Connect on Facebook
    • Connect on Twitter
    • Connect on Google+
    • Connect on Pinterest

    Tags

    apache web

    Archives

    • March 2019 (1)
    • January 2019 (2)
    • December 2018 (15)
    • March 2014 (2)

    Random Posts

    • Blog Post with Right Sidebar March 16, 2014
    • How to Redirect HTTP to HTTPS on Apache2
      How to Redirect HTTP to HTTPS on Apache2 December 30, 2018

    © Copyright 2014. http://tutorials-space.com.