How To Install Linux, Apache, MySQL, PHP (LAMP) stack On CentOS 7

Update your system:

# sudo yum update

Install Apache Server with Basic Configurations

# sudo yum install httpd

Once it installs, you can start Apache:


# sudo systemctl start httpd.service

Check the installation:

http://your_server_IP_address/

You will see the default CentOS 7 Apache web page, which is there for informational and testing purposes. If you cannot load – see firewall info below. Also check selinux:

Selinux in CentOS7

For permanent disabling after reboot do:


# sudo nano /etc/selinux/config
SELINUX=permissive or disabled

# sudo setenforce 0

and check with


# sestatus

The last thing you will want to do is enable Apache to start on boot. Use the following command to do so:


# sudo systemctl enable httpd.service

For the database, I am installing Maria:

# sudo yum install mariadb-server mariadb

When the installation is complete, we need to start MariaDB with the following command:


# sudo systemctl start mariadb

Secure MySql

# sudo mysql_secure_installation

Enable it:

# sudo systemctl enable mariadb.service

Install PHP

# sudo yum install php php-mysql php-pdo php-gd php-mbstring
# sudo yum install php php-pear

Edit /etc/php.ini for better error messages and logs, and upgraded performance.


nano /etc/php.ini
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
error_log = /var/log/php/error.log
max_input_time = 30

Create the log directory for PHP and give the Apache user ownership:


# sudo mkdir /var/log/php
# sudo chown apache /var/log/php

Locate and change date.timezone line to look like this, using PHP Supported Timezones list.


date.timezone = Continent/City

Restart

# sudo systemctl restart httpd.service

Install PHP Modules

# yum search php
php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstraction layer module for PHP applications
php-devel.x86_64 : Files needed for building PHP extensions
php-embedded.x86_64 : PHP library for embedding in applications
php-enchant.x86_64 : Enchant spelling extension for PHP applications
php-fpm.x86_64 : PHP FastCGI Process Manager
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
. . .

To get more information about what each module does, you can either search the internet, or you can look at the long description in the package by typing:


# sudo yum info package_name

If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:


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

Other important Firewalld options are presented below:


# firewall-cmd --state
# firewall-cmd --list-all
# firewall-cmd --list-interfaces
# firewall-cmd --get-service
# firewall-cmd --query-service service_name
# firewall-cmd --add-port=8080/tcp

Leave a Comment