FoxuTech

How to Setup LAMP on Redhat & Centos 7

A “LAMP stack” is a combination of operating system and software which enables you to host websites and web apps on your server.

The term “LAMP” stands for Linux, Apache, MySQL/MariaDB and PHP.

Here will see how to setup LAMP server on centos/Redhat 7 server.

Install Apache/HTTP:

We can install http using following yum command.

Before install check is there any updates, and if any update it.

# yum check-update

# yum update -y

# yum install httpd –y

Once its finished start the apache service and enable it to start at boot,

# systemctl start httpd.service

# systemctl enable httpd.service

If in your environment, firewall enabled use following command to use allow defauil ports 80 (http) and 443 (https) using firewalld command.

# firewall-cmd –permanent –add-port=80/tcp

# firewall-cmd –permanent –add-port=443/tcp

Reload the firewall service for the changes to take effect.

# firewall-cmd –reload

You can test the apache service using your browser through http://server-ip-address You will see the default redhat Apache web page like below

Install MariaDB

MariaDB is a drop-in replacement for MySQL. It is easy to install, offers many speed and performance improvements, and is easy to integrate into most MySQL deployments. MariaDB offers more storage engines than MySQL, including Cassandra, XtraDB and OQGRAPH

Install mariaDB using following command # yum install mariadb-server mariadb Once installed start the mariaDB service and enable it in boot using  # systemctl start mariadb# systemctl enable mariadb

Now, to secure the MariaDB installation. You can do this by running:

# mysql_secure_installation

Enter following details as per your environment standard.

Your MySQL installation should now be secure.

Install PHP

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely used open-source general purpose scripting language that is especially suited for web development and can be embedded into HTML.

To Install PHP and its modules use following commands,

# yum install php php-mysql php-pdo php-gd php-mbstring -y 

Test PHP:

Create a sample “test.php” file in Apache document root folder and append the lines as shown below:

# vi /var/www/html/test.php

Add the following lines.

<?php 

phpinfo();

?>

Restart httpd service:

# systemctl restart httpd 

You can see the test page like below  

Install phpMyAdmin

phpMyAdmin is a free open-source web interface tool used to manage your MySQL databases. By default official RHEL 7.0 or CentOS 7.0 repositories doesn’t provide any binary package for PhpMyAdmin Web Interface. So let us install it from EPEL repository.

# yum install epel-release

Now, install phpMyAdmin:

# yum install phpmyadmin -y

Configure phpMyAdmin

By default, phpMyAdmin can only be accessed from the localhost itself. To make it to accessible globally, do the following steps.

Edit the phpmyadmin.conf file:

# vi /etc/httpd/conf.d/phpMyAdmin.conf

Find and comment the whole /<Directory> section and add the lines as shown below: And replace 127.0.0.1 with <<your-server IP>>;

[...]

Alias /phpMyAdmin /usr/share/phpMyAdmin

Alias /phpmyadmin /usr/share/phpMyAdmin 

## Comment the following Section ## 

#<Directory /usr/share/phpMyAdmin/>

#   <IfModule mod_authz_core.c>

#     # Apache 2.4

#     <RequireAny>

#       Require ip 127.0.0.1

#       Require ip ::1

#     </RequireAny>

#   </IfModule>

#   <IfModule !mod_authz_core.c>

#     # Apache 2.2

#     Order Deny,Allow

#     Deny from All

#     Allow from 127.0.0.1

#     Allow from ::1

#   </IfModule>

#</Directory> 

## Add the following lines: 

<Directory /usr/share/phpMyAdmin/>        

Options none        

AllowOverride Limit        

Require all granted</Directory>[...]

Edit “config.inc.php” file and change from “cookie” to “http” to change the authentication in phpMyAdmin:

# vi /etc/phpMyAdmin/config.inc.php

Change ‘cookie’ to ‘http’.

[…] /* Authentication type */$cfg[‘Servers’][$i][‘auth_type’]     = ‘http’;    // Authentication method (config, http or cookie based)?[…]

Restart the Apache service:

# systemctl restart httpd

Now you can access the phpmyadmin console by navigating to the URL http://server-ip-address/phpmyadmin/ from your browser.

Exit mobile version