In this tutorial you will learn How To Install Apache MySQL PHP on CentOS 7 (LAMP) Stack step by step in 10 minutes.
By default in CentOS 7 from repositories available PHP 5.4 version. I will show how to install latest version of PHP 7.4 on CentOS 7.
Also we will install most recent version of MariaDB 10.5.
In general for install LAMP stack on CentOS 7 you need do next 4 steps:
Time needed: 10 minutes
How to Install Linux Apache MySQL PHP (LAMP) Stack on CentOS 7
- Update Linux Packages
Update all installed Linux packages with Linux yum command.
- Install the Apache Web Server
Install Apache web Server, start and set Apache to start at boot time.
- Install MySQL (MariaDB)
Install MySQL Server and configure MySQL Security (secure MySQL Server installation)
- Install PHP 7.4 with PHP modules
Install PHP 7.4, Install PHP modules and test PHP functionality.
Lets start step by step.
Step 1: Update Linux Packages
Update all installed Linux packages with Linux yum command:
# yum update -y
Optional: after Linux system updating I always recommend reboot the server:
# reboot
Step 2. Install the Apache Web Server
Now time install Apache WEB server with YUM command:
# yum install httpd
Start Apache Server with command:
# systemctl start httpd
Enable Apache auto start at boot time:
# systemctl enable httpd.service
Note. Make sure your CentOS 7 firewall ports are open and server can accept incoming TCP connections on HTTP 80 port and HTTPS 443. CentOS Firewalld
Open HTTP and HTTPS ports on CentOS 7
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload
Now try open test page. Type in browser you server IP or DNS name: http://Your_Server_IP. You will see this page:
Step 3. Install MySQL (MariaDB) Server
MariaDB Server is one of the most popular open source fork of MySQL
То Install latest MySQL Server MariaDB 10.5 create MariaDB.repo file in /etc/yum.repos.d/
# vim /etc/yum.repos.d/MariaDB.repo
And fill with following:
# MariaDB 10.5 CentOS repository list - created 2020-07-10 05:18 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
Save and close MariaDB.repo file.
Install MariaDB 10.5:
# yum install MariaDB-server
After installing run MySQL Server:
# systemctl start mariadb
Check the MySQL (MariaDB) status:
# systemctl status mariadb
Enable MySQL (MariaDB) auto start at boot time:
# systemctl enable mariadb
MySQL_secure_installation
Now we need secure MySQL Server installation.
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. MariaDB comes with a database named ‘test’. So we need remove anonymous user and ‘test’ database.
And setup root password for MySQL
Run for start MySQL database securing wizard run:
# mysql_secure_installation
And answer to questions in wizard:
- Switch to unix_socket authentication [Y/n] Y
- Change the root password? [Y/n] Y
- New password: Type new root password
- Re-enter new password: Re-enter new root password
- Remove anonymous users? [Y/n] Y
- Disallow root login remotely? [Y/n] Y
- Remove test database and access to it? [Y/n] Y
- Reload privilege tables now? [Y/n] Y
Step 4. Install PHP 7.4 with PHP modules
By default in CentOS 7 from repositories available PHP 5.4 version. We will install latest version of PHP 7.4 on CentOS 7 with modules:
# yum install epel-release yum-utils -y
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
# yum-config-manager --enable remi-php74
# yum install php php-common php-mcrypt php-cli php-gd php-curl php-mysql -y
Test PHP Installation
To test PHP functionality create a phpinfo.php file in /var/www/html with following contents:
<?php
phpinfo();
?>
Open with the web browser: http://Your_Server_IP/phpinfo.php
If your PHP 7.4 installation is correct you will see this page:
Conclusion
You just learned Install Apache MySQL PHP on CentOS 7 and securing MySQL Server
Discuss article in ArsTech Forum
Read also: Install Apache, MySQL, PHP (LAMP) stack On CentOS 6
yum install mod_php
you forgot it !