Installing LAMP (Linux, Apache, MySQL, PHP) Stack on Debian 7

This article explains the steps to install the LAMP software bundle on Debian 7.

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)

Debian

Debian is a Linux distribution and Unix-like operating system. It comprises of free and open source software and most of it is licensed under the GNU General Public License.

Prerequisites

The prerequisites to successfully install LAMP on Debian 7 are as follows:

  • A non-root user account to perform the installation.
  • Ensure that sudo is installed on the system.
    If sudo is not installed, run the command as root
    apt-get install sudo
  • Set up the required hostname on the server.

Setting up Non-Root User Account

Root user has higher privileges and permissions which this installation does not require. To reduce the 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. Type a password for the user.
  4. Retype the password.

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

  1. Type answers for the questions that appear on the terminal.
    These questions are optional and if you do not wish to provide answers, press the Enter
    The system asks for confirmation on the information provided.
  2. Press y to confirm the information.
  3. To add the user to the sudo group for sudo privileges, run the command
    usermod –a –G sudo <username>

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

Installing LAMP

LAMP installation comprises the following tasks:

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

Installing Apache

To install Apache Web Server on Debian 7, 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 apt-get update && sudo apt-get upgrade

    System gets the updates as shown in the following figure.
  3. To install the Apache package, run the command
    sudo apt-get install apache2

    The system asks for confirmation on the installation.
  4. Press y to confirm the installation. The installation is successful.

Configuring Name-Based Virtual Hosts

To configure Apache virtual hosts, perform the following:

  1. Log in to the terminal.
  2. Create a configuration file for your website, at the directory /etc/apache2/sites-available.
    For example, com.conf.
  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:
    sudo mkdir –p /var/www/sample.com/public_html 
    sudo mkdir /var/www/sample.com/logs
  6. Enable the virtual host of the website, by running the command
    sudo a2ensite sample.com.conf

    Note: If you want to disable it at any time, run the command
    sudo a2dissite sample.com.conf
  7. Restart Apache web server by running the command
    sudo service apache2 restart

Installing MySQL

To install MySQL database on Debian 7, perform the following:

  1. Log in to the terminal as user performing the installation.
  2. Run the command
    sudo apt-get install mysql-server
  3. Press y to confirm the installation.
  4. Type password for MySQL server when prompted.
  5. To secure the database, run the command
    sudo mysql_secure_installation.
  6. Type the MySQL password when prompted.
  7. Press n if you do not want to change the MySQL password.
    System prompts some questions.
  8. 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 the password for the database when prompted.
    The mysql prompt appears.
  3. To create a database, run the command
    create database sample

    You can replace sample to a name of your choice for your database.
  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 Debian 7, perform the following:

  1. Log in to the terminal as the user performing the installation.
  2. Run the command
    sudo apt-get install php5 php-pear.
  3. Press y to confirm the installation.
  4. If you want to install MySQL support for PHP, run the command
    sudo yum install php-mysql
  5. Edit the file /etc/php5/apache2/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 apache2 restart

19 Comments


Donnie - 26/05/2018 14:03:15

I'd like to speak to someone about a mortgage https://www.drugonsale.com online pharmacy BEIJING/HONG KONG - China reiterated its opposition on Thursday to a European Union plan to limit airline carbon dioxide emissions and called for talks to resolve the issue a day after its major airlines refused to pay any carbon costs under the new law.


Judi - 12/05/2018 12:44:15

rKcHyx https://www.genericpharmacydrug.com


Judi - 12/05/2018 12:30:44

fSS7bE https://www.genericpharmacydrug.com


mike11 - 18/04/2018 01:14:49

avpsHU https://www.genericpharmacydrug.com


mike11 - 17/04/2018 23:52:34

F0g72k https://www.genericpharmacydrug.com


mike11 - 16/04/2018 16:39:42

TgaTBZ https://www.genericpharmacydrug.com


holabromx - 22/03/2018 08:55:30

http://google0125.com/


HolaBromz - 19/03/2018 18:35:53

http://google0123.com/


GoldenTabs - 07/01/2018 10:48:47

o5PRNJ https://goldentabs.com/


ElvaCyc - 12/11/2017 19:50:49

Hey guys!!!

designs and builds specialty lines of lead oxide production equipment, material handling systems, battery related process machinery, parts, and accessories for the battery, pigment, glass, and chemical industries. http://techbasys.com offers technical application and engineering services to help the customer acheive maximum benefit from their equipment and manufacturing processes.


ElvaNcr - 07/11/2017 14:36:34

Hey guys!!!

designs and builds specialty lines of lead oxide production equipment, material handling systems, battery related process machinery, parts, and accessories for the battery, pigment, glass, and chemical industries. http://techbasys.com offers technical application and engineering services to help the customer acheive maximum benefit from their equipment and manufacturing processes.


Barnypok - 08/07/2017 23:56:37

OaDApH http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


Barnypok - 08/07/2017 02:12:05

FmCUQ2 http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


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

8PmNKI http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


matt - 20/02/2017 11:16:06

OfEgze http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


gordon - 20/02/2017 09:20:05

TiQBiZ http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


chaba - 20/02/2017 07:22:57

5yxiwY http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


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

QvzQf7 http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com


Richard - 03/11/2015 11:19:01

All ran perfectly on my new debian machine, can now get started with hosting my site! Thanks.