How To Install LAMP (Linux Apache, MariaDB, PHP) on CentOS 7

Install LAMP (Linux Apache, MariaDB, PHP) on CentOS 7

In this tutorial, we will show you how to install LAMP (Linux Apache, MariaDB, PHP) on CentOS 7. For those of you who didn’t know, LAMP which originally stands for Linux, Apache, MySQL, and PHP has now recently changed with the rise of MariaDB, a drop-in replacement for original MySQL. We will be using Apache for our web server and PHP for our scripting language. All components are free and open-source software, and the combination is suitable for building dynamic web pages.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. I will show you through the step-by-step installation of LAMP (Linux Apache, MariaDB, and PHP) on CentOS 7.

Install LAMP (Linux Apache, MariaDB, PHP) on CentOS 7

Step 1. First of all, make sure that all packages are up to date.

yum -y update

Step 2. Installing Apache on CentOS 7.

We will be installing Apache with yum, which is the default package manager for CentOS 7:

yum install httpd openssl mod_ssl

Restart Apache and add it to automatically start on your system start-up using:

systemctl restart httpd
systemctl status httpd
systemctl enable httpd

You can verify that Apache is really running by opening your favorite web browser and entering the URL http://your-server’s-address. you should get a “Testing 123″ page similar to the image below:

Step 3. Installing MariaDB on CentOS 7.

MariaDB is a drop-in replacement for MySQL. It is a robust, scalable, and reliable SQL server that comes a rich set of enhancements. We will also be using yum to install MariaDB:

yum install mariadb mariadb-server mysql

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MySQL:

mysql_secure_installation

To log into MariaDB, use the following command (note that it’s the same command you would use to log into a MySQL database):

mysql -u root -p

Restart the MariaDB database server and enable it to start on system start-up using:

systemctl restart mariadb
systemctl status mariadb
systemctl enable mariadb

Step 4. Installing PHP on CentOS 7.

Finally, run the commands below to install PHP along with other good-to-have modules:

yum install php php-mysql

You may want to install some other PHP extensions required by your applications. Here is the list:

php-bcmath          : A module for PHP applications for using the bcmath library
php-cli             : Command-line interface for PHP
php-common          : Common files for PHP
php-dba             : A database abstraction layer module for PHP applications
php-devel           : Files needed for building PHP extensions
php-embedded        : PHP library for embedding in applications
php-enchant         : Enchant spelling extension for PHP applications
php-fpm             : PHP FastCGI Process Manager
php-gd              : A module for PHP applications for using the gd graphics library
php-intl            : Internationalization extension for PHP applications
php-ldap            : A module for PHP applications that use LDAP
php-mbstring        : A module for PHP applications which need multi-byte string handling
php-mysql           : A module for PHP applications that use MySQL databases
php-mysqlnd         : A module for PHP applications that use MySQL databases
php-odbc            : A module for PHP applications that use ODBC databases
php-pdo             : A database access abstraction module for PHP applications
php-pear.noarch     : PHP Extension and Application Repository framework
php-pecl-memcache   : Extension to work with the Memcached caching daemon
php-pgsql           : A PostgreSQL database module for PHP
php-process         : Modules for PHP script using system process interfaces
php-pspell          : A module for PHP applications for using pspell interfaces
php-recode          : A module for PHP applications for using the recode library
php-snmp            : A module for PHP applications that query SNMP-managed devices
php-soap            : A module for PHP applications that use the SOAP protocol
php-xml             : A module for PHP applications which use XML
php-xmlrpc          : A module for PHP applications which use the XML-RPC protocol

Restart Apache using systemctl for the changes to take effect:

systemctl restart httpd
systemctl status httpd

To test PHP, create a test file named info.php with the content below. Save the file, then browse to it to see if PHP is working:

nano /var/www/html/info.php
<?php
phpinfo();
?>

Step 5. Configure firewall on CentOS 7.

Because everything is blocked by default on CentOS 7, you must enable HTTP/HTTPS traffic through the firewall. To enable web traffic, run the commands below:

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Congratulations! You have successfully installed LAMP. Thanks for using this tutorial for installing LAMP (Apache, MariaDB and PHP)) on CentOS 7 system. For additional help or useful information, we recommend you to check the official Apache, MariaDB, and PHP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

Save