Nexolinux
Sistemas Linux, servidores web, certificaciones, LPIC, Linux básico y profesional
Navigation
  • Home
  • Bash
  • LPIC
  • Noticias
  • Seguridad
  • Servicios
  • HowTo’s
You are here: Home › Servidor Web › Instalar servidor LEMP en Linux (Linux, Nginx, MariaDB y PHP)

Instalar servidor LEMP en Linux (Linux, Nginx, MariaDB y PHP)

1 julio, 2013 | Filed under: Servidor Web and tagged with: lemp, linux nginx, linux php, mariadb, nginx php

Muchos conocéis la arquitectura LAMP  que lleva años siendo bastante importante con el crecimiento de servidores web en Internet y a nivel de empresa. Las siglas LAMP venían a significar Linux, Apache, Mysql y PHP principalmente, aunque también habían variantes como con Perl o Python en lugar de PHP y con Postgres en lugar de Mysql.

Hoy en día está empezando a conocerse más y más las siglas LEMP en donde la configuración base podríamos decir que es Linux, Nginx (EngineX), PHP y MariaDB la cual ha sido sustituida recientemente por Red hat en sus versiones comerciales. El servidor que vamos a utilizar es alguna de las últimas versiones de CentOS

Instalamos Nginx

En otro par de artículos ya os relatamos el potencial de este «nuevo» servidor web, que poco a poco se está comiendo el mercado alcanzando una cuota de un 14% a nivel mundial.

Para instalarlo no lo tenemos en los repositorios oficiales con lo que una forma sencilla sería añadir el repositorio EPEL  y utilizar Yum

[root@server ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

Y ahora ya podremos instalar Nginx de forma sencilla:

[root@server ~]# yum install nginx -y

Iniciamos el servicio y lo configuramos para que arranque al reiniciarse la máquina.

[root@server ~]# /etc/init.d/nginx start 
Starting nginx: [ OK ] 
[root@server ~]# chkconfig nginx on

Abrimos el puerto 80 de iptables en el caso de que no lo tengamos abierto.

[root@server ~]# vi /etc/sysconfig/iptables 
[...]
-A INPUT -p udp -m state --state NEW --dport 80 -j ACCEPT 
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
[...]

Reiniciamos iptables para hacer efectivos los cambios.

[root@server ~]# /etc/init.d/iptables restart

Ahora podremos acceder sin problemas a la página de pruebas por defecto de Nginx

Test-Page-for-the-Nginx-HTTP-Server-on-EPEL-Mozilla-Firefox_001

Configurar Nginx

Abrimos el fichero /etc/nginx/nginx.conf y configuramos el worker_processes con el número de CPU. Para cualquier duda se explicaba en otro artículo

[root@server ~]# vi /etc/nginx/nginx.conf 
worker_processes 1;

A continuación editamos el “/etc/nginx/conf.d/default.conf”

[root@server ~]# vi /etc/nginx/conf.d/default.conf
#
# The default server
#
server {
    listen       80;
    server_name  server.nexolinux.com;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    ## Uncomment or Add the following lines
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

Reiniciamos el servicio Nginx

[root@server ~]# /etc/init.d/nginx restart

Instalar  MariaDB

Puede que tengamos problemas de dependencias al intentar instalarla, con lo que añadimos el Repositorio REMI para ello:

[root@server ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Instalamos el paquete compat-mysql55

[root@server ~]# yum --enablerepo=remi-test --disablerepo=remi install compat-mysql55

Creamos un fichero de repostorio para MariaDB y añadimos lo siguiente:

Para sistemas de  32bit :

[root@server ~]# vi /etc/yum.repos.d/mariadb.repo
# MariaDB 5.5 CentOS repository list - created 2013-06-06 07:42 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-x86
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Para sistemas de  64bit:

[root@server ~]# vi /etc/yum.repos.d/mariadb.repo
# MariaDB 5.5 CentOS repository list - created 2013-06-06 07:53 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Guardamos y al salir ejecutamos yum:

[root@server ~]# yum update

instalamos MariaDB:

[root@server ~]# yum install MariaDB-devel MariaDB-client MariaDB-server -y

Iniciamos el servicio de MariaDB y lo configuramos para que inicie al reiniciarse la máquina:

[root@server ~]# /etc/init.d/mysql start
Starting MySQL... SUCCESS! 
[root@server ~]# chkconfig mysql on

Configurar password mysql.

Por defecto el password de mysql está vacío, así que no podemos dejarlo así:

[root@server ~]# /usr/bin/mysql_secure_installation 
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Instalar PHP

[root@server ~]# yum install php php-common php-fpm php-mysql -y

Iniciamos el servicio y como hicimos con los anteriores para que arranque en un reinicio de máquina.

[root@server ~]# /etc/init.d/php-fpm start 
[root@server ~]# chkconfig php-fpm on

Configuramos PHP

Abrimos el fichero /etc/php.ini y buscamos la línea cgi.fix_pathinfo cambiamos el valor 1 a 0 :

[root@server ~]# vi /etc/php.ini
[...]
; http://www.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo
cgi.fix_pathinfo=0
[...]

Abrimos el fichero /etc/php-fpm.d/www.conf y cambiamos el usuario y grupo de apache to nginx:

[root@server ~]# vi /etc/php-fpm.d/www.conf 
[...]
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
[...]

Guardamos y reiniciamos servicio:

[root@server ~]# /etc/init.d/php-fpm restart

Comprobamos PHP

Creamos el fichero “info.php”  en el directorio raíz de Apache:

[root@server ~]# vi /usr/share/nginx/html/info.php 
<?php
phpinfo();
?>

Guardamos y reiniciamos Nginx:

[root@server ~]# /etc/init.d/nginx restart

Navegamos a http://server-ip-address/info.php y nos saldrá la página de información de PHP

Autoría: unixmen.com

Comparte esto:

  • Facebook
  • Twitter
  • LinkedIn

Me gusta esto:

Me gusta Cargando...

2 Responses to "Instalar servidor LEMP en Linux (Linux, Nginx, MariaDB y PHP)"

  1. Jose Carlos dice:
    21 julio, 2013 a las 04:10

    Muchísimas gracias de verdad. He podido hacerlo todo bien.
    El único problema que tengo ahora es a la hora instalar phpmyadmin, pero no se como configurarlo . Podrías ayudarme.
    Gracias!!!

    Responder
    1. m3t4g4m3 dice:
      21 julio, 2013 a las 20:29

      buenas!!

      Si no recuerdo mal, el tema era descargar phpmyadmin y ponerlo en el DocumentRoot de Nginx en este caso, en una carpeta llamada phpmyadmin por ejemplo. Con eso y creando un usuario o algo similar, creamos un usuario específico a ser posible, y le damos permisos.

      Saludos!

      Responder

Deja un comentarioCancelar respuesta

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.

Categorías.

  • Bases de datos
  • Bash & Comandos
  • HowTo
  • Linux General
  • LPIC
  • LPIC-2
  • Nivel Avanzado
  • Nivel Basico
  • Noticias
  • Seguridad
  • Servicios
  • Servidor Web

Entradas y Páginas Populares

  • Comando fuser, Localizamos procesos que usan un fichero.
    Comando fuser, Localizamos procesos que usan un fichero.
  • Ejemplos usos mount y umount
    Ejemplos usos mount y umount
  • Ficheros de usuarios /etc/passwd y /etc/shadow
    Ficheros de usuarios /etc/passwd y /etc/shadow
  • Instruccion READ en Bash
    Instruccion READ en Bash
  • ¿Cómo cifra linux las contraseñas?
    ¿Cómo cifra linux las contraseñas?
  • Proxy Squid, control de accesos ACL (II)
    Proxy Squid, control de accesos ACL (II)
  • 15 dispositivos que funcionan con Linux
    15 dispositivos que funcionan con Linux
  • fichero fstab
    fichero fstab
  • HowTo:Ejecutar comando como otro usuario.
    HowTo:Ejecutar comando como otro usuario.
  • Comandos más usados para gestionar Iptables
    Comandos más usados para gestionar Iptables

© 2025 Nexolinux

Utilizamos cookies propias y de terceros para mejorar nuestros servicios y mostrar publicidad relacionada con tus preferencias. cerrar Política de cookies
Privacidad y política de cookies

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Siempre activado
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
GUARDAR Y ACEPTAR
 

Cargando comentarios...
 

    %d