Installing LAMP (Linux, Apache, MySQL, PHP) Stack on CentOS 6

This article explains the steps to install the LAMP software bundle on CentOS 6.

Blue Light Tech

LAMP

LAMP is a web service solution stack suitable for building highly dynamic web applications and web sites. It is open source software and the term LAMP is an acronym for the components of the bundle, which are as follows:

  • Linux operating system
  • Apache Web Server
  • MySQL database
  • PHP (sometimes substituted by Python or Perl)

CentOS

CentOS is a Linux distribution and the abbreviation of Community Enterprise Operating System.

Prerequisites

The prerequisite to successfully install LAMP on CentOS 6 is a non-root user account to perform the installation.

Setting up Non-Root User Account

Root user has higher privileges and permissions which this installation does not require. To reduce the chances of risk which may come with unwanted permissions, a non-root user with some root privileges is used for the installation.

To create a non-root user for the installation, perform the following:

  1. Open the terminal and log in as root user on the server.
  2. Type the command
    adduser <username>

    Replace <username> with a name for the user. For example – tester
  3. To add a password for the user, run the command
    passwd <username>

    Replace <username> with a name for the user.
  4. Type a password for the user.
  5. Retype the password.

    Following figure shows the password being updated for the new user.

  1. To add the user to the wheel group for sudo privileges, run the command
    usermod –a –G wheel <username>

    Replace <username> with a name for the user.
    User is successfully added to the wheel group.

Installing LAMP

LAMP installation comprises the following tasks:

  1. Installing Apache
    1. Configuring Apache Virtual Hosts
  2. Installing MySQL
    1. Creating MySQL Database
  3. Installing PHP

Installing Apache

To install Apache Web Server on CentOS 6, perform the following:

  1. Log in to the terminal as the user performing the installation.
  2. To get an update of the packages, run the command
    sudo yum update

    System gets the updates.
  3. To install the Apache package, run the command
    sudo yum install httpd

    The system asks for confirmation on the installation.
  4. Press y to confirm the installation. When the installation is successful, the terminal displays a message as Complete!

Configuring Apache Virtual Hosts

To configure Apache virtual hosts, perform the following:

  1. Log in to the terminal.
  2. Run the command
    mkdir /etc/httpd/conf.d/vhost.conf
    to create conf file.
  3. Open the file and add the block as shown in the following figure.
  4. Save and exit the file.
  5. Create the directories mentioned in the block by running the following commands:
    1. sudo mkdir –p /var/www/sample.com/public_html
    2. sudo mkdir /var/www/sample.com/logs
  6. Start Apache web server by running the command
    sudo service httpd start
  7. Run the command
    sudo /sbin/chkconfig –levels 235 httpd
    on to set the service to run at boot.

Installing MySQL

To install MySQL database on CentOS 6, perform the following:

  1. Log in to the terminal as user performing the installation.
  2. Run the command
    sudo yum install mysql-server
  3. Run the command
    sudo service mysqld start
    to start MySQL.
  4. Run the command
    sudo /sbin/chkconfig –levels 235 mysqld on
  5. To secure the database, run the command
    sudo mysql_secure_installation.
    System prompts some questions.
  6. Press Enter for questions that follow. The database is now secure for storing data.

Creating MySQL Database

To create the MySQL database, perform the following:

  1. Log in to MySQL by running the command
    mysql –u root –p
  2. Type a password for the database when prompted.
  3. To create a database, run the command
    create database webdata
  4. Run the command
    grant all on <database name>.* to ‘<user name>’ identified by ‘<password>’;
    Replace the following parameters in the preceding command:
    • <database name> with a name for the database
    • <user name> with a name for the user
    • <password> with a password for the user
  5. Type quit to exit MySQL.

Installing PHP

To install PHP on CentOS 6, perform the following:

  1. Log in to the terminal as the user performing the installation.
  2. Run the command
    sudo yum install php php-pear.
  3. If you want to install MySQL support for PHP, run the command
    sudo yum install php-mysql
  4. Edit the file /etc/php.ini to update values for the following block:

    error_reporting = E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_ERROR | E_CORE_ERROR
    error_log = /var/log/php/error.log
    max_input_time = 30
  1. Uncomment the preceding lines.
  2. To create the log directory for PHP, run the command
    sudo mkdir /var/log/php
  3. To give ownership to the Apache user, run the commad
    sudo chown apache /var/log/php
  4. Restart the Apache service to register the update, by running the command
    sudo service httpd restart

23 Comments


Judi - 12/05/2018 12:55:43

TlrGBC https://www.genericpharmacydrug.com


Judi - 12/05/2018 12:48:55

nFYOnX https://www.genericpharmacydrug.com


Judi - 12/05/2018 12:45:57

f7X5Gj https://www.genericpharmacydrug.com


mike11 - 18/04/2018 02:53:50

FI7989 https://www.genericpharmacydrug.com


mike11 - 18/04/2018 01:57:26

lL8aqN https://www.genericpharmacydrug.com


mike11 - 18/04/2018 01:28:07

PKjvtl https://www.genericpharmacydrug.com


GoldenTabs - 08/01/2018 23:30:42

HHEvMx https://goldentabs.com/


GoldenTabs - 08/01/2018 15:03:41

2dVA3L https://goldentabs.com/


GoldenTabs - 08/01/2018 12:43:49

OUvKHk https://goldentabs.com/


GoldenTabs - 08/01/2018 04:31:11

5lFtci https://goldentabs.com/


Lanny - 06/12/2017 14:01:13

Could you transfer $1000 from my current account to my deposit account? http://avanafil.blog.hu/ cache odd buy avanafil extinct flannel “This is the first time I’ve competed with a lady competitor,” Painter said, impressed by first runner-up Margaret Devlin’s Halibut En Papillote, using a traditional French technique where the white fish is baked in parchment paper. Devlin is an EMT with Battalion 14 EMS station in the South Bronx.


Renaldo - 06/12/2017 14:00:55

Do you know the number for ? http://avanafil.blog.hu/ filch flush avanafil won singing The Yanks have fallen 3-1/2 game back for the last wild card spot and need to win three of four in the series against Texas that starts Monday night in Arlington if they are to climb over the Rangers.


JimmiNu - 10/09/2017 14:15:00

xMqURH http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com


Barnypok - 07/07/2017 13:20:42

G9eezi http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


JimmiXzSq - 20/05/2017 21:25:44

oBndUx http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


JimmiXzSq - 18/05/2017 06:54:47

qLW7Yr http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


Barnypok - 31/03/2017 18:37:37

FnZQ3W http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


matt - 20/02/2017 13:52:48

nSC8Ej http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


matt - 20/02/2017 11:55:12

A3LG4E http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


gordon - 20/02/2017 09:59:10

yxpIeQ http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


chaba - 20/02/2017 08:02:58

8sV5LB http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


gordon - 20/02/2017 06:05:26

6nRxlG http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


Jamie Rhodes - 02/11/2015 11:45:14

Successfully installed lamp on my centos machine.



Simpler than expected thanks to this!