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

Install Linux

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

Posted on |
Install Linux

Are you looking for a solution on how to install a lamp on Ubuntu 18.04? Before starting with the article, Dataservermarket wishes to explain the LAMP stack comprehensively. The detailed guide presented by Dataservermarket will help you understand the Ubuntu lamp install process. Let’s first understand the meaning of the LAMP stack.

LAMP stack: Introduction:

A LAMP stack is an individual component, creating a complete environment for application development. LAMP stack components are independently developed, but the combined usage and compatibility qualify to become a LAMP stack. In this writing, you will know how to install lamp on Ubuntu 18.04 by Dataservermarket.

What is the LAMP stack?

It is a group of open-source stack solutions used primarily in web development. The LAMP stack consists of four components, establishing a fully functional web development environment. The first letters of the components make together a LAMP stack.

The LAMP stack components are as follows:

  • Linux:

It is an operating system that runs the rest of the LAMP stack components.

  • Apache:

It is a web server software that serves static web pages.

  • MySQL:

Itis a relational database system used to create and manage web databases.

  • PHP:

It is a programming language creating applications on the web.

Each piece depicts an integral layer of the LAMP stack. These LAMP stack together to make data-driven and dynamic websites. Before diving into the article regarding how to install lamp on Ubuntu 18.04, Dataservermarket will let you know the LAMP stack architecture in detail.

LAMP Stack architecture explained by Dataservermarket:

Linux:

Linux is the open-source operating system and the backbone of the LAMP stack. Dataservermarket explains OS as the software that manages hardware such as CPU, storage, and memory. The flexible and customized nature of Linux makes it the most popular OS solution for running the rest of the LAMP stack components smoothly. SQL, ASP.NET, and ASP work more efficiently on Windows, whereas PHP and MySQL provide the best results on the Linux LAMP stack suggested by Dataservermarket.

Apache:

Apache server is one of the considerable widespread web server software that runs on the Linux OS in the LAMP stack. The function of a web server in the LAMP stack is to request and transmit information using HTTP through the Internet. Apache is configured as a threaded and process-based server with multi-processing modules. The web server’s modular architecture supports other features such as modular protocol handling.

Dataservermarket explains that Apache is known for its filters. It processes the data handled by the server. Apache helps static and dynamic content that encrypts, scans viruses, and compresses using filters in the LAMP stack.

The equally competitive alternative to Apache is NGINX, whose popularity has increased since 2008. Apache and NGINX are capable servers; however, users prefer anyone depending on the usage scenario, hosting, and content types available.

As per Dataservermarket, NGINX is considered the best for static content. However, there are some minor changes when it comes to dynamic range. Moreover, shared hosting users use Apache, whereas virtual private servers use NGINX.

MySQL:

Dataservermarket explains MySQL as a database management system supporting SQL and relational tables. It is a good choice for creating and maintaining dynamic enterprise-level databases in the LAMP stack. Dataservermarket will provide a detailed guide showcasing how to install lamp on Ubuntu 18.04. MySQL is cross-platform compatible, qualifying to be a part of a web development solution such as a LAMP stack that targets multiple OS.

One of the primary disadvantages of MySQL suggested Dataservermarket compares that it scales only vertically to non-relational solutions such as Mongo DB. It is also ineffective in addressing extensive databases in projects that expect a lot of traffic and requires careful planning.

Maria DB is another relational database that is used alternatively in the LAMP stack. Dataservermarket suggests Maria DB be entirely consistent with MySQL. It permits users to share their database without any difficulties or losses.

PHP:

PHP is a programming language that combines every element of the LAMP stack and allows web applications and websites to run smoothly. The server processes PHP commands when a visitor opens the web page and sends the results to the visitor’s browser.

Dataservermarket explains PHP as the fourth layer of the original LAMP stack as it interacts satisfactorily with MySQL. It is generally utilized for web expansion because of its dynamic language embedded into HTML, making it faster and easy.

The “P” in the LAMP stack also refers to the other two programming languages- Perl and Python. Dataservermarket recommends all three languages as equally applicable because of establishing dynamic connections.

So, these were the LAMP stack architecture explained by Dataservermarket. The article will provide a comprehensive guide on how to install lamp on Ubuntu 18.04. Before understanding how to install lamp on Ubuntu 18.04, let’s first understand the uses of the LAMP stack.

Uses of LAMP stack:

The LAMP stack is used for delivering and building web applications. The flexibility and efficiency of the LAMP stack allow small developers to compete with commercial software development solutions. The four elements of the LAMP stack were picked as the best solutions for developers who wished to serve, host, and manage web-based content. It provides a route for accessing content, other web-based tools, and software.

So, these were used for the LAMP stack provided by the Dataservermarket. Let’s understand how to install lamp on Ubuntu 18.04. Before that, we will peek into the pros and cons of the LAMP stack.

Pros and Cons of LAMP stack:

Pros:

  • LAMP stack is an open-source web-based solution. The software code is shared publicly, enhancing the overall performance.
  • The users can customize and replace every component with an open-source solution to suit the application’s requirements.
  • It is straightforward to find aid due to the LAMP stack community’s size.
  • It is easy to set up due to its maturity.

Cons:

  • LAMP stack does not support any other OS other than Linux.
  • The relational property of MySQL makes the LAMP stack less efficient than other non-relational solutions.
  • Apache runs into performance problems due to heavy workloads.
  • Coding in PHP and Python on the server-side and using JavaScript on the client-side disrupt the development workflow.

So, the Dataservermarket lists the pros and cons of the LAMP stack. If you want to know how to install lamp on Ubuntu 18.04, read the entire article. Dataservermarket provided a step-by-step guide on how to install lamp on Ubuntu 18.04. Before starting with the process on how to install lamp on Ubuntu 18.04, let’s first know the pre-requisites.

Pre-requisites of the LAMP stack:

To complete the tutorial on how to install lamp on Ubuntu 18.04, Dataservermarket suggests you have an Ubuntu 18.04 server, a non-root sudoenabled user account, and a basic firewall configured.

A comprehensive guide on how to install lamp on Ubuntu 18.04:

Dataservermarket provided the following detailed process on how to install lamp on Ubuntu 18.04:

Step 1: Install Apache and update the firewall:

The web server Apache is one of the considerable widespread servers used with PHP to host dynamic websites. It has a broader use and rich history of the web.

Primarily, make sure that your apt-cache is updated:

$ sudo apt update

You will be encouraged to deliver a user password to understand how to install lamp on Ubuntu 18.04 if you are using sudo for the first time.

You can install Apache with the following command once the cache is updated:

$ sudo apt install apache2

To understand the process of how to install lamp on Ubuntu 18.04 and enter the command, apt will let you know which packages you need to install and how much space they will take. To move with the installation, press “Y” and hit “Enter.”

Adjust firewall to allow web traffic:

The next step for how to install lamp on Ubuntu 18.04 is to adjust the firewall. Dataservermarket assumes that you have followed the initial server setup and enabled the UFW firewall. Make sure the firewall allows HTTP or HTTPS web traffic. You may also check the UFW firewall settings by issuing the following command:

$ sudo ufw app list

The output will be:

Available applications:

Apache

Apache Full

Apache Secure

OpenSSH

If you will see the full Apache profile details, it enables traffic ports to 80 and 443:

$ sudo ufw app info “Apache Full”

Output

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

Run the subsequent order to permit incoming HTTP or HTTPS traffic:

$ sudo ufw allow “Apache Full”

To understand the steps on how to install lamp on Ubuntu 18.04, you may do a spot check by visiting server’s IP addresses in your web browser.

http://your_server_ip

You will notice the default Ubuntu 18.04 web page for testing and information purposes.

How to find the public server IP address:

The server’s public IP address is usually connected to your server through SSH. There are few ways to understand how to install lamp on Ubuntu 18.04. You may use the iproute2 tools to get the IP address by issuing the following command:

$ ip addr show eth0 | grep inet | awk ‘{ print $2; }’ | sed ‘s/\/.*$//’

Every address mentioned above is correct, but your computer may use only one. So, sense unrestricted to try each of them.

An alternative method for Ubuntu lamp install is to use the curl utility to contact the third party and tell how it sees the server. Dataservermarket suggests by asking a specific server regarding your IP address:

$ sudo apt install curl

$ curl http://icanhazip.com

Type your web browser address bar to view the default Apache page to understand how to install lamp on Ubuntu 18.04.

Step 2: Install MySQL:

Now you have cleared the primary step of how to install lamp on Ubuntu 18.04; the next step is to install MySQL. It is a database management system providing access to databases where your website stores information.

Proceed with the apt command to acquire and install MySQL software to process how to install lamp on Ubuntu 18.0https://dataservermarket.com/?s=ubuntu4.

$ sudo apt install mysql-server

Note:

In this case, you do not have to run sudo apt update before the command. You just ran it in the orders above to install Apache. The container index on your computer should already be up-to-date.

The command will show the list of packages to be installed for understanding the process of how to install lamp on Ubuntu 18.04. It indicates the quantity of disk space the application will take. Press “Y” to continue further.

After the second process of Ubuntu lamp install is completed, run a simple security script with pre-installed MySQL. It will remove dangers and viruses from the database system. Start the script of interaction by issuing the following command for Ubuntu lamp install:

$ sudo mysql_secure_installation

The pop-up asks for configuring VALIDATE PASSWORD PLUGIN.

Note:

Enabling the feature is like a judgment call. MySQL will reject the passwords not matching the specific criteria with showcasing errors if you provide weak passwords in combination with software that configures MySQL automatically, user credentials. It would be best to use solid passwords for the Ubuntu lamp install suggested by Dataservermarket.

Press “Y” for Yes or continue for anything else without enabling:

VALIDATE PASSWORD PLUGIN can be used to test passwords

and improve security. It checks the strength of passwords

and allows the users to set only those passwords which are

secure enough. Would you like to set up VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No:

If you answer “Y,” you are asked for password selection and validation for Ubuntu lamp install. Keep in a notice to enter 2 for the most substantial level. You may receive errors in setting a password for Ubuntu lamp install if it does not contain numbers, special characters, upper and lowercase letters.

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: 1

Your server will ask to select and confirm a password for MySQL root users. Do not get confused with the system root. The database user resembles an administrative user over the database system with full privileges. The default authentication procedure for the MySQL root user distributes the password used. The password defined should be strong even when set as an additional safety measure. We will come to this point in a moment.

If you enabled password validation for the Ubuntu lamp install, you would be shown the strength of the root password you entered. The server will ask if you want to change the password. Press “N” or No if you are happy with the current password.

We are using an existing password for root.

Estimated strength of the password: 100

Change the password for root? ((Press y|Y for Yes, any other key for No): n

Press “Y” or “Yes” and hit the “Enter” key for each command or prompt for the rest of the questions. It will test the database and remove some anonymous users for Ubuntu lamp install. It will also load new rules and disable remote root logins to respect the changes made immediately in MySQL.

The next step for Ubuntu lamp install is trying to console whether you can log in to MySQL by issuing the following command:

$ sudo mysql

It will connect to the MySQL server with the administrative database user root, inferred by using the sudo command:

The sample output will be as follows:

Output

Welcome to the MySQL monitor. Commands end with; or \g.

Your MySQL connection id is 5

Server version: 5.7.34-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and its

affiliates. Other names may be trademarks of their respective

owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

To exit the MySQL, issue the following command:

mysql > exit

You may notice that it didn’t prompt the password to connect as the root user even though you defined one while running the mysql_secure_installation script. The default authentication process for MySQL users is unix_socket instead of the password. It makes the database more secured even it looks like the security concern for Ubuntu lamp install at first instance. Setting up a password for the root MySQL account works as a safety option.

It is best to have dedicated user accounts, especially if you have or plan to use multiple databases hosted on the server. The second step of the Ubuntu lamp install is completed. The next step is installing PHP, which is the final process of how to install lamp on Ubuntu 18.04 suggested by Dataservermarket.

Step 3: Installing PHP:

PHP is a programming terminology that assists in the setting process to display the dynamic content. It runs scripts and connects to the MySQL databases to your web server, communicating results to the visitors.

You need to leverage the apt system to install PHP. In addition to the PHP package, you need to install libapache2-mod-php to integrate PHP into Apache. You need to install the php-mysql package to allow PHP to connect to MySQL databases. Issue the following command to install all the three packages along with their dependencies:

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

The next step for the Ubuntu lamp install suggested by Dataservermarket is setting up an Apache virtual host to store your server’s configuration details.

Step 4: Set up the virtual host:

Using the Apache web server, you may use a virtual host to install configuration details. It is possible to host more than one domain from a single server. Try setting up a domain called your_domain; replace this with your website’s domain name.

Apache on Ubuntu 18.04 has one default server block enabled that is configured to serve the documents from the /var/www/html directory. It is easier for a single site; it becomes tricky to host multiple sites. Let’s create a directory structure within /var/www for your_domain site instead of modifying /var/www/html. It will leave /var/www/html in place as the default directory served if a client request does not match with any other sites.

Create the directory for your_domain by issuing the following command:

$ sudo mkdir /var/www/your_domain

Assign ownership of the directory with $user variable, referencing the current logged user:

$ sudo chown -R $USER:$USER /var/www/your_domain

If you haven’t modified the unmasked value, make sure that the permissions of the webroot directory are correct by issuing the following command:

$ sudo chmod -R 755 /var/www/your_domain

The next step is creating a sample index.html page using the nano or any other editor:

$ nano /var/www/your_domain/index.html

Add the following sample HTML:

<html>

<head>

<title>Welcome to Your_domain!</title>

</head>

<body>

<h1>Success! The your_domain server block is working!</h1>

</body>

</html>

Save and close the file when you are done.

Creating a virtual host file with correct directories for Apache to serve the content. Let’s make a new directory at /etc/apache2/sites-available/your_domain.conf instead of modifying the default configuration file located at /etc/apache2/sites-available/000-default.conf:

$ sudo nano /etc/apache2/sites-available/your_domain.conf

Paste the following in the configuration block:

<VirtualHost *:80>

ServerAdmin webmaster@localhost

ServerName your_domain

ServerAlias www.your_domain

DocumentRoot /var/www/your_domain

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Notice that we have updated the ServerAdmin to an email and DocumentRoot to the new directory. We have added two directives-

  • ServerName establishes the base domain to match the virtual host definition.
  • ServerAlias defines other names that match if they are like the base name.

Save and close the file when you are done.

The next step is enabling the file with the a2ensite tool:

$ sudo a2ensite your_domain.conf

Disable the default site that is defined in 000-default.conf:

$ sudo a2dissite 000-default.conf

The next step is testing for configuration errors by issuing the following command:

$ sudo apache2ctl configtest

You will see the following output:

Output

Syntax OK

Restart the Apache to implement the following changes by issuing the command as follows:

$ sudo systemctl restart apache2

Apache should serve your domain name, and you may test by navigating to http://your_domain, and you will get the following sentence:

Success! The your_domain virtual host is working!

Your virtual host is fully set up. Before deploying any applications or making any changes, it is recommended by the Dataservermarket to test out the PHP configuration proactively. You must carefully address the issues or intricacies.

The next step on how to install lamp on Ubuntu 18.04 is testing the PHP process on the webserver.

Step 5: Testing PHP process on the webserver:

The last and final process of the Ubuntu lamp install provided by Dataservermarket is testing that your system is configured correctly by PHP and creating a PHP script called info.php.

For Apache to serve correctly and find this file, you must save it in your webroot directory. Create a file at the webroot just like the previous step by issuing the following command:

$ sudo nano /var/www/your_domain/info.php

The command mentioned above will open a blank file. Add the following text inside the file, which is a valid PHP code:

<?php

phpinfo();

Save and close the file when you are done.

The next step is to test whether your web server displays the content correctly; the PHP script generates that. Visit the page of your web browser to try this out. You will need your server’s public IP address or domain name again to try it.

The IP address you want to visit is as follows:

http://your_domain/info.php

The page will pop up that provides basic information about the server’s public from the PHP perspective. It helps ensure that the settings are applied correctly. It is also used for debugging.

If you notice the page in your browser, you can say that the PHP is working as expected.

Dataservermarket suggests removing the above file after the tests as it gives certain unauthorized information to the users. To remove the file, issue the following command:

$ sudo rm /var/www/your_domain/info.php

It is also possible to recreate this page to gain information on the later stages.

So these were the steps for Ubuntu lamp install suggested by the Dataservermarket. The above steps provide an individual a comprehensive guide in knowing how to install lamp on Ubuntu 18.04.

Wrapping up:

After successfully installing the LAMP stack on your web server, you have many choices left as to what to do next. You have finally installed a platform that allows you to install many websites and different types of web software on your web server.

The next step suggested by Dataservermarket is to ensure that the connections to the web servers are secured and looking to serve them via HTTPS. There are many other options available.

We hope you are well versed with the comprehensive guide of installing the LAMP stack on Ubuntu 18.04 by Dataservermarket.

Leave a Reply

Your email address will not be published. Required fields are marked *