Install Apache, MySQL, PHP (LAMP) Stack on CentOS 8
First disable SELinux by editing file
1 |
vi /etc/selinux/config |
Find
1 |
SELINUX=enforcing |
Replace with
1 |
SELINUX=disabled |
Now restart the server.
1 |
reboot |
Verify SELinux is disabled by running “sestatus” command. It should show disabled.
Install basic tools
Lets start by installing some basic tools like whois, curl, git etc..
1 |
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
1 2 3 4 5 |
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
1 |
dnf -y install httpd |
Enable Apache to start on boot by running
1 |
systemctl start httpd |
Verify Apache is running with command
1 |
netstat -lntp | grep 80 |
If Apache is running, you will see something like
If all works good, you should be able to access your web server by opening your server IP in a web browser.
Install PHP
CentOS 8 comes with PHP 7.2
To install PHP, run
1 |
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
1 |
dnf -y install php-fpm |
Enable php-fpm start on boot
1 |
systemctl enable php-fpm |
Start php-fpm with
1 |
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.
1 |
systemctl restart httpd |
Now create a file
1 |
vi /var/www/html/1.php |
with content
1 |
<?php phpinfo(); |
You should be able to access phpinfo page on URL
1 |
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
1 |
dnf install mariadb-server |
Enable MariaDB to start on boot
1 |
systemctl enable mariadb |
Start MariaDB
1 |
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”.
To create a database, use
1 |
create database DB_NAME_HERE; |
To create a user, run
1 |
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