Dark Light

The best way to install Apache, PHP 7. three or more and MySQL on CentOS seven. 6

I will add the EPEL repo right here to install latest phpMyAdmin as follows:

rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum -y set up epel-release

Installing MySQL / MariaDB
MariaDB is a MySQL fork of the original MySQL developer Monty Widenius. MariaDB is compatible with MySQL and I’ve chosen to use MariaDB here rather than MySQL. Run this command to set up MariaDB with yum:

yum -y install mariadb-server mariadb
Then we all create the system startup links meant for MySQL (so that MySQL starts automatically whenever the system boots) and start the MySQL server:

systemctl start mariadb. service
systemctl enable mariadb. service
Set passwords for that MySQL root account:


[[email protected] ~]

# mysql_secure_installation


In order to login MariaDB to secure it, we’ll need the current
password for the underlying user. If you’ve just installed MariaDB, and
you haven’t arranged the root password yet, the password will be blank,
so you must press enter here.

Enter current password for root (enter for none): < –ENTER
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB
root consumer without the proper authorisation.

Set root password? [Y/n]
New password: < –yourmariadbpassword
Re-enter new password: < –yourmariadbpassword
Password updated successfully!
Reloading privilege tables..
… Success!

By default, a MariaDB installation posseses an anonymous user, allowing anyone
to log into MariaDB without having to possess a user account created for
all of them. This is intended only for testing, and also to make the installation
go a bit smoother. You should remove them before getting into a
production environment.

Remove unknown users? [Y/n] < –ENTER
… Success!

Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root security password from the network.

Disallow root login remotely? [Y/n] < –ENTER
… Success!

By default, MariaDB has a database named ‘test’ that anybody can
access. This is furthermore intended only for testing, and should become removed
before moving into the production environment.

Remove test database and access to it? [Y/n] < –ENTER

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

Reloading the privilege tables will ensure that most changes made so far
is going to take effect immediately.

Reload privilege tables right now? [Y/n] < –ENTER
… Success!

Cleaning up…

All completed! If you’ve completed all of the above measures, your MariaDB
installation need to now be secure.

Thanks for using MariaDB!

[[email protected] ~]

3 Installing Apache
CentOS 7 boats with Apache 2 . 4. Apache is directly available as a CentOS 7 package, therefore we can do the installation like this:

yum -y install httpd

Now configure your system to start Apache at boot time…

systemctl start httpd. service
systemctl enable httpd. service
To be able to access the webserver through outside, we have to open the HTTP (80) and HTTPS (443) ports in the firewall. The default firewall on CentOS is firewalld which may 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 own browser to the IP address of the server, in my case, and you ought to see the Apache placeholder page:

Installing PHP
The PHP version that will ships with CentOS as default is quite old (PHP 5. 4). Therefore I will show you in this chapter some options to install newer PHP versions like PHP 7. 0 to 7. 3 from Remi repository.

Add the Remi CentOS database.

rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Install yum-utils as we need the yum-config-manager application.

yum -y install yum-utils
plus run yum update

yum update
Now you have to chose which PHP version you want to use on the machine. If you like to use PHP 5. four, then proceed to chapter 4. 1 ) To install PHP 7. 0, the actual commands in chapter 4. two, for PHP 7. 1 chapter 4. 3, for PHP 7. 4 use chapter 4. four and for PHP 7. 3 adhere to chapter 4. 5 instead. Stick to just one of the 4. x chapters and not all of them as you can only make use of one PHP version at a time along with Apache mod_php.

4. 1 Install PHP 5. 4
To install PHP 5. 4, run this control:

yum -y install php
4. 2 Install PHP 7. 0
We can install PHP 7. 0 and the Apache PHP 7. 0 module as follows:

yum-config-manager –enable remi-php70
yum -y install php php-opcache
4. 3 Set up PHP 7. 1
In order to use PHP 7. 1 instead, use:

yum-config-manager –enable remi-php71
yum -y install php php-opcache
4. 4 Install PHP 7. 2
If you want to use PHP 7. 2 instead, use:

yum-config-manager –enable remi-php72
yum -y set up php php-opcache
4. 5 Install PHP 7. 3
If you want to use PHP 7. a few instead, use:

yum-config-manager –enable remi-php73
yum -y install php php-opcache
In this example and in the downloadable virtual machine, I’ll make use of PHP 7. 3.

We must restart Apache to apply the changes:

systemctl restart httpd. service
5 Testing PHP / Getting Details About Your PHP Installation
The document root of the default website is /var/www/html. We will create a small PHP document (info. php) in that directory and call it in a browser to test the particular PHP installation. The file will certainly display lots of useful details about our PHP installation, such as the installed PHP version.

nano /var/www/html/info. php
<? php
Right now we call that file inside a browser (e. g.

Getting MySQL Support In PHP
To get MySQL support in PHP, we are able to install the php-mysqlnd package. It’s a good idea to install some other PHP segments as well as you might need them for your apps. You can search for available PHP5 segments like this:

yum search php
Select the ones you need and install them like this:

yum -y install php-mysqlnd php-pdo
In the next step I will set up some common PHP modules that are required by CMS Systems such as WordPress, Joomla, and Drupal:

yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap snuggle curl-devel
Now restart Apache web server:

systemctl restart httpd. support
Now reload in your browser and scroll down to the modules section again. You should today find lots of new modules like curl etc there.:

If you don’t need the PHP info output anymore, then delete that file for security factors.

rm /var/www/html/info. php

7 phpMyAdmin installation

phpMyAdmin is really a web interface through which you can manage your MySQL databases.
phpMyAdmin can now be installed as follows:

yum -y install phpMyAdmin

Now we configure phpMyAdmin. We all change the Apache configuration so that phpMyAdmin allows connections not just from localhost (by commenting out the stanza and adding the ‘Require most of granted’ line):

nano /etc/httpd/conf. d/phpMyAdmin. conf
Alias /phpMyAdmin /usr/share/phpMyAdmin
Parallelbezeichnung /phpmyadmin /usr/share/phpMyAdmin

AddDefaultCharset UTF-8

# Apache 2 . 4

Require all given

# Apache 2 . 2 Order Deny, Allow Deny from All Allow from 127. 0. 0. 1 Allow from:: 1

Options none
AllowOverride Limit
Need all granted

Restart Apache to apply the configuration changes:

systemctl restart httpd. service

Afterwards, you can access phpMyAdmin under

Leave a Reply

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