Fedora LAMP (Linux, Apache, MariaDB, PHP) Tutorial

Para tus implementaciones opensource, para tus desarrollos, seguro necesitaras un stack Fedora LAMP

Sigue leyendo este tutorial en español paso a paso donde te muestro como instalarlo y configurarlo FÁCIL en tu servidor Fedora

Que es un stack LAMP?

Un stack LAMP (o solución LAMP) es el conjunto de 4 soluciones para crear implementaciones web (sitios, paginas dinámicas, etc)

Su nombre viene de las 4 iniciales Linux, Apache, MySQL/MariaDB y PHP. De mas esta decir que todos son opensource

Fedora LAMP requerimientos

Instalamos paquetes y dependencias de Fedora LAMP

-Junto a los paquetes de apache, mariadb y php, se instalaran una serie de dependencias necesarias para nuestro LAMP

dnf install httpd mariadb-server mariadb NetworkManager-tui php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-memcache php-pecl-memcached php-gd php

Quieres ver este Fedora LAMP tutorial en vídeo? Aquí debajo te lo muestro, ah, y no olvides suscribirte a mi canal

Configuramos IP estática en el servidor Fedora LAMP

-Si acabas de instalar tu servidor Fedora Linux, es muy posible que su conexión este en modo DHCP

Por lo cual es muy recomendable hacer el cambio a modo static (ip estatica o fija)

Esta tarea la podemos realizar desde Fedora Cockpit en el menú ip estática o por consola como mostrare aquí en este articulo

Usando NetworkManager TUI en Fedora

Ejecutamos NetworkManager TUI

nmtui

-La interfaz de NetworkManager TUI es bastante sencilla

Presionamos Enter sobre Modificar una conexión para hacer los cambios

-Nos aparece un listado de las tarjetas de red detectadas en nuestro servidor Fedora

Seleccionamos la tarjeta (ens18 en este caso) y por medio de la tecla TAB cambiamos al botón Editar y presionamos Enter

-Seguimos usando la tecla TAB y cambiamos de Automático a Manual la Configuración IPv4

-Otro TAB y presionamos Enter sobre Mostrar de Configuracion IPv4

-Mínimo debemos agregar o modificar los siguientes campos

  • Direcciones: Dirección ip/mascara (en este ejemplo 192.168.5.101/24)
  • Puerta de enlace: Puerta de salida o gateway
  • Servidores DNS: Pueden ser los de tu ISP o google, etc
  • Requiere dirección IPv4 para esta conexión
  • Conectar de forma automática
  • Disponible para todos los usuarios

Finalmente damos Enter sobre el botón Aceptar

-Nos regresamos con TAB y Enter hasta el botón Salir, desde donde regresaremos al prompt de consola

Como verificar configuracion actual de red en Fedora

-La forma mas rápida en consola es mirando la configuracion actual con un comando cat

Si nos fijamos, todo lo que configuramos en NetworkManager TUI ya debe estar en este fichero

cat /etc/sysconfig/network-scripts/ifcfg-ens18
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
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=ens18
UUID=75139538-34e4-3d92-b224-1351992569b5
ONBOOT=yes
AUTOCONNECT_PRIORITY=-999
DEVICE=ens18
IPADDR=192.168.5.101
PREFIX=24
GATEWAY=192.168.5.3
DNS1=1.1.1.1
DNS2=8.8.8.8
DNS3=192.168.5.3

-Reiniciamos NetworkManager para que tome los cambios (OJO, si hiciste cambio de ip, seguramente tu conexión ssh se cerrara obligándote a reconectarte)

Verificamos el estado actual de NetworkManager

systemctl restart NetworkManager
systemctl status NetworkManager
NetworkManager.service - Network Manager
Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2018-12-07 14:35:08 -05; 8s ago
Docs: man:NetworkManager(8)
Main PID: 1777 (NetworkManager)
Tasks: 4 (limit: 1146)
Memory: 5.5M
CGroup: /system.slice/NetworkManager.service
└─1777 /usr/sbin/NetworkManager --no-daemon

-Una ultima comprobación con el comando ip

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: ens18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether ce:15:8c:67:70:7c brd ff:ff:ff:ff:ff:ff
inet 192.168.5.101/24 brd 192.168.5.255 scope global noprefixroute ens18
valid_lft forever preferred_lft forever
inet6 fe80::7164:fce0:7091:80b9/64 scope link noprefixroute
valid_lft forever preferred_lft forever

Reglas de firewall para Fedora LAMP

-Primero verificamos tengamos firewalld ejecutándose en nuestro servidor

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 Fri 2018-12-07 11:42:18 -05; 2h 55min ago
Docs: man:firewalld(1)
Main PID: 557 (firewalld)
Tasks: 2 (limit: 1146)
Memory: 25.3M
CGroup: /system.slice/firewalld.service
└─557 /usr/bin/python3 /usr/sbin/firewalld --nofork --nopid

-Después vamos a permitir trafico por los puertos http y https (80 y 443)

firewall-cmd --permanent --add-service=http
success
firewall-cmd --permanent --add-service=https
success

-Reiniciamos el firewall para que tome los cambios

systemctl restart firewalld

Configuramos Apache para Fedora LAMP

-En nuestro estack LAMP usaremos Apache como servidor web

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

systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
systemctl start httpd

-Verificamos su correcta ejecución

systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/httpd.service.d
└─php-fpm.conf
Active: active (running) since Fri 2018-12-07 14:39:01 -05; 25s ago
Docs: man:httpd.service(8)
Main PID: 1842 (httpd)
Status: "Running, listening on: port 80"
Tasks: 213 (limit: 1146)
Memory: 16.3M
CGroup: /system.slice/httpd.service
├─1842 /usr/sbin/httpd -DFOREGROUND
├─1849 /usr/sbin/httpd -DFOREGROUND
├─1850 /usr/sbin/httpd -DFOREGROUND
├─1851 /usr/sbin/httpd -DFOREGROUND
└─1852 /usr/sbin/httpd -DFOREGROUND

-Y no esta de mas verificar su configuracion actual no tenga errores

apachectl configtest
Syntax OK

-Importante sobre Apache
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/

-Navegamos a la ip del servidor desde otro equipo verificando se nos muestre la pagina de inicio de apache

Configuramos MariaDB para Fedora LAMP

-MariaDB es nuestro motor de bases de datos en el stack LAMP y comenzamos activando su servicio

Después lo iniciamos

systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
systemctl start mariadb

-Ya iniciado el servicio, lo verificamos este ejecutándose correctamente

systemctl status mariadb
mariadb.service - MariaDB 10.3 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/mariadb.service.d
└─tokudb.conf
Active: active (running) since Fri 2018-12-07 14:47:35 -05; 28s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 2463 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
Process: 2293 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)
Process: 2269 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Main PID: 2413 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 49 (limit: 1146)
Memory: 150.3M
CGroup: /system.slice/mariadb.service
└─2413 /usr/libexec/mysqld --basedir=/usr

Aseguramos la configuracion de MariaDB

-Por default MariaDB viene con algunas opciones sin configurar (como por ejemplo, la cuenta root sin contraseña)

Por lo tanto es IMPORTANTE asegurar nuestro MariaDB antes de comenzar nuestro desarrollos

/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):
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] Aceptamos escribir una contraseña para la cuenta root MariaDB
New password:<---Escribimos una contraseña (no se vera en pantalla)
Re-enter new password: <---Volvemos a escribir la contraseña
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] Eliminamos usuarios anónimos
... 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] No permitimos a la cuenta root conectarse de forma remota
... 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] Eliminamos la base de datos test
- 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] Volvemos a cargar las tablas de privilegios
... 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!

-Momento para probar los cambios a nuestro MariaDB ingresando por su CLI con la cuenta root

Se nos pedirá la contraseña de la cuenta root de MariaDB (la que acabamos de escribir en el paso anterior)

mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.10-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)

MariaDB [(none)]> quit;
Bye

-Importante sobre MariaDB
Configuración: /etc/my.cnf
Puerto: 3306
Logs: /var/log/mariadb/

Como verificar nuestro stack LAMP Fedora?

-Creamos un fichero php para probar la conf de nuestro php

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

-Damos permisos al usuario apache y grupo apache

chown apache.apache /var/www/html/test.php

-Navegamos desde otro equipo al url http://ip-server-fedora-lamp/test.php y nos aparecerá la pagina con todos los módulos PHP instalados

Ahora si podemos comenzar los desarrollos con nuestro stack LAMP en un servidor Fedora Linux, ya lo usas? estas en planes de instalarlo

Cuéntame aquí debajo 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.