How to Install Apache, MySQL, and phpMyAdmin on CentOS 8

How to Install Apache, MySQL, and phpMyAdmin on CentOS 8

What Do I Need?

  • A Dedicated or VPS Linux Server
  • CentOS 8

What is Apache, MySQL and phpMyAdmin?

Apache is an open-source web server solution, developed and maintained by the Apache Software Foundation and a super active community, it runs over 60% of all the web servers in the world. MySQL is an open-source relational database management system that stores all your website and user data. A relational database organizes information, or data, into one or more data tables in which data types can be related to each other; these relationships help structure the data. phpMyAdmin is another open-source software tool used to manage the tables and data inside databases. A control panel that supports various types of operations in either MariaDB or MySQL.

  1. Preparing your Machine
    1. In this guide, I use the hostname example.com with the IP address 192.168.0.100. These settings may differ for you, so please replace them with your own alternatives where appropriate.
    2. The EPEL repo for installing the latest version of phpMyAdmin is:
    rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
    yum -y install epel-release

    1. To edit files in the shell, please install the nano editor. If you prefer vi for file editing, then please skip this step.
    yum -y install nano


  1. Installing MySQL/MariaDB
  1. MariaDB is a fork of the original MySQL, developed by Monty Widenius. MariaDB is compatible with MySQL and is often used as an alternative in cPanel and Plesk.
  2. Run the following command to install MariaDB with yum:
yum -y install mariadb-server mariadb

  1. Then we create the system startup links for MySQL, so that it automatically starts when the machine starts:
systemctl start mariadb.service
systemctl enable mariadb.service

  1. Set passwords for the MySQL root account:
mysql_secure_installation

  1. Install Apache
  1. CentOS ships with Apache. Apache is directly available as a native package and therefore can be installed with:
yum -y install httpd
  1. Now configure your server to start Apache at every boot or reboot:
systemctl start httpd.service
systemctl enable httpd.service
  1. To be able to access the web server from outside of the network, and therefore be accessible to the public, we have to open the HTTP (80) and HTTPS (443) ports in the firewall. The default firewall on CentOS is firewalld. This can be configured with the firewalld-cmd command.
firewall-cmd --permanent --zone=public --add-server=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
  1. Visit your installed instance, in this example at https://192.168.0.100. You should see a placeholder effectively confirming a successful installation.
  1. Install PHP
  1. CentOS ships with a number of versions of PHP, some of them out of date. We will be installing newer versions in order to better protect our server from pesky virii and hackers.
  2. Add the Remi CentOS repository:
rpm -uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
  1. Install yum-utils as we require the yum-config-manager utility:
yum -y install yum-utils
yum update

  1. Install PHP 7.3
  1. I personally recommend ensuring that you install the most recent, stable release of PHP available and that, at the moment, version 7.3.
yum-config-manager --enable remi-php73
yum -y install php php-opcache
systemctl  restart httpd.service

  1. Test PHP and View Install Information
  1. The default root of a website is /var/www/html. We will create a PHP file (info.php) in that root directory and access it via our browser so we can test our installation and view useful details about the installation and environment.
nano /var/www/html/info.php

  1. Add the following lines to the blank file:
<?php
phpinfo();
  1. Viewing that page will confirm that everything is operating correctly together. Scrolling down the page reveals more interesting insights, for example missing MySQL support. Which is what we will add next.
  1. Install MySQL Support in PHP
  1. In order to enable proper MySQL support in PHP we have to install the php-mysqlnd package.
yum search php
yum -y install php-mysqlnd php-pdo
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap curl curl-develop
systemctl restart httpd.service

  1. Refresh your browser and you will notice some changes and updates. You should find lots of new modules, like curl:

  1. Once finished with your PHP info, I recommend deleting the file as it will prevent any would-be penetrators or hackers from being able to ‘fingerprint’ your server.
rm /var/www/html/info.php

  1. Install phpMyAdmin
  1. phpMyAdmin is the web interface that will allow you to control all your database awesomeness. Install as follows:
yum -y install phpMyAdmin

  1. Now we have to configure phpMyAdmin to work as expected. We change the Apache configuration so that phpMyAdmin is allowed connections not just from localhost but also elsewhere. We do this by commenting out the <RequireAny> stanza and adding Require all granted (in red):
nano /etc/httpd/conf.d/phpMyAdmin.conf
  1. Restart Apache:
systemctl restart httpd.service

  1. Visit your instance via your browser at:
  1. http://192.168.0.100/phpmyadmin/

Next Steps

There’s a lot that can be done next to your server dependent on its intended use case. Whatever you’re planning to use your new server for, I advise logging in as the ‘root’ superuser at your soonest opportunity and then running the following commands to ensure you have the latest updates and fixes:

yum upgrade
yum update
reboot

Conclusion

Personally, I’m a massive fan of CentOS, and Kali, of course. Whatever your plans are for your new server, make sure you keep on top of security updates and upgrades. Watch this space for more how-to guides on hardening and securing your CentOS installation. Be secure and above all, have fun.

  • Want to get top recommendations about best hosting? Just click this link!

How to Install and Setup CentOS 8

CentOS is a Linux operating system that provides an open-source, fully community
6 min read
JB Benjamin
JB Benjamin
Hosting Expert

How to Set Up NextCloud on CentOS 8

NextCloud is one of the best self-hosted solutions for sharing and collaborating
3 min read
JB Benjamin
JB Benjamin
Hosting Expert

How to Install mCrypt on CentOS 8

Essentially the mcrypt extension is a replacement for the classic Unix crypt com
2 min read
JB Benjamin
JB Benjamin
Hosting Expert

How to Troubleshoot Boot Up Issues with CentOS 8

Your server has broken and just won’t appear to do what you need it to do. As
2 min read
JB Benjamin
JB Benjamin
Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top