Craft CMS is a versatile and extensible content management system that allows you to create custom digital experiences. In this step-by-step guide, we will walk you through the process of installing Craft CMS on AlmaLinux 8. By the end of this tutorial, you will have a fully functioning Craft CMS installation on your AlmaLinux 8 server.
Step 1: Create Database
First, let’s create a database and a user for Craft CMS. We will also grant the necessary privileges to the user so that it can interact with the database. Open a terminal and log in to your AlmaLinux 8 server with root access.
mysql -u root
Once you are logged in to the MySQL shell, execute the following commands to create the database and user:
CREATE DATABASE craft; CREATE USER 'craftuser'@'localhost' IDENTIFIED BY 'YOUR-PASSWORD-HERE'; GRANT ALL PRIVILEGES ON craft.* TO 'craftuser'@'localhost'; FLUSH PRIVILEGES; quit;
Make sure to replace ‘YOUR-PASSWORD-HERE’ with a strong and secure password for the Craft CMS database user.
Step 2: Configure Nginx Reverse Proxy
Next, we need to configure Nginx as a reverse proxy for Craft CMS. Open the Nginx configuration file with your preferred text editor:
nano /etc/nginx/nginx.conf
Replace the contents of nginx.conf
with the following configuration:
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; }
Save and exit the file by pressing Ctrl+O
and then Ctrl+X
. This configuration sets up the basic Nginx settings.
Now, let’s create a new Nginx configuration file for your Craft CMS domain:
vi /etc/nginx/conf.d/craft.conf
Add the following code to the craft.conf
file:
server { listen 80; server_name your-domain.com; root /var/www/html/craft; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$args; } location = /favicon.ico { log_not_found off; access_log off; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass unix:/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } listen 443 http2 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot }
Make sure to replace your-domain.com
with your actual domain name. Also, update the SSL certificate paths accordingly.
Save and exit the file by pressing Esc
, then typing :wq!
, and finally pressing Enter
.
If you have SELinux enabled, run the following command to allow Nginx to make network connections:
setsebool -P httpd_can_network_connect1
Now, let’s restart Nginx to apply the changes:
systemctl restart nginx
To verify that Nginx is running without any errors, you can check its status:
systemctl status nginx
Step 3: Enable HTTP and HTTPS (Ports 80 and 443)
To enable HTTP and HTTPS connections through the firewall, run the following commands:
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --reload
This will allow incoming traffic on ports 80 and 443, which are used for HTTP and HTTPS respectively.
Step 4: Download and Install Craft CMS
Now, let’s download and install Craft CMS on your AlmaLinux 8 server. Navigate to the /var/www/html
directory:
cd /var/www/html
Create a new directory for your Craft CMS installation:
mkdir craft
Navigate into the craft
directory:
cd craft
Download the latest version of Craft CMS from the official website:
wget https://craftcms.com/latest-v3.zip
Unzip the downloaded file:
unzip latest-v3.zip
Remove the downloaded ZIP file:
rm latest-v3.zip
Step 5: Configure Craft CMS
Before we can access the Craft CMS installation, we need to configure it with the database details. Open the .env
file in your preferred text editor:
nano /var/www/html/craft/.env
Update the following lines with your MySQL database information:
DB_DRIVER=mysql DB_SERVER=localhost DB_PORT=3306 DB_DATABASE=craft DB_USER=craftuser DB_PASSWORD=YOUR-PASSWORD-HERE
Save and exit the file.
Next, let’s set the correct file permissions for Craft CMS. Run the following commands to make the necessary folders readable:
chmod -R 755 /var/www/html/craft chown -R nginx:nginx /var/www/html/craft chcon -R -t httpd_sys_content_rw_t /var/www/html/craft
Now, restart Nginx to apply the changes:
systemctl restart nginx
To verify that Nginx is running without any errors, you can check its status:
systemctl status nginx
Step 6: Access Craft CMS
You can now access your Craft CMS installation by navigating to your server’s IP address or domain name in your web browser:
https://your-domain.com
Replace your-domain.com
with your actual domain name or IP address.
Follow the on-screen instructions to complete the Craft CMS installation. You will be prompted to enter the database details that we configured earlier.
Congratulations! You have successfully installed Craft CMS with LEMP stack on your AlmaLinux 8 server.
Conclusion
In this tutorial, we learned how to install Craft CMS on AlmaLinux 8 using the LEMP stack. We covered the step-by-step process of creating a database, configuring Nginx as a reverse proxy, downloading and installing Craft CMS, and configuring it with the necessary database details. Now you can start building your custom digital experiences with Craft CMS on AlmaLinux 8.
If you want a hassle-free Craft CMS hosting experience, consider checking out Shape.host. Shape.host offers reliable Linux SSD VPS hosting with excellent performance and top-notch customer support.