How to Setup Apache 2, MySQL 5.7, PHP 7.2 with all Modules/Extensions in Ubuntu 18.04?

In this article, we will explain how to set up localhost on Ubuntu 18.04.

We need a Ubuntu 18.04 LTS version. You need to download it from here. download

You go through the details of how you can install Ubuntu OS on the desktop step by step. Installation

Step By Step Guide To Setup Localhost:

We need to install Apache2.

Apache 2:

Apache is the most popular web server software in use today. Its popularity is earned through its stability, speed, and security.

How to install Apache 2:

Step 01: Update the repository cache.

# sudo apt-get update

Step 02: Install the Apache 2 package

# sudo apt-get install apache2

Step 03: To make .htaccess files work as expected, you need to modify this file.

# sudo nano /etc/apache2/apache2.conf

Step 04: Next, you need to search for AllowOverride None

Change the AllowOverride None to AllowOverride All

To make .htaccess files work as expected, you need to modify this file.

 

Ctrl+X, then enter ‘y’.

Step 05: You must restart Apache, Once you make any changes to its configuration.

# sudo service apache2 restart

Step 06: Make sure the Apache module mod_rewrite & mod_headers  is enabled.

# sudo a2enmod headers

# sudo a2enmod rewrite

Step 07: You must restart Apache once you make any changes to its configuration.

# sudo service apache2 restart

Step 08: You can also check the status of the apache2 webserver.

# sudo service apache2 status

Step 09: You will see the default Ubuntu 18.04 Apache web page

http://your-server-ip/localhost

You will see the default Ubuntu 18.04 Apache web page

 

PHP:

PHP stands for Hypertext Preprocessor, and it’s a script-based server-side programming language. It handles tasks like dynamic content, database requests, and processing and displaying data.

See also  Why sound and WiFi not working properly after windows update?

How To Install PHP 7.2:- 

Step -1 Add the repository to your system.

# sudo add-apt-repository ppa:ondrej/php

Step -2 Update the repository cache.

# sudo apt-get update

Step -3 Install PHP 7.2 with the below command.

# sudo apt-get install php7.2

Step -4 Install all modules/extensions for PHP 7.2.

# sudo apt-get install php7.2-enchant php7.2-mbstring php7.2-snmp php7.2-bcmath php7.2-fpm php7.2-mysql php7.2-soap php7.2-bz2 php7.2-gd php7.2-odbc php7.2-sqlite3 php7.2-cgi php7.2-gmp php7.2-opcache php7.2-sybase php7.2-cli php7.2-imap php7.2-pgsql php7.2-tidy php7.2-common php7.2-interbase php7.2-phpdbg php7.2-xml php7.2-curl php7.2-intl php7.2-pspell php7.2-xmlrpc php7.2-dba php7.2-json php7.2-readline php7.2-xsl php7.2-dev php7.2-ldap php7.2-recode php7.2-zip

You can also have multiple PHP versions on your system. Each PHP version will have separate configuration files under the /etc/php/7.X directory.

How to check the PHP version after installation?

Once you have installed the PHP package, check the version by this command line.

#php -v

You can use a phpinfo() page to view the current PHP information for your server.

This file outputs a large amount of information, such as:

  • Information about PHP extensions
  • PHP version
  • Server information and environment 
  • PHP environment
  • OS version information
  • HTTP headers
  • PHP license etc

How to create a PHP info file?

Step 01: Create a new file named phpinfo.php in your associated website root directory.

# sudo nano /var/www/html/phpinfo.php

Step 2: Add the following lines to your phpinfo.php file.

  <?php
  phpinfo();
  ?>

Step 03: Save your changes.

After saving enter ‘CTRL+X’ then ‘Y’.

Step 04: View your phpinfo file

 http://localhost/phpinfo.php

View your phpinfo file

 

MYSQL:

MySQL is the world’s most popular open-source relational database management system. It is widely used with web servers like apache2, Nginx, etc.

See also  How Safe is it to Use a Pin on Windows Boot?

How to install MYSQL 5.7 Step by Step.

Step -1: Update the Mysql APT repository in your system.

# sudo apt-get update

Step -2: To install MySQL from the APT repository, run the following command.

# sudo apt-get install mysql-server

Open the MYSQL from your terminal

# sudo mysql

Step -3: To configure the root account to authenticate with a password, run the following ALTER USER command.

# mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;

Step -4: Then, run FLUSH PRIVILEGES which tells the server to reload the grant tables and put your new changes into effect. 

# mysql> FLUSH PRIVILEGES;

Step -5: To create a database

# mysql> create database “db-name”;

Step -6: To show all databases

# mysql> show databases;

Step -7: Exit from sql server

# mysql> exit;

Step -8: To check the version of the mysql server

# mysql -V

How to Install Zip Step-by-Step?

Step -1: Run the command in the terminal to check the update.

# sudo apt-get update

Step -2: Then you have to install zip by using the following command line. 

# sudo apt-get install zip

Step -3: After installing the zip you can create a zip file by using the following command.

# sudo zip -r /destination file path/filename.zip /source_path/source_file

Step -4: You have to install unzip by using the following command line. 

# sudo apt-get install unzip

Step -5: After installing the unzip you can unzip a zip file by using the following command.

# sudo unzip /file_path/filename.zip -d /destination_file

Congratulations! We have successfully set up Apache2, Mysql 5.7, and Php 7.2 with all extensions/modules in Ubuntu 18.04 Server/Desktop.

Leave a Comment