How to install Apache, PHP 7.3 and MySQL on CentOS 7.6 (LAMP)

This tutorial exhibits how to put in an Apache internet server on CentOS 7 server with PHP (mod_php) and MySQL database. The acronym LAMP is brief for Linux, Apache, MySQL, PHP.

This up to date tutorial exhibits the set up of the most recent PHP variations (7.0, 7.1, 7.2 and seven.3) on CentOS 7.6.

1 Preliminary Notice

On this tutorial, I exploit the hostname with the IP p These settings may differ for you, so it’s a must to change them the place acceptable.

I’ll add the EPEL repo right here to put in newest phpMyAdmin as follows:

rpm --import /and many others/pki/rpm-gpg/RPM-GPG-KEY*
yum -y set up epel-release

To edit information on the shell, I will set up the nano editor. Should you want vi for file modifying, then skip this step.

yum -y set up nano

2 Putting in MySQL / MariaDB

MariaDB is a MySQL fork of the unique MySQL developer Monty Widenius. MariaDB is appropriate with MySQL and I’ve chosen to make use of MariaDB right here as a substitute of MySQL. Run this command to put in MariaDB with yum:

yum -y set up mariadb-server mariadb

Then we create the system startup hyperlinks for MySQL (in order that MySQL begins robotically at any time when the system boots) and begin the MySQL server:

systemctl begin mariadb.service
systemctl allow mariadb.service

Set passwords for the MySQL root account:

[[email protected] ~]# mysql_secure_installation


In an effort to log into MariaDB to safe it, we'll want the present
password for the basis person.  Should you've simply put in MariaDB, and
you have not set the basis password but, the password will likely be clean,
so it is best to simply press enter right here.

Enter present password for root (enter for none): <--ENTER
OK, efficiently used password, shifting on...

Setting the basis password ensures that no person can log into the MariaDB
root person with out the right authorisation.

Set root password? [Y/n]
New password: <--yourmariadbpassword
Re-enter new password: <--yourmariadbpassword
Password up to date efficiently!
Reloading privilege tables..
 ... Success!

By default, a MariaDB set up has an nameless person, permitting anybody
to log into MariaDB with out having to have a person account created for
them.  That is meant just for testing, and to make the set up
go a bit smoother.  It is best to take away them earlier than shifting right into a
manufacturing atmosphere.

Take away nameless customers? [Y/n] <--ENTER
 ... Success!

Usually, root ought to solely be allowed to attach from 'localhost'.  This
ensures that somebody can't guess on the root password from the community.

Disallow root login remotely? [Y/n] <--ENTER
 ... Success!

By default, MariaDB comes with a database named 'take a look at' that anybody can
entry.  That is additionally meant just for testing, and needs to be eliminated
earlier than shifting right into a manufacturing atmosphere.

Take away take a look at database and entry to it? [Y/n] <--ENTER
 - Dropping take a look at database...
 ... Success!
 - Eradicating privileges on take a look at database...
 ... Success!

Reloading the privilege tables will be certain that all adjustments made to this point
will take impact instantly.

Reload privilege tables now? [Y/n] <--ENTER
 ... Success!

Cleansing up...

All accomplished!  Should you've accomplished the entire above steps, your MariaDB
set up ought to now be safe.

Thanks for utilizing MariaDB!
[[email protected] ~]#

Three Putting in Apache

CentOS 7 ships with Apache 2.4. Apache is straight out there as a CentOS 7 bundle, subsequently we are able to set up it like this:

yum -y set up httpd

Right here a screenshot of the set up course of.

Installing Apache web server on CentOS

Now configure your system to start out Apache at boot time...

systemctl begin httpd.service
systemctl allow httpd.service

To have the ability to entry the webserver from exterior, we now have to open the HTTP (80) and HTTPS (443) ports within the firewall. The default firewall on CentOS is firewalld which could be configured with the firewalld-cmd command.

firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

Now direct your browser to the IP handle of your server, in my case, and it is best to see the Apache placeholder web page:

Apache Default page on CentOS

Four Putting in PHP

The PHP model that ships with CentOS as default is sort of previous (PHP 5.4). Due to this fact I'll present you on this chapter some choices to put in newer PHP variations like PHP 7.Zero to 7.Three from Remi repository.

Add the Remi CentOS repository.

rpm -Uvh

Set up yum-utils as we want the yum-config-manager utility.

yum -y set up yum-utils

and run yum replace

yum replace

Now it's a must to selected which PHP model you need to use on the server. Should you like to make use of PHP 5.4, then proceed to chapter 4.1. To put in PHP 7.0, comply with the instructions in chapter 4.2, for PHP 7.1 chapter 4.3, for PHP 7.Four use chapter 4.Four and for PHP 7.Three comply with chapter 4.5 as a substitute. Observe simply one of many 4.x chapters and never all of them as you may solely use one PHP model at a time with Apache mod_php.

4.1 Set up PHP 5.4

To put in PHP 5.4, run this command:

yum -y set up php

4.2 Set up PHP 7.0

We are able to set up PHP 7.Zero and the Apache PHP 7.Zero module as follows:

yum-config-manager --enable remi-php70
yum -y set up php php-opcache

4.Three Set up PHP 7.1

If you wish to use PHP 7.1 as a substitute, use:

yum-config-manager --enable remi-php71
yum -y set up php php-opcache

4.Four Set up PHP 7.2

If you wish to use PHP 7.2 as a substitute, use:

yum-config-manager --enable remi-php72
yum -y set up php php-opcache

4.5 Set up PHP 7.3

If you wish to use PHP 7.Three as a substitute, use:

yum-config-manager --enable remi-php73
yum -y set up php php-opcache

On this instance and within the downloadable digital machine, I will use PHP 7.3.

We should restart Apache to use the adjustments:

 systemctl restart httpd.service

5 Testing PHP / Getting Particulars About Your PHP Set up

The doc root of the default web site is /var/www/html. We are going to create a small PHP file (data.php) in that listing and name it in a browser to check the PHP set up. The file will show a lot of helpful particulars about our PHP set up, such because the put in PHP model.

nano /var/www/html/data.php

Now we name that file in a browser (e.g.

PHP version information

As you see, PHP 7.Three is working, and it is working by way of the Apache 2.0 Handler, as proven within the Server API line. Should you scroll additional down, you will note all modules which might be already enabled in PHP. MySQL isn't listed there which suggests we do not have MySQL assist in PHP but.

6 Getting MySQL Help In PHP

To get MySQL assist in PHP, we are able to set up the php-mysqlnd bundle. It is a good suggestion to put in another PHP modules in addition to you may want them on your functions. You may seek for out there PHP5 modules like this:

yum search php

Decide those you want and set up them like this:

yum -y set up php-mysqlnd php-pdo

Within the subsequent step I'll set up some widespread PHP modules which might be required by CMS Techniques like WordPress, Joomla, and Drupal:

yum -y set up php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap curl curl-devel

Now restart Apache internet server:

 systemctl restart httpd.service

Now reload in your browser and scroll right down to the modules part once more. It is best to now discover a lot of new modules like curl and many others there.:

PHP has now MySQL support enabled

Should you do not want the PHP data output anymore, then delete that file for safety causes.

rm /var/www/html/data.php

7 phpMyAdmin set up

phpMyAdmin is an online interface by way of which you'll be able to handle your MySQL databases.
phpMyAdmin can now be put in as follows:

yum -y set up phpMyAdmin

Now we configure phpMyAdmin. We alter the Apache configuration in order that phpMyAdmin permits connections not simply from localhost (by commenting out the <RequireAny> stanza and including the 'Require all granted' line):

nano /and many others/httpd/conf.d/phpMyAdmin.conf
Alias /phpMyAdmin /usr/share/phpMyAdmin Alias /phpmyadmin /usr/share/phpMyAdmin <Listing /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8

<IfModule mod_authz_core.c>
# Apache 2.4
# <RequireAny>
# Require ip
# Require ip ::1
# </RequireAny>
Require all granted
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Permit
Deny from All
Permit from
Permit from ::1
<Listing /usr/share/phpMyAdmin/> Choices none AllowOverride Restrict Require all granted </Listing>


Restart Apache to use the configuration adjustments:

systemctl restart  httpd.service

Afterwards, you may entry phpMyAdmin underneath

PHPMyAdmin Login

PHPMyAdmin on CentOS

Eight Obtain as a digital machine

This setup is on the market as digital machine obtain in ova/ovf format (appropriate with VMWare and Virtualbox) for howtoforge subscribers.

Login particulars for the VM

  • The Linux root password is: howtoforge.
  • Rhe MySQL root password is: howtoforge

Please change each passwords on the first login.

  • The IP handle of the VM is


The right way to Use Distant Desktop (rdesktop) in Redhat/Fedora/CentOS

Previous article

Official Galaxy Word 10 photographs leak, showcase the massive, boxy physique

Next article

You may also like


Leave a Reply

More in Apache