Install Apache, MySQL, PHP (LAMP) Stack on CentOS 8

First disable SELinux by editing file

vi /etc/selinux/config

Find

SELINUX=enforcing

Replace with

SELINUX=disabled

Now restart the server.

reboot

Verify SELinux is disabled by running “sestatus” command. It should show disabled.

CentOS 8 sestatus

Install basic tools

Lets start by installing some basic tools like whois, curl, git etc..

dnf -y install wget curl telnet bind-utils net-tools git

Configure Firewall

On CentOS 8 by default only port 22 (SSH) is open to public. To run a web server, you need to open ports 80 and 443.

Run following command to open ports in firewall

firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --zone=public --permanent --add-service=ssh
firewall-cmd --zone=public --permanent --add-port=25/tcp
firewall-cmd --reload

Install Apache

To install Apache, run

dnf -y install httpd

Enable Apache to start on boot by running

systemctl start httpd

Verify Apache is running with command

netstat -lntp | grep 80

If Apache is running, you will see something like

CentOS 8 apache netstat

If all works good, you should be able to access your web server by opening your server IP in a web browser.

CentOS 8 Apache Default page

Install PHP

CentOS 8 comes with PHP 7.2

To install PHP, run

dnf -y install php php-cli php-xml php-json php-intl php-odbc php-pdo php-soap php-mysqlnd php-process php-bcmath php-gd php-mbstring

Install php-fpm

dnf -y install php-fpm

Enable php-fpm start on boot

systemctl enable php-fpm

Start php-fpm with

systemctl start php-fpm

php-fpm pool config files are located in folder /etc/php-fpm.d. php-fpm listens on socket at /run/php-fpm/www.sock

php-fpm package comes with Apache config file, it get placed on /etc/httpd/conf.d/php.conf. Restart apache to get php-fpm activated.

systemctl restart httpd

Now create a file

vi /var/www/html/1.php

with content


You should be able to access phpinfo page on URL

http://YOUR-SERVER-IP/1.php

php.ini file located in /etc/php.ini, you need to restart php-fpm service if you edit this file.

Install MySQL

We will install MariaDB, it is an open source drop in replacement for MySQL, created by creator of MySQL. To install MariaDB, run

dnf install mariadb-server

Enable MariaDB to start on boot

systemctl enable mariadb

Start MariaDB

systemctl start mariadb

CentOS 8 come with MariaDB 10.3. By default there is no root PW set, So you can connect to MySQL with command "mysql".

CentOS 8 MariaDB

To create a database, use

create database DB_NAME_HERE;

To create a user, run

grant all on DB_NAME_HERE.* to 'USER_NAME'@'localhost' identified by 'PASSWORD_HERE';

Now you have Apache, PHP, MySQL ready to use. Upload your web application to /var/www/html folder using SFTP.

See CentOS 8

Need help with Linux Server or WordPress? We can help!

Leave a Reply

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