Installing a LAMP environment on Debian and derivatives

This tutorial will explain how to install a development environment LAMP. But what is that LAMP? LAMP is short for Linux + Apache2 + PHP5 + MySQL, that is, an environment to write scripts, maintain or set up sites made or written in PHP with MySQL on an Apache server.

Getting your hands on the matter ...

We install Apache2

server@host:# apt-get install apache2 apache2-doc

Basic use of Apache:

server@host:# /etc/init.d/apache2 {start|stop|restart|reload|force-reload}

Now, how do we tell Apache2 to use the modules we installed for it?

Editing /etc/apache2/apache2.conf and adding:

<IfModule dir_module>
DirectoryIndex index.html index.htm index.shtml index.cgi index.php index.php3 index.pl index.xhtml
</IfModule>

Add modules:

Can be found in / usr / lib / apache2 / modules /

For example: Mod_Rewrite overwrite urls to make them more user friendly.

Add in /etc/apache2/apache2.conf:

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

A more elegant way can be, from the command terminal enable it with the following command:

server@host:# a2enmod rewrite

And then restart Apache:

server@host:# /etc/init.d/apache2 restart

PHP5 Installation / Configuration

server@host:# apt-get install libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd php5-idn php-pear php5-imagick php5-imap php5-json php5-mcrypt php5-memcache php5-mhash php5-ming php5-mysql php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Some changes to PHP 5

En /etc/php5/apache2/php.ini:

Upload files to server [size]:

upload_max_filesize = 8M

Memory usage:

memory_limit = 32M

Upload files, POST method:

post_max_size = 8M

Start, restart PHP 5?

PHP 5 runs on the system as an Apache2 module, so if we do some configuration in PHP5 just by restarting Apache, the changes made are applied.

MySQL Installation / Configuration

server@host:# apt-get install mysql-server

During the installation you will be asked for the password for the MySQL root user, for security reasons, try to make it different from the root password of the system.

Basic usage of MySQL:

server@host:# /etc/init.d/mysql {start|stop|restart|reload|force-reload|status}

And in the settings [/etc/mysql/my.cnf, line 71 approximately] we enable the logs uncommenting:

log  /var/log/mysql/mysql.log

And then restarting MySQL for the changes to take effect ...

server@host:# /etc/init.d/mysql restart

Installation / Configuration of PHPMyAdmin

server@host:# apt-get install phpmyadmin

And the configuration comes in the config.inc.php file, which is not there, but we will create it with the following content:

<?php
$cfg['blowfish_secret'] = 'phpmyadmin';
$i = 0;
$i++;
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
?>

Virtualhosting

It is a method that allows the publication of several websites [with several different domain names] under the same IP address. Allows you to share memory and processor cycles [Hz] more efficiently.

Apache2 Commands for VirtualHosting:

  • a2ensite: Activate a website. The configs must be in / etc / apache2 / sites-available /
  • a2dissite: Deactivate a website.
  • a2enmod: Activates an apache module available in / etc / apache2 / mods-available /
  • a2dismod: Deactivate a module.

Create a virtualhost

We create the configuration file of the VirtualHost:

server@host:# cd /etc/apache2/sites-available/
server@host:/etc/apache2/sites-available# touch blog.example.com

We create the folder where the website will be ...

server@host:# mkdir -p /var/www/blog/

Blog.example.com configuration:

<VirtualHost *:80>
ServerAdmin admin@blog.example.com
ServerName blog.example.com
DocumentRoot /var/www/blog/
# HTML documents, with indexing.
<Directory />
Options +Includes
</Directory>
</VirtualHost>

We enable:

server@host:# a2ensite blog.example.com

And then? Sure, the happy ending:

server@host:# /etc/init.d/apache2 restart

Note: We should talk to our network administrator, if we are better, to add an A record in DNS that points to our IP with the name "blog”. This must be done to redirect all DNS polls from blog.example.com to our PC.

Then we just write in our browser:

http://blog.example.com

And we will have access to the site in question.

It only remains to install a WordPress or a Drupal on this virtualhost, if we are going to develop, from scratch or a framework.

That's all, see you at another time to continue installing / configuring services on GNU / Linux systems.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   3ndriago said

    Installation of WampServer or XAMP in WinOS:

    1- Double click installer. *
    2-Enjoy!

    MAMP installation on MacOS:
    1- Download the MAMP disk image from http://www.mamp.info.
    2- Open the disk image and drag MAMP into your Applications folder.
    3-Enjoy!

    God bless the GUIs !!!!!!!!!!!!!!!

    1.    KZKG ^ Gaara said

      But ... simple or easy does not mean better. Typical example ... the vast majority of web servers (and not webs) in the world work on UnixLike systems ... in addition to obviously NOT having a GUI. And ... I doubt that the administrators of companies like Google, HP, Twitter, MySQL, Facebook, Intel, Dell, etc etc etc are wrong 😀

      Cheers bro

    2.    assuarto said

      Installing Apache2 on Debian
      1 .- # apt-get install apache2 apache2-doc
      2.- Enjoy!

  2.   koratsuki said

    xD, good that one, but okay ... How would you customize that if you didn't have a GUI?

    1.    KZKG ^ Gaara said

      You would have to do an SSH -X to forward the X and whatever you open in Windows that is shown on your computer ... oh .. mmm wait, I just remembered that Windows does not have SSH nor can it be forwarding O_O

      1.    taregon said

        Don't change the theme, install XAMP just by clicking next and stopping / starting services from a single icon ... aha, that's priceless = P

        In the future, if the options available in Windows are not enough, there will always be the option of looking for a penguin and breaking windows 🙂

        1.    KZKG ^ Gaara said

          I'll be the weirdo who prefers to install each individual service ... manually ^ ⁻ ^ » ... hehe

          1.    koratsuki said

            It's not you alone, I like it that way too xD ...

  3.   3ndriago said

    Let's see, let's start by clarifying some concepts:
    1- The juxtaposition of interfaces (graphic-command line) is not a war between good and evil, it is not Aragorn VS Sauron, there is no good or bad, or in fact both are "the good" if they suit your needs. purposes.
    2-That I emphasize the simplicity of the click against the command line, does not mean that I deny the importance of the second, nor that I say that the first is "better". I'm just saying that it is, at least, friendlier
    3- The fact that many mega-servers like the ones you mention do not have GUIs, does not make the command line interface superior either, only more suitable for that purpose. In Propositional Logic this is called a Fallacy, since based on true arguments, you arrive at a false conclusion. Can you imagine a smartphone based on the command line? Once again, only the application judges which interface is more competent.
    Judging by the title of the article ("Installation of a LAMP environment in Debian and derivatives") it is not possible to grasp what purpose this Apache installation is going to have, that is, it is not understood that it is going to be for Google, Dell, etc. etc. etc. (Also I highly doubt they use Apache !!! but I have no arguments here). Based on my personal use -only to test websites in a local environment before putting them online- if I had to do the deployment like this, based on the command line, I would shoot myself or change my job 😀
    And finally, a Chinese proverb, an ancient culture from which much needs to be learned, which beautifully reflects the concept of 'make your life easy': «Do not do what you can do while sitting down, and do not do what you can do while lying down. ».

    1.    KZKG ^ Gaara said

      Indeed haha ​​... WordPress.com as well as Opera.com use Nginx, notably less consumer and really recommended 😀

      About what you say, at least I prefer to try to simulate as well as possible the final environment where the site will be.
      That is, I install all the services and configure thinking about how they will be installed and configured, but on the final server where the site will be (once finished).

      That is why I have always preferred to install everything by hand and configure it myself.

    2.    George said

      Sorry for meddling after so long, maybe you already know why big servers don't have a GUI.
      graphical interfaces (GUI) require a graphical environment for their use. The same that uses resources in any team is of the capacity that is, as administrators, the last thing we want is to "waste" resources of a team to build a graphical environment.

      So, yes, if there is good and bad, argon vs sauron, when you need the server to respond to thousands of requests, search in bd, send and receive emails, and also run some other application, simply uninstall the graphical environment and that's it

      regards!

  4.   Gabriel said

    You can also use the xamp that consists of pasting the files in a root directory, faster if we only want to develop.

  5.   taregon said

    Sure, I'm not old school but this instruction

    server @ host: # /etc/init.d/apache2 restart

    It could also be executed in the following way

    server @ host: # sudo service apache2 restart

    It was just a piece of information that I wanted to share, since whenever I enter blogs I see that it is more common to use the first option 🙂

    1.    KZKG ^ Gaara said

      In Debian this second method that you propose I don't think it can be used.

  6.   koratsuki said

    We all know that Window $ and MAC have their advantages, nice GUI [MAC only, Windows GUI sucks], many facilities, many clicks on the next button, etc, but guys, the unborn Linux with its horrendous command line must also give it the opportunity, apart from the blog is Linux, if I publish how to install a Wamp here, I get banned for life xD. One, because it is to give sicuiente until your finger gets tired, the other because it is from Windows ...

    So, let's be good and don't mistreat me xD.

    @Taregon: I am old school and I prefer the /etc/init.d/ restart, although there is also an "apache2ctl restart".

    1.    3ndriago said

      Totally agree, is that my previous partner was to respond to KZKG ^ Gaara, but I did not follow the trend ... the fallacy is his, not yours 😀

      1.    koratsuki said

        Sorry, then… xD

    2.    3ndriago said

      Totally agree, what happens is that my previous comment was in response to KZKG ^ Gaara, but I did not follow the trend correctly, the fallacy is his, not yours 😀

    3.    taregon said

      Don't worry, no one will get hurt 😉 that's why I say I'm not from the "old school" since I'm bad at retaining routes in my mind, if I change from Mint to Centos, what I knew about one doesn't apply to the other and I prefer to look for commands that are compatible on both systems.

      IF I CAN DO IT LYING I DON'T SEE WHY SITTING UP XD more or less the proverb went like this.

    4.    KZKG ^ Gaara said

      Neither like that, if you do the post on how to download, install and configure LAMP ... it will gladly put it 😀

  7.   jamin samuel said

    Hello guys .. here is a tutorial it seemed ... very practical and simple

    http://www.taringa.net/posts/apuntes-y-monografias/14741966/Instalar-XAMPP-en-Linux.html

  8.   koratsuki said

    Now reviewing documentation, I see that in the benchmarks, Nginx gives Apache, Cherokee, and Lighthttpd perfect by far ...

  9.   resilver said

    Thanks, excellent guide, it helped me a lot, I want to work with cakephp but I needed to install a local web server with lamp first.

  10.   James said

    Hello, I am new to linux (Fedora 20), I have installed the LAMP server and everything is perfect, except for one problem ... It turns out that once everything is working, and I open an "index.html", it does it without problem shows the page in the browser. But when trying to open an «index.php», the download window opens asking what to do with the file «Save» «Cancel», but it does not show it in the browser.
    I have tried everything I have found on the web but nothing solves the error, I appreciate any help or guidance. Thank you.

  11.   Jaime Rodriguez said

    Hello good afternoon to everyone.
    I don't know if this section will be the most suitable for making a query regarding the result I receive after performing a "var_dump"….
    I will say that I am new to Linux (Fedora 20) and I do not control the OS very well.

    RESULT OF A var_dump IN WAMPSERVER-WINDOWS 7.

    array (size = 6)
    'id' => string '1' (length = 1)
    'name' => string 'jaime' (length = 5)
    'email' => string 'jrbios.net@gmail.com' (length = 20)
    'content' => string 'this is another comment' (length = 23)
    'date' => string '2014-11-21 18:12:16' (length = 19)
    'status' => string '0' (length = 1)

    ************************************************** *******************

    RESULT OF A var_dump IN LAMP-FEDORA 20.

    array (6) {["id"] => string (2) "17" ["name"] => string (15) "Jaime rodriguez" ["email"] => string (26) "flamencogranaino @ gmail. com »[" content "] => string (21)" this is a comment "[" date "] => string (19)" 2014-12-05 21:32:26 "[" status "] => string (eleven" }

    ************************************************** ************************************************** *

    The point is that in wamp the result appears ordered and the data received from the db in red.
    and in lamp everything appears in a single line, between brackets and all the data in black….
    I would appreciate any guidance or clarification of why this happens and if there is any solution to receive the data as in wamp.
    Thank you very much in advance, best regards.

    Jaime Rodriguez