Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Install LAMP on Ubuntu 18.04

DZone's Guide to

Install LAMP on Ubuntu 18.04

In this post, let's check out how to install LAMP on Ubuntu 18.04 Server and also test PHP and install PHP modules.

· Integration Zone ·
Free Resource

The new Gartner Critical Capabilities report explains how APIs and microservices enable digital leaders to deliver better B2B, open banking and mobile projects.

In this post, I will show you how to install LAMP on Ubuntu 18.04 Server. LAMP stands for Linux, Apache Web Server, MySQL, and PHP.

A good portion of web applications deployed today are deployed on a LAMP stack.

This means a Linux web server has the Apache Web Server, MySQL Database Server, and PHP Hypertext Preprocessor installed to serve web-based applications.

In this post, I will walk you through the process.

Make sure you have a fresh copy of Ubuntu Server 18.04 installed and fully updated.

Install Apache2

To begin, we will need to install the Apache 2 Web Server.

apt install apache2 -y

After it is installed, you can browse to the server's IP address or DNS name and see the default web page that comes with Apache.

All of your web content by default is located in /var/www/html.

In addition, everything in the /var/www/html directory needs to be owned by the www-data user and www-data group for the Apache Web Server to be able to read the files.

Next, we will install the MySQL Database.

Install MySQL

MySQL is an open-source relational database that is very robust.

Run the following command to install MySQL.

apt install mysql-server -y

After it is completed installing, we need to secure it. Run this command to secure MySQL.

mysql_secure_installation

This script will ask you several questions.

The first question will ask you to install the Validate Password Plugin.

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

I typically answer "N" to this question because I know my password is secure. You can answer "Y" if you would like.

Next, the script will ask you to set a new password for the root MySQL user.

New password: 

Re-enter new password:

The script will now ask you to remove anonymous users. Answer "Y."

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y

Next, it will ask you if you want to disallow root login remotely. We should always answer "Y" to this.

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) : Y

It will ask you to remove the test database and access to it. Answer "Y."

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) : Y

Next, it will ask you to reload the privilege tables. Answer "Y."

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) : Y

Finally, the script completes.

MySQL is now installed.

Install PHP

The last step to install LAMP on Ubuntu 18.04 is to install the PHP preprocessor.

PHP adds server-side web page processing that enables dynamic web pages.

Run the following command to install PHP.

apt install php -y

Next, we need to tell Apache to serve PHP pages first.

Open /etc/apache2/mods-enabled/dir.conf file and change it to have index.php listed first.

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

Finally, we need to restart the Apache Web Server.

systemctl restart apache2

Testing PHP

We should make sure that PHP is working correctly.

Create a new file in /var/www/html called info.php with the following contents:

<?php
phpinfo();
?>

Save and exit the file.

Now browse to this URL:

http://{your_server}/info.php

And you should see the PHP Information page.

Remove the file after you have verified that PHP is working.

rm /var/www/html/info.php

Installing PHP Modules

Most likely, when you install a PHP based application, it will have PHP module dependencies.

A common PHP module is the php-curl module.

We can use apt to install these. Just prepend a "php-" in front of the module that you need to install.

apt install php-curl

If you are having trouble finding the module you need, simply type in "apt install php" (first letter of module), then hit the TAB key.

Ubuntu will list all the matching packages for you.

# apt install php-c
php-cache-integration-tests  php-cgi                      php-common                   php-console-table
php-cache-lite               php-cli                      php-composer-ca-bundle       php-constant-time
php-cache-tag-interop        php-cli-prompt               php-composer-semver          php-curl
php-cas                      php-codecoverage             php-composer-spdx-licenses   
php-cassandra                php-codesniffer              php-console-commandline

Conclusion

In this post, we learned how to install LAMP on Ubuntu 18.04.

I hope you have enjoyed this post and that it was helpful. If it was, then please share it and comment below.

Click here for other great Ubuntu articles on AdminTome Blog.

The new Gartner Critical Capabilities for Full Lifecycle API Management report shows how CA Technologies helps digital leaders with their B2B, open banking, and mobile initiatives. Get your copy from CA Technologies.

Topics:
integration ,tutorial ,ubuntu ,lamp ,install lamp on ubuntu ,ubuntu 18.04 ,apache 2 ,linux ,mysql ,php hypertext preprocessor

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}