Complete tutorial on installing Apache, MySQL, PHP, LAMP on Ubuntu 18.04

Complete tutorial on installing Apache, MySQL, PHP, LAMP on Ubuntu 18.04

1. Install Apache

$ sudo apt update && sudo apt install apache2

There will be a pause in the middle asking whether to continue, enter y and press Enter .

2. Test Apache

Check whether Apache is installed correctly by viewing the status of the Apache service.

$ sudo service apache2 status 

After checking the status, you need to press q to exit the Apache server status.
After checking, we know that the Apache service is up, so the next step is to check some Apache web pages.
Enter the IP address into the address bar of the browser and press Enter to see it.
If you don't know your IP address, you can check it using the following command:

$ sudo ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' 

When you see the above page in the browser, it means that it has been completed. The page you see is the file
/var/www/html/index.html
If you want to modify the page, just modify /var/www/html/index.html.

3. Install MySQL

$ sudo apt update && sudo apt install mysql-server 

Type y and press Enter to continue.
After the installation is complete, we check whether the MySQL service is up.

$ sudo service mysql status

If it is up, you will see the activation status as follows:

You may need to press q to check the service status, or you may not. (I don't need it here)

4. Configure MySQL security

For secure configuration of MySQL server, you should run mysql_secure_installation

$ sudo mysql_secure_installation

If you created a password for the root user in Step 1, you may be prompted to enter it here. Otherwise, you will be asked to create one.
You will be asked if you want to set up the Verify Password plugin.
Unless you have some reason to enforce a strict password policy, this is not necessary.

Go to the picture above, just press Enter here if you don't want to set up a verification password plugin.
After pressing Enter, the following will occur:

If you did not create a password for the root user in Step 1, you must create one here now.
Note that when you enter your password in Linux, it does not display what you are typing (no asterisks or dots).

Type y and press Enter to remove the anonymous user.

Type y and press Enter to not allow remote login for the root user. This will prevent robots and hackers from trying to guess the root user password.

Type y and press Enter to remove the test database.

Type y and press Enter to reload the privilege tables.
Then, done.

As a test, you can log in to the MySQL server and run the version command.

$ sudo mysqladmin -p -u root version 

The first password here is the root user password, and the second password is the MySQL root password just set.
Enter the MySQL root password you set earlier and you should see the following:

MySQL has now been successfully installed and configured!

5. Install PHP

Let's start by updating the repository and installing the PHP package using apt. We will also install two more packages libapache2-mod-php and PHP-MySQL which allow PHP to communicate with the MySQL database.

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

When prompted to install the PHP package, press y and hit enter .

6. Testing PHP

Once the package has been installed, we can test PHP from the command line.

$ php -version

If PHP is installed correctly, you should see something like this:

Great, now let's test PHP for Apache.
Create a new file called info.php in your document root
The default document root directory in Ubuntu 18.04 is /var/www/html/

Once you have determined the location of your document root, use vi or vim or gedit or another text editor to create a new file called info.php. (If you are not used to vi, it is recommended to use the visual text editor gedit)
In this example, we will create a new file in /var/www/html/

$ sudo vi /var/www/html/info.php

The content written into info.php is as follows:

<?php
phpinfo(); 
?>

As shown below

Then save and exit.

Now we can load this file in the browser by typing:
http://your_ip/info.php
My address is 192.168.1.10, so I typed http://192.168.1.10/info.php in my browser.
If you don't know your IP address, you can find it out by running the following command:

$ sudo ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' 

Below we can see that the PHP information page is working fine.

Once you have verified that PHP is working properly, it is important to delete info.php as it contains information that could be useful to hackers.

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

If you still want to install phpMyAdmin, please continue to see: Install phpMyAdmin on Ubuntu 18.04

Reference: Installing Apache, MySQL, PHP (LAMP) Stack on

Summarize

The above is a complete tutorial for installing Apache, MySQL, PHP, and LAMP on Ubuntu 18.04. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • How to install JDK and Mysql on Ubuntu 18.04 Linux system
  • Ubuntu 18.04 does not prompt for password when installing MySQL and how to solve it
  • Detailed explanation of the process of installing MySQL on Ubuntu 18.04.4

<<:  The process of building a development environment based on visual studio code + react

>>:  Detailed discussion of MySQL stored procedures and stored functions

Recommend

MySQL query sorting and paging related

Overview It is usually not what we want to presen...

Mysql error: Too many connections solution

MySQL database too many connections This error ob...

Detailed example of changing Linux account password

Change personal account password If ordinary user...

js realizes the dynamic loading of data by waterfall flow bottoming out

This article shares with you the specific code of...

Docker time zone issue and data migration issue

Latest solution: -v /usr/share/zoneinfo/Asia/Shan...

TypeScript Mapping Type Details

Table of contents 1. Mapped Types 2. Mapping Modi...

How to install PostgreSQL11 on CentOS7

Install PostgreSQL 11 on CentOS 7 PostgreSQL: The...

Google Translate Tool: Quickly implement multilingual websites

Google China has released a translation tool that ...

Several methods of implementing carousel images in JS

Carousel The main idea is: In the large container...

How to set background color and transparency in Vue

Background color and transparency settings As sho...

Linux uses iptables to limit multiple IPs from accessing your server

Preface In the Linux kernel, netfilter is a subsy...