Instalar en pc ApacheMariaDB, PHP (pila LAMP) en el servidor Ubuntu 18.04 LTS

Como ya sabrás,LÁMPARAstack es una popular plataforma de desarrollo web de código abierto que se puede utilizar para ejecutar e implementar sitios web dinámicos y aplicaciones basadas en la web. Por lo general, la pila LAMP consta de Apache servidor web, bases de datos MariaDB/MySQL, lenguajes de programación PHP/Python/Perl. LAMP es el acrónimo deLProhibido,METROaria DB /METROYSQL,PAGSCV/PAGSllorar /PAGSerl. En este tutorial, veremos cómo instalar ApacheMariaDB, PHP (pila LAMP) en el servidor Ubuntu 18.04 LTS.

Instalar en pc ApacheMariaDB, PHP (pila LAMP) en el servidor Ubuntu 18.04 LTS

Para el propósito de este tutorial, usaré el siguiente cuadro de prueba.

  • Sistema operativo: Ubuntu 18.04 Servidor LTS de 64 bits
  • dirección IP: 192.168.225.22/24

1. Instalar el servidor web Apache

Instalar Apache servidor web, ejecute el siguiente comando desde la Terminal:

$ sudo apt install apache2

Comprobar si Apache el servidor web se está ejecutando o no:

$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Fri 2018-07-06 11:42:35 UTC; 27s ago
Main PID: 2079 (apache2)
Tasks: 55 (limit: 2322)
CGroup: /system.slice/apache2.service
├─2079 /usr/sbin/apache2 -k start
├─2081 /usr/sbin/apache2 -k start
└─2082 /usr/sbin/apache2 -k start

Jul 06 11:42:35 ubuntuserver systemd[1]: Starting The Apache HTTP Server...
Jul 06 11:42:35 ubuntuserver systemd[1]: Started The Apache HTTP Server.

Apache ¡El servicio está cargado y funcionando!

1.1 Ajustar el cortafuegos para permitir Apache Servidor web

De manera predeterminada, no se puede acceder al navegador web apache desde sistemas remotos si ha habilitado el firewall UFW en Ubuntu 18.04 LTS. Debe permitir el tráfico http y https a través de UFW siguiendo los pasos a continuación.

Primero, veamos qué aplicaciones han instalado un perfil usando el comando:

$ sudo ufw app list
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH

Como puedes ver, Apache y las aplicaciones OpenSSH tienen perfiles UFW instalados.

Si miras en el“Apache Completo”perfil, verás que habilita el tráfico a los puertos80y443:

$ sudo ufw app info "Apache Full"
Profile: Apache Full
Title: Web Server (HTTP,HTTPS)
Description: Apache v2 is the next generation of the omnipresent Apache web
server.

Ports:
80,443/tcp

Ahora, ejecute el siguiente comando para permitir el tráfico HTTP y HTTPS entrante para este perfil:

$ sudo ufw allow in "Apache Full"
Rules updated
Rules updated (v6)

Si no desea permitir el tráfico https, sino solo el tráfico http (80), ejecute este comando en su lugar:

$ sudo ufw app info "Apache"

Ahora, abra su navegador web y navegue hastahttps://servidorlocal/ohttps://Dirección IP/.

Si ve una pantalla como la de arriba, está listo para comenzar. Apache ¡el servidor está funcionando!

2. Instalar MariaDB

MariaDB es el reemplazo directo del servidor de base de datos MySQL.

Para instalarlo, ejecuta:

$ sudo apt install mariadb-server mariadb-client

La versión de MariaDB en los repositorios oficiales de Ubuntu podría estar desactualizada. Si desea instalar un MariaDB más reciente, agregue elRepositorio oficial de MariaDBpara Ubuntu e instálelo como se muestra a continuación.

Primero, agregue el repositorio de MariaDB e importe la clave como se muestra a continuación.

$ sudo apt-get install software-properties-common
$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 
$ sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://sgp1.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu bionic main'

Después de agregar el repositorio, ejecute los siguientes comandos para instalar MariaDB.

$ sudo apt update
$ sudo apt install mariadb-server

Verifique si el servicio MariaDB se está ejecutando o no usando el comando:

$ sudo systemctl status mysql

Salida de muestra:

● mariadb.service - MariaDB database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2018-07-06 11:52:12 UTC; 2min 39s ago
Main PID: 3869 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 27 (limit: 2322)
CGroup: /system.slice/mariadb.service
└─3869 /usr/sbin/mysqld

Jul 06 11:52:13 ubuntuserver /etc/mysql/debian-start[3906]: mysql
Jul 06 11:52:13 ubuntuserver /etc/mysql/debian-start[3906]: performance_schema
Jul 06 11:52:13 ubuntuserver /etc/mysql/debian-start[3906]: Phase 6/7: Checking and upgrading tables
Jul 06 11:52:13 ubuntuserver /etc/mysql/debian-start[3906]: Processing databases
Jul 06 11:52:13 ubuntuserver /etc/mysql/debian-start[3906]: information_schema
Jul 06 11:52:13 ubuntuserver /etc/mysql/debian-start[3906]: performance_schema
Jul 06 11:52:13 ubuntuserver /etc/mysql/debian-start[3906]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Jul 06 11:52:13 ubuntuserver /etc/mysql/debian-start[3906]: OK
Jul 06 11:52:13 ubuntuserver /etc/mysql/debian-start[3975]: Checking for insecure root accounts.
Jul 06 11:52:13 ubuntuserver /etc/mysql/debian-start[3979]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables

¡Mysql se está ejecutando!

2.1 Configurar la contraseña del usuario administrativo (raíz) de la base de datos

Durante la instalación de MariaDB, establecerá la contraseña para la cuenta de usuario administrativo (raíz).

Si intenta configurar la contraseña manualmente usando el comando:

$ mysql_secure_installation

No puede iniciar sesión establecer la contraseña. Verá un error como el siguiente.

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): 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Enter current password for root (enter for none):

Para solucionar este problema, inicie sesión como administrador de la base de datos MySQL usando el comando:

$ sudo mysql -u root

Después de iniciar sesión en el indicador de MySQL, ejecute los siguientes comandos uno por uno.

use mysql;
update user set plugin='' where User="root";
flush privileges;
q

Ahora, puede configurar la contraseña administrativa de la base de datos usando el comando:

$ mysql_secure_installation

Enter contraseña contraseña, y presione la tecla ENTER para aceptar los valores predeterminados.

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): # Press ENTER
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] # Press ENTER
New password: # Enter password
Re-enter new password: # Re-enter 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] # Press ENTER
 ... 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] # Press ENTER
 ... 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] # Press ENTER
 - 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] # Press ENTER
 ... Success!

Cleaning up...

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

Eso es todo. Se ha establecido la contraseña para la cuenta de usuario administrativo de la base de datos.

3, instala PHP

Para instalar PHP, ejecute:

$ sudo apt install php libapache2-mod-php php-mysql

Después de instalar PHP, creeinfo.phparchivo en el Apache carpeta de documentos raíz. Por lo general, la carpeta de documentos raíz de apache será/var/www/html/o/var/www/en la mayoría de las distribuciones de Linux basadas en Debian. En Ubuntu 18.04 LTS, es/var/www/html/.

Cree info.php en la carpeta raíz de apache como se muestra a continuación.

$ sudo vi /var/www/html/info.php

Agregue las siguientes líneas:

<?php
phpinfo();
?>

Guarde y salga del archivo. Reinicie el servicio de apache para que se apliquen los cambios.

$ sudo systemctl restart apache2

Ahora, abra su navegador web y escriba:https://dirección-IP/info.phpen la barra de direcciones.

Estará satisfecho con una pantalla como la siguiente.

Instalar módulos PHP

Para mejorar la funcionalidad de PHP, puede instalar algunos módulos PHP adicionales.

Para enumerar los módulos PHP disponibles, ejecute:

$ sudo apt-cache search php- | less

Salida de muestra:

Use las flechas y para moverse hacia arriba y hacia abajo entre los resultados. Para salir del resultado, escribaq.

Para encontrar los detalles de cualquier módulo php en particular, por examplephp-gdcorrer:

$ sudo apt-cache show php-gd

Para instalar un módulo php ejecute:

$ sudo apt install php-gd

Para instalar todos los módulos (aunque no es necesario), ejecute:

$ sudo apt-get install php*

No olvides reiniciar Apache servicio después de instalar cualquier módulo php.

¡Felicidades! Hemos configurado correctamente la pila LAMP en el servidor Ubuntu 18.04 LTS.

  • Instalar en pc ApacheMySQL, pila de PHP (LAMP) en Ubuntu 18.04 LTS
  • Instalar Nginx, MariaDB, PHP (LEMP Stack) en Ubuntu 18.04 LTS
  • Instalar en pc ApacheMariaDB, pila de PHP (LAMP) en Arch Linux
  • Instale la pila Nginx, MariaDB, PHP (LEMP) en Arch Linux

Y, eso es todo por ahora. Como puede ver, configurar la pila LAMP en Ubuntu es absolutamente fácil y sencillo. Cualquier persona con experiencia limitada puede configurar fácilmente la pila LAMP. Más cosas buenas por venir. ¡Manténganse al tanto!

¡Salud!

¡Gracias por pasar!

Ayúdanos a ayudarte:

¡¡Que tenga un buen día!!

Artículos Relacionados