How To Install Apache2, MySQL, PHP stack on Ubuntu 18.04 Step By Step

Intro:-

PHP is a general-purpose scripting language.It is suited for Web development. Its scripts can be embedded into HTML. Here we explain how to install and configure PHP in an Ubuntu 18.04 System

Requirement:-

Ubuntu Server With non-root user account with sudo privileges set up on your server.

Step 1: Apache2 Installation:-

As you know The Apache web server is among the most popular web servers in the world. Apache is documented and has been in wide use on the web, which makes it a great default choice for hosting a website.
You can install apache2 using, apt. A package allows us to install most software free from a repository maintained by Ubuntu.
We can get started apache2 installation by using these commands:

$ sudo apt-get update
$ apt-get install apache2 -y

 

If you are using a sudo command, these operations get executed with root privileges. You need root password to verify your intentions.
When apache2 installation done then restart apache2 service if getting Global name warning you can open this file and set server name:-

$ vim /etc/apache2/apache2.conf

If you do not have a domain name, you can use your server’s public IP address:

/etc/apache2/apache2.conf
. . . . .
ServerName linuxworld.info

 

Save and close the file when you are finished.
Using this command for checking syntax errors:

$ sudo apache2ctl configtest

Since we added the global ServerName directive, all you should see is:

Output
Syntax OK

Restart apache server using this command:

$ sudo systemctl restart apache2

Now, apache2 successfully installed in your system. Check on browser type domain name or public ip.But make sure 80 port is open in your system firewall.

Find Public IP Address Using this Command:

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

Step 2: Install MySQL Server On Ubuntu-18.04 System Step by Step

MySQL is a database management system. It will organize and provide access to databases where our site can store information.
When you install MYSQL server for Ubuntu 18.04 System you need to use this command:-

$ sudo apt-get install mysql-server

Press Y for Yes when You get the confirmation message.
After installing MYSQL server you need to secure your installation bcoz at the time of installation it is not secure.
So do this first using this command:-

$ sudo mysql_secure_installation

When you use this command your screen will show many questions and it also asked you about the password and the root password also so you set it firstly.

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

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

Please set the password for root here.
New password:
Re-enter new password:
Estimated strength of the password: 100

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : 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
Success.

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
Success.

 

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

  • Dropping test database
    Success.
  • Removing privileges on test database…
    Success.

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

Success.
All done!

After installing and secure MYSQL successfully
You need to test your installation so login using this command:-

$ sudo mysql -u root –p

Install PHP On Ubuntu System Step By Step

When you want install PHP on your Ubuntu 18.04 system use this command

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

Press Y for confirm the installation

After installing the PHP We need to test PHP installation by creating a file on the root folder of our website. for doing this use this command below:

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

Then copy and paste the text which is given below and click CTR+X and Y to save the file.

<?php phpinfo(); ?>

Above all are the basic steps for installing the PHP, Apache, and MYSQL.

 

All Done 🙂

Also Reads : How to Install Mariadb

One thought on “How To Install Apache2, MySQL, PHP stack on Ubuntu 18.04 Step By Step

Leave a Reply

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