Servidor LAMP · 6 min read · Sep 26, 2025
Como Instalar o LAMP Server Stack no Ubuntu 22.04

LAMP é uma plataforma de desenvolvimento web gratuita, de código aberto e uma das mais populares, permitindo que desenvolvedores web construam, implantem e gerenciem sites e aplicações online. Ele utiliza quatro componentes de código aberto: Linux como sistema operacional, Apache como servidor web, MySQL como sistema de gerenciamento de banco de dados relacional e PHP/Perl/Python como linguagem de script orientada a objetos. O stack LAMP é a escolha primária de todos os desenvolvedores web porque é suficiente para hospedar uma ampla variedade de frameworks de sites, como Joomla, Drupal e WordPress.
Recursos
- Um servidor LAMP é gratuito e de código aberto, então qualquer um pode baixar seu código-fonte, fazer alterações e melhorias, aumentando seu desempenho geral.
- É personalizável. Assim, você pode substituir cada componente por outra solução de código aberto para atender às necessidades específicas da aplicação.
- Tem uma comunidade maior, então você pode encontrar suporte facilmente.
- É um stack maduro que é fácil de configurar.
Este post mostrará como instalar o servidor LAMP no Ubuntu 22.04.
Pré-requisitos
- Um servidor rodando Ubuntu 22.04.
- Mínimo de 1 GB de RAM e 5 GB de espaço em disco rígido.
- Uma senha de root configurada no servidor.
Instalar Apache no Ubuntu 22.04
O servidor web Apache é um componente principal do stack LAMP. Por padrão, o pacote do servidor web Apache está incluído no repositório padrão do Ubuntu 22.04. Você pode instalá-lo facilmente executando o seguinte comando:
apt-get install apache2 -yUma vez que o servidor Apache esteja instalado, inicie e habilite o serviço web Apache usando o seguinte comando:
systemctl start apache2
systemctl enable apache2Agora você pode verificar o status do serviço Apache usando o seguinte comando:
systemctl status apache2Você receberá o status do Apache na seguinte saída:
? apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-04-29 07:27:44 UTC; 4s ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 923 (apache2)
Tasks: 55 (limit: 4630)
Memory: 5.1M
CPU: 56ms
CGroup: /system.slice/apache2.service
??923 /usr/sbin/apache2 -k start
??924 /usr/sbin/apache2 -k start
??925 /usr/sbin/apache2 -k start
Apr 29 07:27:44 ubuntu systemd[1]: Starting The Apache HTTP Server...
Para verificar a versão do Apache, execute o seguinte comando:
apache2ctl -versionVocê verá a versão do Apache na seguinte saída:
Server version: Apache/2.4.52 (Ubuntu)
Server built: 2022-03-25T00:35:40
Você também pode testar a instalação do Apache através do navegador web usando a URL http://your-server-ip. Você deve ver a página de teste do Apache na seguinte tela:

Uma vez que você tenha terminado, pode prosseguir para instalar o PHP.
Instalar PHP no Ubuntu 22.04
PHP é uma linguagem de processamento usada para servir as páginas PHP. Por padrão, o Ubuntu 22.04 fornece a versão mais recente do PHP 8.1. Você pode instalá-la com outras extensões na seguinte saída:
apt-get install php8.1 libapache2-mod-php8.1 php8.1-mysql php8.1-gd php8.1-curl php8.1-xml -yUma vez que o PHP esteja instalado, você pode verificar a versão do PHP usando o seguinte comando:
php --versionVocê deve ver a versão do PHP na seguinte saída:
PHP 8.1.2 (cli) (built: Apr 7 2022 17:46:26) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies
Uma vez que você tenha terminado, pode prosseguir para instalar o servidor MySQL.
Instalar o Servidor MySQL no Ubuntu 22.04
Por padrão, a versão mais recente do MySQL está incluída no repositório padrão do Ubuntu 22.04. Você pode instalá-la usando o seguinte comando:
apt-get install mysql-server -yUma vez que o servidor MySQL esteja instalado, inicie o serviço MySQL e habilite-o para iniciar na reinicialização do sistema usando o seguinte comando:
systemctl start mysql
systemctl enable mysqlVocê pode verificar o status do MySQL usando o seguinte comando:
systemctl status mysqlVocê receberá a seguinte saída:
? mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-04-29 07:43:21 UTC; 3s ago
Process: 11468 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 11476 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 4630)
Memory: 358.2M
CPU: 991ms
CGroup: /system.slice/mysql.service
??11476 /usr/sbin/mysqld
Apr 29 07:43:20 ubuntu systemd[1]: Starting MySQL Community Server...
Apr 29 07:43:21 ubuntu systemd[1]: Started MySQL Community Server.
Você também pode verificar a versão do MySQL com o seguinte comando:
mysql --versionVocê receberá a seguinte saída:
mysql Ver 8.0.28-0ubuntu4 for Linux on x86_64 ((Ubuntu))
Por padrão, o MySQL não está seguro e a senha do root não está definida. Portanto, você precisará segurá-lo executando o seguinte script:
mysql_secure_installationDefina uma nova senha do MySQL conforme mostrado abaixo:
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:
Please set the password for root here.
New password:
Re-enter new password:
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.
Remova o usuário anônimo conforme mostrado abaixo:
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.
Desabilite o login remoto do root conforme mostrado abaixo:
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.
Remova o banco de dados de teste conforme mostrado abaixo:
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.
Recarregue os privilégios conforme mostrado abaixo:
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!
Verify PHP Installation
Após instalar o servidor LAMP, você precisará verificar se o Apache processa a página PHP ou não.
Para verificar, crie uma página PHP de exemplo:
nano /var/www/html/info.phpAdicione o seguinte código:
Salve e feche o arquivo, então abra seu navegador web e acesse a página PHP usando a URL http://your-server-ip/info.php. Você deve ver a página de informações do PHP na seguinte tela:

Conclusão
Parabéns! você instalou com sucesso o servidor LAMP no servidor Ubuntu 22.04. Agora você pode começar a criar e hospedar seu site usando o stack LAMP. Sinta-se à vontade para me perguntar se você tiver alguma dúvida.
Receba novas postagens na sua caixa de entrada
Sem spam. Cancele a assinatura a qualquer momento.