Redhat / Centos LAMP Setup Guide

If you're setting up a RedHat or Centos server from a VPS server without a control panel, setting up a LAMP (Linux, Apache, MySQL, and PHP) can be a nuisance. Here is a basic setup guide for bringing your Linux server to the LAMP development environment.

RedHat / Centos 8

Starting with RHEL & Centos 8, there is a new package management tool "dnf" which replaces "yum". You may still use "yum", but we'll use dnf to illustrate the LAMP setup. Centos 8 has an SSL root certificate issue, so we'll reinstall the ca-certificates package.

# dnf update
# dnf reinstall ca-certificates

# dnf install php-mysqlnd php-fpm mariadb mariadb-server httpd httpd-tools tar
# dnf install gd php-gd php-mbstring php-xml php-json

# systemctl start php-fpm
# systemctl enable php-fpm
# systemctl start httpd
# systemctl enable httpd
# systemctl start mariadb
# systemctl enable mariadb
# /usr/bin/mysql_secure_installation

# Disable selinux
# Edit /etc/selinux/config, and change the following line:
SELINUX=enforcing
# Change enforcing to disabled.
SELINUX=disabled
# Restart the server.

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

RedHat / Centos 7

# yum install php mysql mysql-server php-pecl php-mysql php-pear 
php-pdo php-gd php-mbstring php-mcrypt php-xml httpd gd mariadb
mariadb-server

# systemctl start httpd.service
# systemctl enable httpd.service
# systemctl start mariadb.service
# systemctl enable mariadb.service
# /usr/bin/mysql_secure_installation

// Edit Apache Configuration Files.
# vi /etc/httpd/conf.d/phpMyAdmin.conf
# vi /etc/phpMyAdmin/config.inc.php

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

RedHat / Centos 6

# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
# rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

# cd /etc/yum.repos.d
// edit remi.repo, enable=1

# yum update
# yum install php mysql mysql-server php-pecl php-mysql php-pear 
php-pdo php-gd php-mbstring php-mcrypt php-xml httpd gd php-gd

# service mysqld start
# /usr/bin/mysqladmin -u root password 'new-password'
// Edit /root/.my.cnf
[client]
user=root
password=new-password
host=127.0.0.1
-- End of edit.

# chmod 600 /root/.my.cnf

// Create a file, /usr/local/bin/watchdog.sh
#! /bin/sh

for p in httpd mysqld
do
    /usr/bin/pgrep $p >/dev/null
    if [ $? -ne 0 ]
    then
        echo "$p is not running."
        /sbin/service $p restart
    fi
done
-- End of Edit.

Check system date and time zone.
# date
Thu Apr  7 11:35:34 CDT 2011
// Remove /etc/localtime, and make a soft link to desired time zone.
# ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime

# chmod +x /usr/local/bin/watchdog.sh

# chkconfig httpd on
# chkconfig mysqld on

// Edit /etc/httpd/conf/httpd.conf
// Create Virtual hosts.

# crontab -e
0 0 * * * /usr/sbin/ntpdate clock.redhat.com
*/10 * * * * /usr/local/bin/watchdog.sh

// Edit /etc/php.ini
// Uncomment date.timezone
date.timezone = "US/Central"

Share this post

Comments (0)

    No comment

Leave a comment

All comments are moderated. Spammy and bot submitted comments are deleted. Please submit the comments that are helpful to others, and we'll approve your comments. A comment that includes outbound link will only be approved if the content is relevant to the topic, and has some value to our readers.


Login To Post Comment