Instalação CraftCMS · 8 min read · Sep 26, 2025

Como Instalar CraftCMS com Apache e Let's Encrypt SSL no Ubuntu 22.04 LTS

Craft é um sistema de gerenciamento de conteúdo de código aberto, flexível e rico em recursos para desenvolvedores e autores de conteúdo. Ele oferece todos os recursos de personalização necessários para construir um site poderoso. Permite gerenciar o conteúdo de vários sites a partir de um único painel. É uma solução alternativa ao WordPress e Drupal para construir experiências digitais sob medida. Possui centenas de plugins gratuitos e pagos que permitem adicionar funcionalidade.

Este post explicará como instalar o Craft CMS com Apache e Let’s Encrypt SSL no Ubuntu 22.04.

Pré-requisitos

  • Um servidor rodando Ubuntu 22.04.
  • Nome de domínio válido apontado para o IP do seu servidor.
  • Uma senha de root configurada no servidor.

Instalar Servidor LAMP

O Craft CMS roda no servidor web, é escrito em PHP e usa MariaDB como backend de banco de dados. Portanto, você precisará instalar todos esses pacotes no seu servidor.

Você pode executar o seguinte comando para instalar todos esses pacotes:

apt-get install apache2 mariadb-server php php-cli libapache2-mod-php php-common php-json php-curl php-gd php-imagick php-json php-mbstring php-mysql php-pgsql php-zip php-intl php-xml -y

Após instalar todos os pacotes, edite o arquivo de configuração do PHP e altere as configurações padrão:

nano /etc/php/8.1/php.ini

Altere as seguintes configurações:

memory_limit = 512M
post_max_size = 32M
upload_max_filesize = 32M
max_execution_time = 360

Salve e feche o arquivo, então reinicie o serviço Apache para aplicar as mudanças:

systemctl restart apache2

Criar um Banco de Dados para CraftCMS

Em seguida, você precisará criar um banco de dados e um usuário para o Fork CMS. Primeiro, faça login no shell do MariaDB com o seguinte comando:

mysql

Uma vez logado, crie um banco de dados e um usuário com o seguinte comando:

MariaDB [(none)]> CREATE DATABASE craftcms;  
MariaDB [(none)]> GRANT ALL ON craftcms.* TO 'craftuser' IDENTIFIED BY 'password';

Em seguida, limpe os privilégios e saia do shell do MariaDB com o seguinte comando:

MariaDB [(none)]> FLUSH PRIVILEGES;  
MariaDB [(none)]> EXIT;

Neste ponto, o banco de dados MariaDB foi criado para o Craft CMS. Você pode agora prosseguir para a próxima etapa.

Instalar Craft CMS Usando o Composer

Em seguida, você precisará instalar o Composer para baixar a versão mais recente do Craft CMS. Você pode instalá-lo usando o seguinte comando:

curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

Uma vez que o Composer esteja instalado, navegue até o diretório raiz da web do Apache e crie um projeto Craft CMS usando o seguinte comando:

cd /var/www/html  
composer create-project craftcms/craft craftcms

Você será solicitado a fornecer suas configurações de banco de dados, nome de usuário do administrador, senha, URL do site, conforme mostrado abaixo:

Which database driver are you using? (mysql or pgsql) [mysql] 
Database server name or IP address: [127.0.0.1] 
Database port: [3306] 
Database username: [root] craftuser
Database password: 
Database name: craft
Database table prefix: 
Testing database credentials ... success!
Saving database credentials to your .env file ... done

Install Craft now? (yes|no) [yes]:yes

Username: [admin] admin
Email: [email protected]
Password: 
Confirm: 
Site name: CraftCMS Site
Site URL: http://craftcms.example.com
Site language: [en-US] 

    > add foreign key fk_rlbmgnhpxsljkaunjwnsezfrnrkhwzpthfsq: {{%widgets}} (userId) references {{%users}} (id) ... done (time: 0.035s)
    > populating the info table ... done
    > saving default site data ... done
    > saving the first user ... done
*** installed Craft successfully (time: 5.449s)

Em seguida, defina as permissões e a propriedade corretas para o diretório do Craft CMS:

chown -R www-data:www-data /var/www/html/craftcms/  
chmod -R 755 /var/www/html/craftcms/

Uma vez que você tenha terminado, pode prosseguir para a próxima etapa.

Configurar o Apache para Craft CMS

Em seguida, você precisará criar um arquivo de configuração de host virtual do Apache para o Craft CMS. Você pode criá-lo com o seguinte comando:

nano /etc/apache2/sites-available/craftcms.conf

Adicione as seguintes linhas:


     ServerAdmin [email protected]
     DocumentRoot /var/www/html/craftcms/web
     ServerName craftcms.example.com


     
          Options FollowSymlinks
          AllowOverride All
          Require all granted
     

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
    
     
            RewriteEngine on
            RewriteBase /
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*) index.php [PT,L]
    

Salve e feche o arquivo, então ative o host virtual do Apache e o módulo de reescrita usando o seguinte comando:

a2ensite craftcms.conf  
a2enmod rewrite

Em seguida, reinicie o serviço Apache para aplicar as mudanças:

systemctl restart apache2

Você também pode verificar o status do Apache com o seguinte comando:

systemctl status apache2

Você receberá a 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-06-17 15:48:11 UTC; 31min ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 37935 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
    Process: 40916 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
   Main PID: 37939 (apache2)
      Tasks: 6 (limit: 2292)
     Memory: 53.0M
        CPU: 28.718s
     CGroup: /system.slice/apache2.service
             ??37939 /usr/sbin/apache2 -k start
             ??40920 /usr/sbin/apache2 -k start
             ??40921 /usr/sbin/apache2 -k start
             ??40922 /usr/sbin/apache2 -k start
             ??40923 /usr/sbin/apache2 -k start
             ??40924 /usr/sbin/apache2 -k start

Jun 17 15:48:11 ubuntu2204 systemd[1]: Starting The Apache HTTP Server...

Uma vez que seu servidor web Apache esteja configurado, você pode prosseguir para a próxima etapa.

Acessar a Interface Web do Craft CMS

Agora, abra seu navegador e digite a URL http://craftcms.example.com para acessar a interface web do Craft CMS. Você deve ver a seguinte página:

Clique em ir para o seu painel de controle. Você será redirecionado para a página de login do Craft CMS:

Forneça seu nome de usuário de administrador, senha e clique no botão login. Você deve ver o painel do Craft CMS na seguinte página:

Proteger o Craft CMS com Let’s Encrypt SSL

Em seguida, é uma boa ideia proteger seu site com Let’s Encrypt SSL. Primeiro, instale o pacote do cliente Certbot com o seguinte comando:

apt-get install python3-certbot-apache -y

Após a instalação bem-sucedida, execute o seguinte comando para proteger seu site com Let’s Encrypt SSL:

certbot --apache -d craftcms.example.com

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

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
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
Plugins selected: Authenticator apache, Installer apache
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for craftcms.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/craftcms-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/craftcms-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/craftcms-le-ssl.conf

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

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 instalar o Let’s Encrypt SSL para seu site:

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/craftcms.conf to ssl vhost in /etc/apache2/sites-available/craftcms-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://craftcms.example.com

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/craftcms.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/craftcms.example.com/privkey.pem
   Your cert will expire on 2022-09-17. 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"
 - 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

Conclusão

Parabéns! você instalou com sucesso o Craft CMS com Apache e Let’s Encrypt SSL no Ubuntu 22.04. Agora você pode explorar os recursos do CraftCMS e começar a criar um site poderoso usando o Craft CMS. Sinta-se à vontade para 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.