Craft CMS is an open-source content management system for creating all sorts of websites. It is a secure and scalable CMS with an extensive plugin ecosystem and high-quality free and paid plugins. It has an intuitive, user-friendly control panel for content creation and administrative tasks. It is built on the Yii PHP framework. The Twig template engine powers its templating system. It can work with both MySQL and PostgreSQL databases for storage and uses the Redis database for caching and session storage.
In this tutorial, you will learn how to install Craft CMS on a Debian 12 server. You will also learn how to enable Redis to work with it and how to back up and restore a site made using Craft CMS.
Prerequisites
A server running Debian 12 with a minimum of 1 GB of RAM.
A non-root user with sudo privileges.
Uncomplicated Firewall(UFW) is enabled and running.
A Fully Qualified Domain Name (FQDN) like
craftcms.example.com
pointing to your server.An SMTP account with an email service like Amazon SES or Mailgun.
Everything is updated.
$ sudo apt update && sudo apt upgrade
A few essential packages are required for the tutorial and Craft CMS to run. Some of these will already be on your server.
$ sudo apt install curl wget nano software-properties-common dirmngr apt-transport-https ca-certificates lsb-release debian-archive-keyring gnupg2 ufw unzip -y
Step 1 – Configure Firewall
The first step before installing any packages is to configure the firewall to allow HTTP and HTTPS connections.
Check the status of the firewall.
$ sudo ufw status
You should see something like the following.
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Allow HTTP and HTTPs ports.
$ sudo ufw allow http
$ sudo ufw allow https
Check the status again to confirm.
$ sudo ufw status
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
80/tcp ALLOW Anywhere
443/tcp ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
443/tcp (v6) ALLOW Anywhere (v6)
Step 2 – Install Nginx
Debian 12 ships with an older version of Nginx. You need to download the official Nginx repository to install the latest version.
Import Nginx’s signing key.
$ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
Add the repository for Nginx’s stable version.
$ echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/debian `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
Update the system repositories.
$ sudo apt update
Install Nginx.
$ sudo apt install nginx
Verify the installation. On Debian systems, the following command will only work with sudo
.
$ sudo nginx -v
nginx version: nginx/1.24.0
Start the Nginx server.
$ sudo systemctl start nginx
Check the service status.
$ sudo systemctl status nginx
? nginx.service - nginx - high performance web server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running) since Fri 2023-12-01 09:46:46 UTC; 18s ago
Docs: https://nginx.org/en/docs/
Process: 39483 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 39484 (nginx)
Tasks: 2 (limit: 2315)
Memory: 1.7M
CPU: 6ms
CGroup: /system.slice/nginx.service
??39484 "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf"
??39485 "nginx: worker process"
Step 3 – Install PHP and extensions
Debian 12 ships with PHP 8.2 by default. You can install it and the extensions required by Craft CMS by running the following command.
$ sudo apt install php php-cli php-common php-json php-gmp php-fpm php-xmlrpc php-bcmath php-imagick php-curl php-zip php-gd php-mysql php-xml php-mbstring php-xmlrpc php-intl php-pgsql
To always stay on the latest version of PHP or if you want to install multiple versions of PHP, add Ondrej’s PHP repository.
First, import Sury’s repo PHP GPG key.
$ sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
Add Ondrej Sury’s PHP repository.
$ sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
Update your system repository list.
$ sudo apt update
You will probably receive information about pending upgrades. Run them.
$ sudo apt upgrade
Install PHP and its extensions.
$ sudo apt install php8.2 php8.2-cli php8.2-common php8.2-gmp php8.2-fpm php8.2-xmlrpc php8.2-bcmath php8.2-imagick php8.2-curl php8.2-zip php8.2-gd php8.2-mysql php8.2-xml php8.2-mbstring php8.2-xmlrpc php8.2-intl php8.2-pgsql
Check the version of PHP installed.
$ php --version
PHP 8.2.13 (cli) (built: Nov 24 2023 13:10:42) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.13, Copyright (c) Zend Technologies
with Zend OPcache v8.2.13, Copyright (c), by Zend Technologies
Check the status of the PHP service.
$ sudo systemctl status php8.2-fpm
? php8.2-fpm.service - The PHP 8.2 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php8.2-fpm.service; enabled; preset: enabled)
Active: active (running) since Fri 2023-12-01 10:29:53 UTC; 34min ago
Docs: man:php-fpm8.2(8)
Process: 65825 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/8.2/fpm/pool.d/www.conf 82 (code=exited, status=0/SUCCESS)
Main PID: 65821 (php-fpm8.2)
Status: "Processes active: 0, idle: 3, Requests: 208, slow: 0, Traffic: 0.2req/sec"
Tasks: 4 (limit: 2315)
Memory: 83.4M
CPU: 6.456s
CGroup: /system.slice/php8.2-fpm.service
??65821 "php-fpm: master process (/etc/php/8.2/fpm/php-fpm.conf)"
??65823 "php-fpm: pool www"
??65824 "php-fpm: pool www"
??65843 "php-fpm: pool www"
Step 4 – Configure PHP-FPM
Open php.ini
for editing.
$ sudo nano /etc/php/8.2/fpm/php.ini
To set file upload sizes, change the values of the upload_max_filesize
and post_max_size
variables. This value decides the file size you can upload to Craft CMS. For our purposes, we are setting it at 128 MB. You can set it to your liking.
$ sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 128M/' /etc/php/8.2/fpm/php.ini
$ sudo sed -i 's/post_max_size = 8M/post_max_size = 128M/' /etc/php/8.2/fpm/php.ini
Configure PHP’s memory limit depending on your server resources and requirements.
$ sudo sed -i 's/memory_limit = 128M/memory_limit = 256M/' /etc/php/8.2/fpm/php.ini
Open the file /etc/php/8.2/fpm/pool.d/www.conf
.
$ sudo nano /etc/php/8.2/fpm/pool.d/www.conf
We need to set the Unix user/group of PHP processes to nginx. Find the user=www-data
and group=www-data
lines in the file and change them to nginx
.
...
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = nginx
group = nginx
...
Also, find the lines listen.owner=www-data
and listen.group=www-data
in the file and change them to nginx
.
listen.owner = nginx
listen.group = nginx
Save the file by pressing Ctrl + X and entering Y when prompted.
Restart the PHP-fpm process. Make sure you have Nginx installed before restarting the PHP service otherwise, it will fail since it won’t be able to find the nginx
group.
$ sudo systemctl restart php8.2-fpm
Step 5 – Install Composer
Composer acts as a dependency manager for PHP. It is also the dependency manager of the Laravel PHP framework, which is what powers Craft CMS.
Download the Composer installation script.
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
Verify the downloaded installer.
$ php -r "if (hash_file('sha384', 'composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
You will receive the following output.
Installer verified
Run the installation script to download the latest version of Composer.
$ php composer-setup.php
Remove the installation script.
$ php -r "unlink('composer-setup.php');"
Move the downloaded binary file to the /usr/local/bin
directory.
$ sudo mv composer.phar /usr/local/bin/composer
Confirm the installation.
$ composer --version
Composer version 2.6.5 2023-10-06 10:11:52
Step 6 – Install and Configure PostgreSQL
Debian 12 ships with PostgreSQL 15 by default. We will be using PostgreSQL 16 instead.
Run the following command to add the PostgreSQL GPG key.
$ curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /usr/share/keyrings/postgresql-key.gpg >/dev/null
Add the APT repository to your sources list.
$ sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/postgresql-key.gpg arch=amd64] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
Update the system repository.
$ sudo apt update
Now, you can install PostgreSQL using the command below.
$ sudo apt install postgresql postgresql-contrib
The postgresql-contrib
package contains some extra utilities.
Verify the version.
$ psql --version
psql (PostgreSQL) 16.1 (Debian 16.1-1.pgdg120+1)
Check the status of the PostgreSQL service.
$ sudo systemctl status postgresql
? postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; preset: enabled)
Active: active (exited) since Wed 2023-11-29 05:54:03 UTC; 11s ago
Main PID: 20170 (code=exited, status=0/SUCCESS)
CPU: 1ms
Nov 29 05:54:03 craftcms systemd[1]: Starting postgresql.service - PostgreSQL RDBMS...
Nov 29 05:54:03 craftcms systemd[1]: Finished postgresql.service - PostgreSQL RDBMS.
You can see that the service is enabled and running by default.
Launch the PostgreSQL shell.
$ sudo -i -u postgres psql
Create the Craft CMS database.
postgres=# CREATE DATABASE craftcms;
Create the Craft CMS user and choose a strong password.
postgres-# CREATE USER craftuser WITH PASSWORD 'Your_Password';
Change the database owner to the Craft CMS user.
postgres-# ALTER DATABASE craftcms OWNER TO craftuser;
Grant all privileges on the database to the Craft CMS user.
postgres-# GRANT ALL PRIVILEGES ON DATABASE craftcms TO craftuser;
Exit the shell.
postgres-# \q
Verify that your credentials work.
$ psql --username craftuser --password --host localhost craftcms
Password:
psql (16.1 (Debian 16.1-1.pgdg120+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.
craftcms=>
Exit the shell by typing \q
.
Step 7 – Install and Configure Redis
Debian 12 ships with Redis 7.0 by default which is what we will be using. Install Redis.
$ sudo apt install redis
Verify the version.
$ redis-server --version
Redis server v=7.0.11 sha=00000000:0 malloc=jemalloc-5.3.0 bits=64 build=c4e7f6bf175a885b
If however, you want to install the latest version, you can do so by using Redis’s official repository by issuing the following commands.
$ curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
$ echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
$ sudo apt update
$ sudo apt install redis
The next step is to add authentication to the Redis server. Since Redis v6.0, the best way to add authentication is to use ACL (Access Control Lists). Open the /etc/redis/redis.conf
file for editing.
$ sudo nano /etc/redis/redis.conf
Find the line # aclfile /etc/redis/users.acl
entry and uncomment it by removing the hash (#
) in front of it.
aclfile /etc/redis/users.acl
Save the file by pressing Ctrl + X and entering Y when prompted.
Next, create and open the /etc/redis/users.acl
file for editing.
$ sudo nano /etc/redis/users.acl
Add the following line to it.
user navjot on +@all ~* >yourpassword
Save the file by pressing Ctrl + X and entering Y when prompted.
Restart the Redis server to implement the change.
$ sudo systemctl restart redis
Open the Redis shell.
$ redis-cli
Use the PING
command. It will give an authentication error.
127.0.0.1:6379> PING
(error) NOAUTH Authentication required.
Use the AUTH
command to log in.
127.0.0.1:6379> AUTH navjot yourpassword
OK
Use the PING
command again.
127.0.0.1:6379> PING
OK
Exit the shell.
127.0.0.1:6379> exit
You will also need to install the PHP Redis extension.
$ sudo apt install php-redis
Step 8 – Install Craft CMS
Before installing Craft CMS, you can check if you meet all the server requirements for running it using the following command.
$ curl -Lsf https://raw.githubusercontent.com/craftcms/server-check/HEAD/check.sh | bash
You will get the following output.
Running Craft Server Check…
Craft CMS Requirement Checker
This script checks if your web server configuration meets the requirements for running a Craft CMS installation.
It checks if the server is running the right version of PHP, if appropriate PHP extensions have been loaded,
and if php.ini file settings are correct.
Results:
--------
PHP 8.2+: OK
BCMath extension: OK
ctype extension: OK
cURL extension: OK
DOM extension: OK
Fileinfo extension: OK
GD extension or ImageMagick extension: OK
iconv extension: OK
Intl extension: OK
JSON extension: OK
Multibyte String extension (with Function Overloading disabled): OK
OPcache extension (with save_comments): OK
OpenSSL extension: OK
PCRE extension (with UTF-8 support): OK
PDO extension: OK
Reflection extension: OK
SPL extension: OK
Zip extension: OK
ignore_user_abort(): OK
password_hash(): OK
proc_close(): OK
proc_get_status(): OK
proc_open(): OK
proc_terminate(): OK
allow_url_fopen: OK
ini_set calls: OK
Memory Limit: OK
------------------------------------------
Errors: 0 Warnings: 0 Total checks: 27
Once everything is okay, you can proceed. Create the web root directory.
$ sudo mkdir /var/www/html/craftcms -p
Set the currently logged-in user as the owner of this directory.
$ sudo chown -R $USER:$USER /var/www/html/craftcms
Switch to the directory.
$ cd /var/www/html/craftcms
Download and Install Craft CMS using Composer. The dot (.
) at the end of the command means that the installation should be performed in the current directory.
$ composer create-project craftcms/craft .
During installation, you will be asked for several details regarding the database, and administrator account. site URL and its language as shown below.
> @php craft setup/welcome
______ .______ ___ _______ .___________.
/ || _ \ / \ | ____|| |
| ,----'| |_) | / ^ \ | |__ `---| |----`
| | | / / /_\ \ | __| | |
| `----.| |\ \----./ _____ \ | | | |
\______|| _| `._____/__/ \__\ |__| |__|
A N E W I N S T A L L
______ .___ ___. _______.
/ || \/ "https://www.howtoforge.com/"
| ,----'| \ / | | (----`
| | | |\/| | \ \
| `----.| | | | .----) |
\______||__| |__| |_______/
Generating an application ID ... done (CraftCMS--923f03f1-9bea-4c3d-a7ca-1466645ce75d)
Generating a security key ... done (iMdcUi6wQyf9MshEda__vZcCwILbclxz)
Welcome to Craft CMS!
Are you ready to begin the setup? (yes|no) [no]:yes
Which database driver are you using? (mysql or pgsql) [mysql] pgsql
Database server name or IP address: [127.0.0.1]
Database port: [5432]
Database username: [root] craftuser
Database password:
Database name: craftcms
Database table prefix:
Testing database credentials ... success!
Using default schema "public".
Saving database credentials to your .env file ... done
Install Craft now? (yes|no) [yes]:yes
Username: [admin] navjot
Email: [email protected]
Password:
Confirm:
Site name: Howtoforge Tutorials
Site URL: https://craftcms.example.com
Site language: [en-US]
*** installing Craft
Make Redis work with Craft CMS
Install the yiisoft/yii2-redis
package.
$ composer require --prefer-dist yiisoft/yii2-redis:"~2.0.0"
Open the /var/www/html/craftcms/config/app.php
file for editing.
$ nano config/app.php
You will see the following content in it.
use craft\helpers\App;
return [
'id' => App::env('CRAFT_APP_ID') ?: 'CraftCMS',
];
Change it as follows.
use craft\helpers\App;
return [
'id' => App::env('CRAFT_APP_ID') ?: 'CraftCMS',
'components' => [
'cache' => function() {
$config = [
'class' => yii\redis\Cache::class,
'keyPrefix' => Craft::$app->id,
'defaultDuration' => Craft::$app->config->general->cacheDuration,
// Full Redis connection details:
'redis' => [
'hostname' => App::env('REDIS_HOSTNAME') ?: 'localhost',
'port' => 6379,
'username' => App::env('REDIS_USERNAME') ?: null,
'password' => App::env('REDIS_PASSWORD') ?: null,
],
];
return Craft::createObject($config);
},
],
];
Save the file by pressing Ctrl + X and entering Y when prompted. This enables Redis as cache storage for Craft CMS. You can also use Redis for storing PHP session data, job queue, and as a mutex driver. You can find the configuration for it in Craft CMS’s documentation.
You also need to add the Redis configuration to the .env
file.
$ nano .env
Add the following code at the end of the file.
REDIS_HOSTNAME=localhost
REDIS_USERNAME=navjot
REDIS_PASSWORD=yourpassword
Choose the options as shown above. Once finished, change the group of the directory to nginx
. This way both the currently logged-in user and Nginx will have access to Craft CMS.
$ sudo chgrp -R nginx /var/www/html/craftcms
Give nginx
group permission to write to the directory.
$ sudo chmod -R g+w /var/www/html/craftcms
From here on, you won’t need to change permissions again and can do all the operations without using root privileges.
Step 9 – Install SSL
We need to install Certbot to generate the SSL certificate. You can either install Certbot using Debian’s repository or grab the latest version using the Snapd tool. We will be using the Snapd version.
Debian 12 comes doesn’t come with Snapd installed. Install Snapd package.
$ sudo apt install snapd
Run the following commands to ensure that your version of Snapd is up to date.
$ sudo snap install core && sudo snap refresh core
Install Certbot.
$ sudo snap install --classic certbot
Use the following command to ensure that the Certbot command can be run by creating a symbolic link to the /usr/bin
directory.
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot
Verify if Certbot is functioning correctly.
$ certbot --version
certbot 2.7.4
Run the following command to generate an SSL Certificate.
$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [email protected] -d craftcms.example.com
The above command will download a certificate to the /etc/letsencrypt/live/craftcms.example.com
directory on your server.
Generate a Diffie-Hellman group certificate.
$ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096
Check the Certbot renewal scheduler service.
$ sudo systemctl list-timers
You will find snap.certbot.renew.service
as one of the services scheduled to run.
NEXT LEFT LAST PASSED UNIT ACTIVATES
---------------------------------------------------------------------------------------------------------------------------
Fri 2023-12-01 10:39:00 UTC 12min left Fri 2023-12-01 10:09:01 UTC 17min ago phpsessionclean.timer phpsessionclean.service
Fri 2023-12-01 17:01:47 UTC 6h left Thu 2023-11-30 17:01:47 UTC 17h ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Fri 2023-12-01 18:34:00 UTC 8h left - - snap.certbot.renew.timer snap.certbot.renew.service
Do a dry run of the process to check whether the SSL renewal is working fine.
$ sudo certbot renew --dry-run
If you see no errors, you are all set. Your certificate will renew automatically.
Step 10 – Configure Nginx
Open the file /etc/nginx/nginx.conf
for editing.
$ sudo nano /etc/nginx/nginx.conf
Add the following line before the line include /etc/nginx/conf.d/*.conf;
.
server_names_hash_bucket_size 64;
Save the file by pressing Ctrl + X and entering Y when prompted.
Create and open the file /etc/nginx/conf.d/craftcms.conf
for editing.
$ sudo nano /etc/nginx/conf.d/craftcms.conf
Paste the following code in it. Replace craftcms.example.com
with your domain name. Make sure the value of the client_max_body_size
is set to 128MB which is what we set for Craft CMS while configuring PHP earlier.
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name craftcms.example.com;
root /var/www/html/craftcms/web;
index index.php;
client_max_body_size 128M;
access_log /var/log/nginx/craftcms.access.log;
error_log /var/log/nginx/craftcms.error.log;
ssl_certificate /etc/letsencrypt/live/craftcms.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/craftcms.example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/craftcms.example.com/chain.pem;
ssl_session_timeout 5m;
ssl_session_cache shared:MozSSL:10m;
ssl_session_tickets off;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
ssl_stapling on;
ssl_stapling_verify on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
location / {
try_files $uri/index.html $uri $uri/ /index.php?$query_string;
}
location ~ [^/]\.php(/|$) {
try_files $uri $uri/ /index.php?$query_string;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_keep_conn on;
include fastcgi_params;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTP_PROXY "";
}
}
# enforce HTTPS
server {
listen 80;
listen [::]:80;
server_name craftcms.example.com;
return 301 https://$host$request_uri;
}
Save the file by pressing Ctrl + X and entering Y when prompted.
Verify your Nginx configuration.
$ sudo nginx -t
Restart the Nginx server.
$ sudo systemctl restart nginx
Step 11 – Access Craft CMS
Open the URL https://craftcms.example.com
in your browser and you will be taken to the following page.
To access the administration page, visit the URL https://craftcms.example.com/admin
and you will be taken to the login page.
Enter your administration credentials and click the Sign in key to log in. You will be taken to the following dashboard.
You can now start using Craft CMS to build your website.
Step 12 – Backup and Restore Craft CMS
You can back up Craft CMS’s database from inside the admin panel by visiting Admin Dashboard >> Utilities >> Database Backup.
Click the Backup button to download your database backup. You can also create the backup using the terminal. Run the following command to create the backup. Enter your password when prompted.
$ mysqldump -u craftcmsuser -p craftcms > ~/craftcms.database.sql
You can also create the database backup using the Craft CMS command-line utility. The advantage of this utility is that you don’t need to pass your database credentials. Read more about the Craft CMS command console utility here.
$ cd /var/www/html/craftcms
$ php craft db/backup ~/
Backing up the database ... done
Backup file: /home/navjot/howtoforge-tutorials--2023-12-03-065138--v4.5.11.1.sql (200.019 KB)
If you don’t specify any location in the above command, the backup file will be written to the /var/www/html/craftcms/storage/backups
directory.
To backup the files, just copy and save the entire /var/www/html/craftcms
folder.
$ cd /var/www/html
$ tar -zcf ~/craftcms.tar.gz craftcms
To restore it on a new server, extract the files to the /var/www/html
folder.
$ tar -xzf craftcms.tar.gz -C /var/www/html/
Create a database with the same credentials on the new server and restore the database using the following command. Enter your password when prompted.
$ mysqlimport -u craftcmsuser -p craftcms craftcms.database.sql
Step 13 – Update Craft CMS
There are two ways to update Craft CMS. One is from inside the administration panel. When an update is available, you will receive a notice. Click on the notice to upgrade. Craft CMS will automatically backup the database before performing an update.
You can also update it via the terminal.
To check all the available updates, run the following command.
$ cd /var/www/html/craftcms/
$ php craft update
If an update is available, run the following command to apply it.
$ php craft update all
Conclusion
This concludes our tutorial where you learned how to install Craft CMS software on a Debian 12 server. If you have any questions, post them in the comments below.