Cum se instalează LAMP pe Ubuntu 22.04

Configurare noua (How To)

Situatie

O stivă LAMP este o formă scurtă de Linux, Apache, MySQL și PHP. În aceasta, L înseamnă sistem de operare Linux, A pentru server web Apache, M este pentru baza de date MySQL, P pentru limbajul de programare PHP. Acest ghid vă va ajuta să instalați Apache, MySQL și PHP (LAMP) pe sistemul Ubuntu 22.04 LTS (Jammy Jelllyfish).

Solutie

Pasi de urmat

În primul rând, actualizați pachetele actuale la cea mai recentă versiune
sudo apt update
sudo apt upgrade

Instalarea Apache este un proces destul de simplu. Vom instala Apache din depozitele implicite Ubuntu folosind managerul de pachete apt. În distribuțiile bazate pe Debian, pachetul Apache și serviciul se numesc apache2.
sudo apt install apache2

MySQL este un sistem popular de gestionare a bazelor de date utilizat în mediile PHP. Arhivele implicite Ubuntu includ serverul MySQL 8.0. Utilizați următoarea comandă pentru a o instala.
sudo apt install mysql-server
Odată ce instalarea este finalizată, se recomandă să rulați un script de securitate care vine preinstalat cu MySQL. Acest script va elimina unele setări implicite nesigure și va bloca accesul la sistemul dumneavoastră de baze de date. Rulați comanda de mai jos:
sudo mysql_secure_installation

Vi se vor solicita câteva întrebări, după cum este prezentat mai jos, selectați opțiunile corespunzătoare:
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

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
Please set the password for root here.

New password:

Re-enter new 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
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
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
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
– 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
Success.

În acest moment, ați instalat Apache și MySQL. Acum avem nevoie de PHP pentru a procesa codul pentru a afișa conținut dinamic utilizatorului. Pachetele PHP 8.2 sunt disponibile în depozitele implicite de pe Ubuntu 22.04 LTS. Pentru a instala PHP pe sistemul dvs., actualizați apt index și apoi instalați-l pe sistemul dvs. De asemenea, a fost necesar să instalați libapache2-mod-php pentru a permite Apache să gestioneze fișierele PHP.
sudo apt update
sudo apt install php libapache2-mod-php php-mysql

După instalarea Apache, asigurați-vă că firewall-ul permite traficul HTTP și HTTPS. Puteți obține o listă cu lista de profiluri ufw tastând:
sudo ufw app list

Available applications:
Apache
Apache Full
Apache Secure
OpenSSH

Permite traficul HTTP și HTTPS de intrare pentru acest profil:
sudo ufw allow in "Apache Full"

Acum am finalizat pașii de instalare a LAMPĂ. Vom vedea câteva comenzi de management de bază.

Pentru a opri serviciul Apache și MySQL, puteți rula:
sudo systemctl stop apache2
sudo systemctl stop mysql
Puteți porni din nou serviciul după tipul:
sudo systemctl start apache2
sudo systemctl start mysql
Pentru a face Reporniți (opriți și porniți) serviciul Apache:
sudo systemctl restart apache2
sudo systemctl restart mysql

Tip solutie

Permanent

Voteaza

(10 din 17 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?