Centos LAMP Server en 5 minutos o menos

Una de las formas comunes de explotar el potencial de Centos Linux es instalar un servidor LAMP (palabra que se forma de las iniciales de Linux Apache MySQL/MariaDB PHP) que nos sirva para hostear nuestras paginas/proyectos web y sera el tema de este articulo, instalar Centos LAMP Server en 5 o menos minutos.

En esta guía en español te diré que paquetes instalar, como ejecutar servicios, abrir puertos necesarios en el firewall y el reemplazo de MySQL por MariaDB.

Para resultados sin errores sugiero copiar y pegar los comandos evitando problemas por sintaxis.

Requerimientos para instalar Centos LAMP Server

Instalando y configurando Centos LAMP Server

Puedes verlo aquí debajo en vídeo (no olvides suscribirte a mi canal) o si lo prefieres, continuar leyendo el articulo

-Instalamos dependencias necesarias en nuestro Linux Centos Server

yum install httpd mariadb-server mariadb php php-mysql php-gd php-pear php-cli php-common NetworkManager-tui wget curl net-tools lsof firewalld

 Configuramos IP fija en Linux Centos

-Para nuestro servidor LAMP es fundamental tener configurada una ip fija (static) y no dinamica (DHCP) como es muy posible que tenga configurada

Primero verificamos que ip tiene actualmente nuestro servidor opensource

ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:66:51:db brd ff:ff:ff:ff:ff:ff
inet 192.168.5.103/24 brd 192.168.5.255 scope global noprefixroute dynamic enp0s3
valid_lft 82553sec preferred_lft 82553sec
inet6 fe80::1b46:3a00:be05:cd27/64 scope link noprefixroute
valid_lft forever preferred_lft forever

-El estado original de nuestra tarjeta de red podemos verificarlo en el archivo ifcfg-enp0s3

Este archivo se origina de 2 palabras, ifcfg y el nombre de la interfaz enp0s3 como vimos en la salida del comando ip anterior

Si miramos por dentro este archivo vemos:

cat /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s3
UUID=0dfe834a-ca6c-48af-b5e8-b3ee16f426a5
DEVICE=enp0s3
ONBOOT=yes
IPV6_PRIVACY=no

Modificando nuestras tarjetas con Network Manager Centos

-Es posible modificar directamente el archivo y hacer el cambio en la configuración de nuestra tarjeta pero lo recomendable es por medio de Network Manager Text User Interface

Es el nombre “largo” del comando nmtui

Lo ejecutamos y presionamos Enter sobre Modificar una conexión

-Veremos listadas todas las interfaces de red en nuestro equipo

Seleccionamos la que queremos modificar y presionamos Enter

-Bajamos con el cursor del teclado hasta el campo Automático de Configuración IPv4 y presionamos Enter

-Debemos cambiar de Automático a Manual para así poder cambiar a IP fija o estática

-Nos movemos a la opción Mostrar y presionamos Enter

-En este momento tenemos acceso a la configuracion de la tarjeta

Comenzaremos agregando una ip con su mascara de red presionando Enter sobre Añadir en Direcciones

-Ademas de la ip debes colocar la Puerta de enlace (gateway) y Servidores DNS, generalmente los que te da tu ISP (proveedor internet) o puedes usar los de google como en este ejemplo

Bajamos con el cursor al terminar al botón Aceptar y presionamos Enter

-Bajamos al botón Back y presionamos Enter

-Bajamos al botón Salir y presionamos Enter

Configuración ethernet Centos Linux

-Verificamos la configuracion de nuestra tarjeta de red Centos Linux

cat /etc/sysconfig/network-scripts/ifcfg-enp0s3

-Reiniciamos el servicio network para que tome los cambios

systemctl restart network

Activamos firewalld en Centos

-Por medio de firewalld podemos modificar las reglas iptables de Centos Linux de una forma algo mas comoda

Activamos el servicio para que se ejecute cada vez que haga boot el equipo y lo iniciamos

systemctl enable firewalld
systemctl start firewalld

-Verificamos su ejecución

systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since jue 2018-05-31 11:31:26 -05; 1h 37min ago
Docs: man:firewalld(1)
Main PID: 521 (firewalld)
CGroup: /system.slice/firewalld.service
└─521 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

-Abrimos los puertos 80 y 443 en el firewall

Reiniciamos el servicio firewalld

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
systemctl restart firewalld

Configuramos Apache en Centos LAMP Server

-Activamos el servicio para que se ejecute de forma automática cuando haga boot el equipo y lo iniciamos

systemctl enable httpd
systemctl start httpd

-Verificamos su ejecución

systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since jue 2018-05-31 13:14:14 -05; 50s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 9451 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─9451 /usr/sbin/httpd -DFOREGROUND
├─9453 /usr/sbin/httpd -DFOREGROUND
├─9454 /usr/sbin/httpd -DFOREGROUND
├─9455 /usr/sbin/httpd -DFOREGROUND
├─9456 /usr/sbin/httpd -DFOREGROUND
└─9457 /usr/sbin/httpd -DFOREGROUND

-Verificamos la configuracion este correcta

apachectl configtest
Syntax OK

-Abrimos un browser en otro equipo desde donde podamos conectarnos a nuestro Centos LAMP Server y debe cargarnos la pagina de inicio de Apache

Anotación sobre Apache en Centos Linux

Configuración: /etc/httpd/conf/httpd.conf
Configuración de módulos: /etc/httpd/conf.modules.d/
Puertos: 80 (http) y 443 (https – SSL)
Logs: /var/log/httpd/

Configuramos MariaDB Centos

-Activamos el servicio mariadb y lo ejecutamos

systemctl enable mariadb
systemctl start mariadb

-Verificamos su ejecución correcta

systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since jue 2018-05-31 13:27:38 -05; 1min 30s ago
Process: 9806 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 9726 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 9805 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─9805 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─9968 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin...

Protegemos MariaDB en Linux Centos

-Por default mariadb se instala sin contraseña en su cuenta root (administrador) por lo cual apenas lo instalamos debemos proteger su configuracion con el siguiente comando

Escribiremos una contraseña segura para la cuenta root y los demás parámetros los dejamos con su default de Y (yes)

/usr/bin/mysql_secure_installation

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): Presionamos Enter sin escribir nada
OK, successfully used password, moving on…

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

Set root password? [Y/n] New password: Escribimos una contraseña segura para la cuenta root
Re-enter new password: La volvemos a escribir
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…
… Success!
– 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!

-Verificamos la cuenta root. Nos conectamos con la contraseña que acabamos de colocarle

Podemos probar a ejecutar comandos (por ejemplo, show databases; para mostrar las db)

mysql -u root -p

Anotación sobre MariaDB

Configuración: /etc/my.cnf
Puertos: 3306
Logs: /var/log/mariadb/

Verificamos PHP en Centos LAMP Server

-Ya casi terminando, es momento de verificar que módulos PHP tiene nuestro servidor Centos Linux instalados

Primero verificamos versión instalada

php -v
PHP 5.4.16 (cli) (built: Apr 12 2018 19:02:01)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

-A continuación crearemos un fichero con una función php que nos dirá toda la información necesitada

vi /var/www/html/test.php
<?php
phpinfo();
?>

-Navegamos a http://192.168.5.103/test.php (haz el cambio a la ip de tu servidor Centos) y veremos todos los módulos que tenemos activos en nuestro apache

Centos LAMP Server, un conjunto de herramientas que unidas te facilitaran tus tareas a la hora de publicar tus proyectos web. Ya usas esta solución LAMP? cuéntame en los comentarios.

Satisfech@ con el articulo, hazme una donación, no importa la cantidad, la intención es lo que vale, dale click a este botón

Comparte este articulo opensource en tus redes sociales (compartir es sexy) por medio de los botones de redes sociales para que otros lo conozcan y apoyes mi blog.

Ademas, no olvides escribirme en los comentarios aquí debajo y pasa la voz compartiendo el tweet.