Instalação Laravel · 9 min read · Nov 01, 2025

Como Instalar o Framework PHP Laravel com Nginx e SSL Gratuito Let's Encrypt no AlmaLinux 8

Laravel é um framework web PHP gratuito, de código aberto e leve, usado para construir aplicações web baseadas em PHP. É popular devido à sua sintaxe elegante, recursos avançados e conjunto de ferramentas robusto. É baseado no framework Symfony e ajuda os desenvolvedores a simplificar o desenvolvimento de aplicações web. Também fornece uma interface de linha de comando Artisan para realizar operações para suas aplicações. Oferece recursos poderosos, incluindo Artisan, Arquitetura MVC, Mapeamento objeto-relacional, Motor de Template, Testes de Unidade e Sistema de Migração de Banco de Dados.

Neste post, mostraremos como instalar o Laravel com Nginx no Alma Linux 8.

Pré-requisitos

  • Um servidor rodando Alma Linux 8.
  • Um nome de domínio válido apontado para o IP do seu servidor.
  • Uma senha de root configurada no seu servidor.

Instalar Servidor LEMP

Primeiro, você precisará instalar o Nginx, MariaDB, PHP e outras extensões PHP necessárias no seu servidor. Você pode instalar todos eles executando o seguinte comando:

dnf install nginx mariadb-server php php-fpm php-common php-xml php-mbstring php-json php-zip php-mysqlnd curl unzip -y

Após instalar todos os pacotes, edite o arquivo de configuração do php-fpm e configure-o para usar o Nginx:

nano /etc/php-fpm.d/www.conf

Altere as seguintes linhas:

listen.owner = nginx
listen.group = nginx

Salve e feche o arquivo, então edite o arquivo de configuração do PHP e altere os valores padrão:

nano /etc/php.ini

Altere as seguintes linhas:

date.timezone = Asia/Kolkata
cgi.fix_pathinfo=1

Salve e feche o arquivo, então inicie e habilite os serviços Nginx, MariaDB e PHP-FPM usando o seguinte comando:

systemctl start nginx  
systemctl start mariadb  
systemctl start php-fpm  
systemctl enable nginx  
systemctl enable mariadb  
systemctl enable php-fpm

Uma vez que você tenha terminado, você pode prosseguir para o próximo passo.

Instalar Composer

Neste post, instalaremos o Laravel usando o Composer. Portanto, você precisará instalar o Composer no seu sistema. Você pode instalá-lo executando o seguinte comando:

curl -sS https://getcomposer.org/installer | php

Você receberá a seguinte saída:

All settings correct for using Composer
Downloading...

Composer (version 2.2.3) successfully installed to: /root/composer.phar
Use it: php composer.phar

Em seguida, mova o binário do Composer para o caminho do sistema e defina as permissões adequadas com o seguinte comando:

mv composer.phar /usr/local/bin/composer  
chmod +x /usr/local/bin/composer

Em seguida, verifique a versão do Composer com o seguinte comando:

composer --version

Você receberá a seguinte saída:

Composer version 2.2.3 2021-12-31 12:18:53

Instalar Laravel no Alma Linux 8

Em seguida, mude o diretório para o diretório raiz da web do Nginx e instale o Laravel usando o Composer:

cd /var/www/html/  
composer create-project --prefer-dist laravel/laravel laravel

Você receberá a seguinte saída:

Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
69 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan key:generate --ansi
Application key set successfully.

Em seguida, defina a propriedade e as permissões adequadas para o Laravel:

chown -R nginx:nginx /var/www/html/laravel/  
chown -R nginx:nginx /var/www/html/laravel/storage/  
chown -R nginx:nginx /var/www/html/laravel/bootstrap/cache/  
chmod -R 0777 /var/www/html/laravel/storage/  
chmod -R 0775 /var/www/html/laravel/bootstrap/cache/

Uma vez que você tenha terminado, você pode prosseguir para o próximo passo.

Criar um Host Virtual Nginx para Laravel

Em seguida, você precisará criar um arquivo de configuração Nginx para o Laravel. Você pode criá-lo usando o seguinte comando:

nano /etc/nginx/conf.d/laravel.conf

Adicione as seguintes linhas:

server {
       listen 80;
       server_name laravel.exampledomain.com;
       root        /var/www/html/laravel/public;
       index       index.php;
       charset utf-8;
       gzip on;
    gzip_types text/css application/javascript text/javascript application/x-javascript  image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
        location / {
         try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php {
                include fastcgi.conf;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/run/php-fpm/www.sock;
        }
        location ~ \.ht {
                deny all;
        }
}

Salve e feche o arquivo, então verifique o Laravel para qualquer erro de configuração:

ginx -t

Você deve receber a seguinte saída:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Em seguida, reinicie os serviços Nginx e PHP-FPM para aplicar as alterações:

systemctl restart php-fpm  
systemctl restart nginx

Você também pode verificar o status do Nginx usando o seguinte comando:

systemctl status nginx

Você receberá a seguinte saída:

? nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/nginx.service.d
           ??php-fpm.conf
   Active: active (running) since Fri 2022-01-07 08:29:11 UTC; 4s ago
  Process: 8186 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 8184 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 8182 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 8188 (nginx)
    Tasks: 2 (limit: 11411)
   Memory: 3.7M
   CGroup: /system.slice/nginx.service
           ??8188 nginx: master process /usr/sbin/nginx
           ??8189 nginx: worker process

Jan 07 08:29:11 linux systemd[1]: nginx.service: Succeeded.
Jan 07 08:29:11 linux systemd[1]: Stopped The nginx HTTP and reverse proxy server.
Jan 07 08:29:11 linux systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 07 08:29:11 linux nginx[8184]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 07 08:29:11 linux nginx[8184]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 07 08:29:11 linux systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Jan 07 08:29:11 linux systemd[1]: Started The nginx HTTP and reverse proxy server.

Configurar Firewall Para Laravel

Em seguida, você precisará permitir as portas 80 e 443 através do firewall firewalld. Você pode permiti-las com o seguinte comando:

firewall-cmd --zone=public --permanent --add-service=http  
firewall-cmd --zone=public --permanent --add-service=https

Em seguida, recarregue o firewalld para aplicar as alterações:

firewall-cmd --reload

Acessar a Interface Web do Laravel

Agora, abra seu navegador e acesse a interface web do Laravel usando a URL http://laravel.exampledomain.com. Você deve ver a página padrão do Laravel na tela a seguir:

Laravel

Habilitar SSL no Site Laravel

É recomendável habilitar o SSL no site Laravel para proteger a conexão. O Let’s Encrypt fornece um SSL gratuito para obter, renovar e gerenciar certificados SSL/TLS para seu domínio. Primeiro, instale o cliente Certbot com o seguinte comando:

dnf install epel-release -y  
dnf install certbot -y

Em seguida, execute o seguinte comando para baixar o SSL do Let’s Encrypt para seu domínio Laravel:

certbot --nginx -d laravel.exampledomain.com

Você será solicitado a fornecer seu e-mail válido e aceitar os termos de serviço, conforme mostrado abaixo:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for laravel.exampledomain.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/laravel.conf

Em seguida, selecione se deseja ou não redirecionar o tráfego HTTP para HTTPS:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Digite 2 e pressione enter para iniciar o processo. Uma vez que o certificado tenha sido instalado, você deve ver a seguinte saída:

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/laravel.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://laravel.exampledomain.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=laravel.exampledomain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/laravel.exampledomain.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/laravel.exampledomain.com/privkey.pem
   Your cert will expire on 2022-04-11. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all*
   of your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

Neste ponto, seu site Laravel está protegido com SSL do Let’s Encrypt. Você pode agora acessá-lo com segurança usando a URL https://laravel.exampledomain.com.

Conclusão

Parabéns! você instalou com sucesso o Laravel com Nginx e SSL do Let’s Encrypt no Alma Linux 8. você pode agora começar a desenvolver aplicações baseadas em PHP usando o framework Laravel. Sinta-se à vontade para me perguntar se você tiver alguma dúvida.

Share: X/Twitter LinkedIn

Receba novas postagens na sua caixa de entrada

Sem spam. Cancele a assinatura a qualquer momento.