Install Nginx Php Mysql Phpmyadmin Ubuntu 18.04


Install Nginx Php Mysql Phpmyadmin Ubuntu 18.04

Introduction

In this article, we will demonstrate how to install Nginx, PHP, MySQL, and phpMyAdmin on an Ubuntu 18.04 server. Nginx is a powerful web server that can serve static or dynamic content. PHP is one of the most popular scripting languages for web development and is installed on most servers. MySQL is a powerful database server that will store all of your data. phpMyAdmin is a web-based interface that you can use to manage your MySQL databases.

Before proceeding with the installation of these packages, you should update all of your currently installed packages. You can do this by running the following command:

sudo apt update && sudo apt upgrade -y

Step 1 — Installing Nginx

The first step is to install the Nginx web server. To do this, run the following command:

sudo apt install nginx

Once the installation is complete, you can check the status of the Nginx service with the following command:

sudo systemctl status nginx

You should see the following output:

● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-03-26 09:32:51 UTC; 2min 24s ago
Main PID: 12586 (nginx)
Tasks: 2 (limit: 1152)
CGroup: /system.slice/nginx.service
├─12586 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─12593 nginx: worker process

The output shows that the Nginx service is running. To make sure that Nginx starts automatically when the system boots up, run the following command:

sudo systemctl enable nginx

You can also check the version of the Nginx web server by running the following command:

nginx -v

Step 2 — Installing PHP

The next step is to install PHP. To do this, run the following command:

sudo apt install php7.2-fpm php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-mysql php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl

Once the installation is complete, you can check the version of PHP by running the following command:

php -v

You should see the following output:

PHP 7.2.24-0ubuntu0.18.04.2 (cli) (built: Jul 21 2019 21:52:11) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.24-0ubuntu0.18.04.2, Copyright (c) 1999-2018, by Zend Technologies

Step 3 — Installing MySQL

The next step is to install MySQL. To do this, run the following command:

sudo apt install mysql-server

Once the installation is complete, you can check the status of the MySQL service with the following command:

sudo systemctl status mysql

You should see the following output:

● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-03-26 09:56:52 UTC; 48min ago
Main PID: 15896 (mysqld)
Tasks: 27 (limit: 1152)
CGroup: /system.slice/mysql.service
├─15896 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
└─15939 sleep 1

If you want to make sure that MySQL starts automatically when the system boots up, you can run the following command:

sudo systemctl enable mysql

Step 4 — Configuring MySQL

Once the installation is complete, you need to secure your MySQL installation by running the mysql_secure_installation script. To do this, run the following command:

sudo mysql_secure_installation

You will be asked a few questions during this process. It is recommended that you answer “yes” to all of them.

Step 5 — Installing phpMyAdmin

The next step is to install phpMyAdmin. To do this, run the following command:

sudo apt install phpmyadmin

Once the installation is complete, you need to create a symbolic link for phpMyAdmin from the web root directory. To do this, run the following command:

sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

Once the symbolic link is created, you need to create an Apache configuration file for phpMyAdmin. To do this, create the configuration file with the following command:

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Add the following lines:

Alias /phpmyadmin /usr/share/phpmyadmin

DirectoryIndex index.php
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1

Restart the Apache service to apply the changes:

sudo systemctl restart apache2

Conclusion

In this article, we have demonstrated how to install Nginx, PHP, MySQL, and phpMyAdmin on an Ubuntu 18.04 server. We have also shown how to configure each of these packages to work properly. We hope you have found this article to be helpful.

FAQs

Q. How do I start and stop Nginx?

A. To start Nginx, you can run the following command:

sudo systemctl start nginx

To stop Nginx, you can run the following command:

sudo systemctl stop nginx

Q. How do I restart MySQL?

A. To restart MySQL, you can run the following command:

sudo systemctl restart mysql

Q. How do I access phpMyAdmin?

A. To access phpMyAdmin, you can open your web browser and go to http://your-server-ip/phpmyadmin. You will be prompted to enter your MySQL username and password.

Leave a Reply

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