GNU/Linux >> Tutoriales Linux >  >> Ubuntu

Instale LAMP Stack (Apache, MariaDB, PHP) en Ubuntu 22.04

La pila LAMP (Linux, Apache, MariaDB / MySQL y PHP) es la pila de tecnología de software más utilizada por las empresas de alojamiento para alojar sitios web y blogs. Además, esta pila se usa comúnmente para implementar sistemas de administración de contenido como WordPress, Drupal, Joomla, etc.

Aquí veremos cómo instalar la pila LAMP en Ubuntu 20.04.

Instalar pila de AMP

En Ubuntu, puede instalar la pila AMP manualmente instalando Apache, MariaDB y PHP uno por uno o la pila completa con un solo comando.

Al instalar AMP Stack usando un solo comando, instalará MySQL v8.0. Pero, al mismo tiempo, si elige instalar la pila LAMP manualmente, obtendrá MariaDB v10.6.

Método 1:Instalar LAMP Stack manualmente (uno por uno)

Instalaremos AMP (Apache v2.4, PHP v8.1 y MariaDB v10.6) en Ubuntu 20.04.

Instalar Apache

Primero, actualice el índice del repositorio de paquetes.

sudo apt update

Luego, instale el paquete apache2 usando el apt comando.

sudo apt install -y apache2 apache2-utils

Instalar MariaDB

MariaDB reemplazó a MySQL como servidor de base de datos predeterminado en Ubuntu y está disponible (v10.6) desde el repositorio de Ubuntu.

También puede instalar la última versión de MariaDB desde el repositorio de MariaDB.

sudo apt install -y mariadb-server mariadb-client

Luego, ejecute mysql_secure_installation Comando para asegurar la instalación de MySQL.

sudo mysql_secure_installation

Salida:

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
haven't set the root password yet, you should just press enter here.

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

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

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] N  << Disable Unix Socket Authentication
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y << Set MariaDB root password
New password: xxx << Enter new MariaDB root password
Re-enter new password: xxx << Re-enter new MariaDB root 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] Y << Remove Anonymous Users
 ... 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] Y << Disallow root login remotely
 ... 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] Y << Remove test database
 - 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] Y << Reload privilege tables
 ... 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

De forma predeterminada, el servidor Apache solo admite archivos HTML estáticos, no PHP. Por lo tanto, deberá instalar PHP y el paquete de extensión de PHP para MariaDB/MySQL si es necesario para habilitar la compatibilidad con PHP.

Ubuntu 22.04 viene con PHP v8.1.

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

Después de la instalación, reinicie el servidor web Apache.

sudo systemctl restart apache2

Ahora, puedes dirigirte a Testing LAMP Stack.

Método 2:instalar la pila LAMP en un solo comando

Instalaremos AMP (Apache v2.4, PHP v8.1 y MySQL v8.0) en Ubuntu 20.04.

Actualice el caché del repositorio usando el comando apt.

sudo apt update

Pegue debajo de la línea en la terminal y presione enter.

sudo apt install -y lamp-server^

El comando anterior buscará e instalará los paquetes necesarios para el servidor LAMP. Deberá esperar unos minutos para que se complete la instalación de la pila LAMP.

Ejecute mysql_secure_installation Comando para asegurar la instalación de MySQL.

sudo mysql_secure_installation

Salida:

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y << Enable validate password component to validate the strength of user passwords

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 << Level of password validation policy
Please set the password for root here.

New password: xxx << Set MySQL root password

Re-enter new password: xxx << Re-Enter MySQL root password

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y << Continue
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : Y << Remove anonymous users
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? (Press y|Y for Yes, any other key for No) : Y << Disable root login remotely
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : Y << Remove test database
 - 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? (Press y|Y for Yes, any other key for No) : Y << Reload tables
Success.

All done!
MySQL utiliza el mecanismo de autenticación Unix Socket para el usuario root de MySQL cuando se instala desde el repositorio de Ubuntu. Este mecanismo de autenticación permite que el usuario root de MySQL inicie sesión solo desde el socket de Unix (#prompt o sudo).

Para deshabilitar la autenticación de Unix Socket y habilitar el mecanismo de contraseña nativo, siga los pasos a continuación.

Inicie sesión como usuario raíz de MariaDB.

sudo mysql -u root -p

No se requiere contraseña

use mysql;

update user set plugin='mysql_native_password' where user='root';

flush privileges;

quit;

Pila LAMP de prueba

La raíz del documento predeterminada de Apache es /var/www/html y el archivo de configuración principal es /etc/apache2/apache2.conf . Puede encontrar configuraciones adicionales como hosts virtuales y módulos en /etc/apache2/*-enabled directorio.

Para probar el PHP, colocaremos un archivo PHP en la raíz del documento predeterminado de Apache.

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Ahora abra un navegador web y escriba lo siguiente en la dirección web para acceder a la página de prueba:

http://ip.ad.dr.ess/info.php

La página se verá como la siguiente.

Desplácese por la página hacia abajo para ver los detalles de las extensiones de PHP para MySQL/MariaDB.

Conclusión

Eso es todo. Espero que, a estas alturas, tenga la pila LAMP en Ubuntu 20.04. Comparta sus comentarios en la sección de comentarios.


Ubuntu
  1. Cómo instalar la pila LAMP en Ubuntu 18.04

  2. Cómo instalar WordPress en Ubuntu 18.04 usando LAMP Stack

  3. Cómo instalar la pila Linux, Apache, MySQL, PHP (LAMP) en Ubuntu 16.04

  4. Instale WordPress con LAMP Stack en Ubuntu 20.04

  5. Cómo instalar y configurar PHP y Apache (pila LAMP) en Ubuntu 20.04

Cómo instalar LAMP Stack (Apache, MariaDB, PHP7.1) en Ubuntu 17.10

Cómo instalar LAMP Stack en servidor/escritorio Ubuntu 20.04

Cómo instalar Apache, MySQL, PHP (pila LAMP) en Ubuntu

Cómo instalar la pila LAMP en Ubuntu 20.04

Cómo instalar una pila LAMP (Apache, MariaDB, PHP) en CentOS 7

Cómo instalar la pila Apache, MySQL, PHP (LAMP) en Ubuntu 16.04