How To Set Up LAMP Environment with Apache MySql and PHP : Part-1?

Most of the industries are working on LAMP environment and with this article, you would learn how to set up a LAMP environment in Linux system with the use of PHP Apache and MySql. Well, this article will teach you to up Apache 2.2 php5.4 and MySql 5.5 with Remi repository

You just have to follow very simple steps, with YUM manager. YUM makes it really easy by avoiding the compilation process and install them easily with installing all other dependencies and you are notified of updates.

NOTE: If Missed You may read and apply below links

Part 1- Learn To Install Apache
Part 2- Learn To Install MySql
Part 3- Learn To Install PHP 

Scenario: My Server IP is 192.168.1.188

So let’s start and Learn To Set Up LAMP Environment with Apache MySql and PHP

Step 1: Enable Remi Repository

The most f the updated package is available under Remi repository. Install it in your system using following commands.

CentOS/RHEL 7:
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
 
CentOS/RHEL 6:
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm 

CentOS/RHEL 5:
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm 

Fedora 20:
# rpm -Uvh http://rpms.famillecollet.com/remi-release-20.rpm

Step 2: Install Apache

After adding Remi repository, install phpMyAdmin using yum package manager. All the dependencies will automatically be installed.

# yum --enablerepo=remi install httpd mod_ssl

Step 3: Start Your Server

As Apache don’t start automatically when you install, you need to start it manually.

#service httpd  start

The following message is displayed:

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
The IP address (shown in this example as 127.0.0.1) is used as the server name by default. In the following steps, set the server name for the next time the server is started.

Step 4: Apache VirtualHost Configuration

#vim /etc/httpd/conf.d/vhost.conf

After this file is open make the following changes

NameVirtualHost *:80

<VirtualHost *:80>
ServerName 192.168.1.188
ServerAdmin [email protected]
DocumentRoot /var/www/html/

DirectoryIndex index.php index.htm index.html

#ScriptAlias /cgi-bin/ /home/www/www.example.com/cgi-bin/
#<Location /cgi-bin>
# Options +ExecCGI
#</Location>

ErrorLog /var/log/httpd/error_log
CustomLog /var/log/httpd/access_log combined
</VirtualHost>
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
order allow,deny
allow from all
#allow from 127.0.0.1
</Directory>

Now save the file using the command  #: wq!


 Step 4: Allow iptables

If you don’t have iptables running then skip this step but sometimes it happens that Centos servers are running with iptables so we have to make some changes to allow Port 80 to get our apache server live for the public domain. else Port 80 and 443(SSL) will be blocked

#iptables -I INPUT -p tcp --dport 80 -j ACCEPT
#iptables -I INPUT -p tcp --dport 443 -j ACCEPT
#service iptables save

Note: After saving iptables restart Apache server. if Apache page doesn’t show up reboot the server and follow from step 5.


Step 5: Restart Apache Server

# Server httpd restart

Step 6: Check Your Installation

Now open a browser and Navigate to your Server IP address (for example, http://192.168.1.188).

How To Set Up LAMP Environment with Apache MySql and PHP ?

If you could see the page then you have successfully installed Apache on to you server

 

Step 7: Set for startUP configuration

As we have installed Apache and its up so make it get start automatically after every reboot you have to run following commands and your Apache server will start automatically when the server is rebooted.

#chkconfig httpd on

Some Useful Command

  1. To check httpd configuration file syntax
#httpd -t
  1. To check Apache automatic start at run levels
#chkconfig --list httpd

output will be …

httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
  1. To restart Apache server
#service httpd restart

Part 1- Learn To Install Apache
Part 2- Learn To Install MySql
Part 3- Learn To Install PHP