Wednesday, December 21, 2016

How to install Apache, MySQL, and PHP 5.6 on CentOS 6 (LAMP)

If you find it tiresome like me to install LAMP on CentOS 6 but with PHP 5.6 then this step-by-step guide will walk you through to get up and running within 15 minutes.

Install MySQL
  • Update the system first.
sudo yum update
  • Download and add the repository then update again. 
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
  • Start MySQL
sudo yum install mysql-server
sudo systemctl start mysqld
  •  Make MySQL secure
sudo mysql_secure_installation
Install Apache

  •  Use the following commands to install and start Apache
sudo yum -y install httpd
sudo /etc/init.d/httpd start
  • Turn on external access of http (Port 80) and https (Port 443)
sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT 
sudo service iptables save
Install PHP 5.6

  • Add EPEL and REMI repo 
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm epel-release-latest-6.noarch.rpm
  • Now you need to enable the repo. Go to /etc/yum.repos.d and open remi.repo in text editor (i.e. vi)
cd /etc/yum.repos.d
vi remi.repo
  • Find the following sections and set enabled=1 
[remi]
name=Remi's RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/remi/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[remi-php56]
name=Remi's PHP 5.6 RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/php56/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/php56/mirror
# WARNING: If you enable this repository, you must also enable "remi"
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
  • Finally install the PHP and restart httpd!
sudo yum install php php-gd php-mysql php-mcrypt
sudo /etc/init.d/httpd restart 
At this point, you should have LAMP installed with PHP 5.6 and it's basic components.

Tuesday, December 20, 2016

How to install Apache, MySQL, and PHP 5.6 on CentOS (LAMP) in OFFLINE!

The basic steps for installing LAMP in offline CentOS servers in same for both CentOS 6.* and 7 but the syntax and packages are different. A generalized approach is described in this article. It is assumed that you run all of the commands as root.

Step 1: Get the necessary packages

The first step is to get the necessary packages from another CentOS system that has internet access. To install PHP 5.6 you might need to add EPEL and Remi repo. Please check the following posts to find out how to add them in your online CentOS system.
Now get the necessary packages with the following commands and copy them to your offline CentOS system.

yumdownloader --resolve php
repotrack -a x86_64 -p . php createrepo mysql-server

Step 2: Create a local repository in your offline CentOS system

Assuming you copies all of your packages under /tmp/rpms and you will use /home/local_repo as your local repository location. Now execute the following commands to create the repository.

mkdir /home/local_repo

mv /tmp/rpms/* /home/local_repo
chown -R root.root /home/local_repo
createrepo /home/local_repo

Now turn on the local repository creating a file /etc/yum.repos.d/local.repo with the following content.

[local]
name=CentOS - local packages
baseurl=file:///home/local_repo
enabled=1
gpgcheck=0
protect=1

Now if you execute the following command as test, you should see PHP 5.6 package is available.

yum list php

Step 3: Install the softwares and configure

yum install httpd
yum install my-server
yum install php php-devel php-mysql
/etc/init.d/httpd restart
iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
service iptables save

Monday, December 5, 2016

How to install Apache, MySQL, and PHP 5.6 on CentOS 7 (LAMP)

If you find it tiresome like me to install LAMP on CentOS 7 but with PHP 5.6 then this step-by-step guide will walk you through to get up and running within 15 minutes.

Install MySQL
  • Update the system first.
sudo yum update
  • Download and add the repository then update again. 
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
  • Start MySQL
sudo yum install mysql-server
sudo systemctl start mysqld
  •  Make MySQL secure
sudo mysql_secure_installation
Install Apache

  •  Use the following commands to install and start Apache
sudo yum -y install httpd
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
  • Turn on external access of http (Port 80) and https (Port 443)
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
Install PHP 5.6

  • If you already have EPEL installed then add REMI repo
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7*.rpm
Otherwise
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7*.rpm epel-release-7*.rpm
  • Now you need to enable the repo. Go to /etc/yum.repos.d and open remi.repo in text editor (i.e. vi)
cd /etc/yum.repos.d
vi remi.repo
  • Find the following sections and set enabled=1 
[remi]
name=Remi's RPM repository for Enterprise Linux 7 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/remi/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/7/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[remi-php56]
name=Remi's PHP 5.6 RPM repository for Enterprise Linux 7 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/php56/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/7/php56/mirror
# NOTICE: common dependencies are in "remi-safe"
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
  • Finally install the PHP!
sudo yum install php php-gd php-mysql php-mcrypt
sudo service httpd restart
At this point, you should have LAMP installed with PHP 5.6 and it's basic components.