Craft CMS is a free and open-source content management system used for creating custom digital experiences on the web. It is flexible, extensible, and designed for website owners who want more control and more powerful performances from their CMS. Craft CMS has a user-friendly web interface and offers tons of plugins that help you to add more functionality to your website. It is an alternative to WordPress for development-oriented publishers.

In this step-by-step guide, we will show you how to install Craft CMS with Nginx on OracleLinux 8.

Step 1 – Install LEMP Server

Before starting, you will need to install the Nginx web server, MariaDB database, PHP, and other required extensions to your server.

dnf install nginx mariadb-server -y

Once both packages are installed, you will need to install PHP version 8.0 and other required extensions on your server.

First, install the EPEL and Remi PHP repositories using the following command:

dnf install epel-release -y
dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

Next, disable the default PHP repository and enable the Remi PHP repository using the following command:

dnf module reset php
dnf module enable php:remi-8.0

Next, install PHP with all required extensions using the following command:

dnf install php php-cli php-fpm php-bcmath php-common php-curl php-gd php-json php-mbstring php-mysqli php-pgsql php-zip php-intl php-xml php-pdo -y

After installing all the packages, edit the php.ini file and change some recommended settings:

nano /etc/php.ini

Change the following settings:

memory_limit = 256M
date.timezone = Asia/Kolkata

Save and close the file, then edit the php-fpm configuration file and change the user and group from apache to nginx:

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

Change the following lines:

user = nginx 
group = nginx 

Save and close the file then start Nginx, MariaDB, and PHP-FPM service and enable them to start at system reboot:

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

Step 2 – Create a Database and User

Next, you will need to create a database and user for Craft CMS. First, log in to MySQL with the following command:

mysql

Once you are logged in, create a database and user with the following command:

create database craftdb;
grant all on craftdb.* to craftuser@localhost identified by 'securepassword';

Next, flush the privileges and exit from MariaDB with the following command:

flush privileges;
quit;

Step 3 – Install Composer

Composer is a dependency manager for PHP used for resolving PHP dependencies for your project.

First, download the Composer setup PHP file with the following command:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

Next, fetch the Composer Hash value and match it with the downloaded file:

HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

If everything is fine, you should get the following output:

Installer verified

Next, run the following command to install Composer on your system:

php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Once Composer is installed, verify the Composer version using the following command:

composer -V

You should get the following output:

Composer version 2.3.5 2022-04-13 16:43:00

Step 4 – Install Craft CMS

First, navigate to the Nginx web root directory and download the latest version of Craft CMS using the Composer tool:

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

During the installation, you will be asked to provide database credentials, admin username, password, and Craft URL as shown below:

> @php craft setup/welcome

   ______ .______          ___       _______ .___________.
  /      ||   _  \        /   \     |   ____||           |
 |  ,----'|  |_)  |      /  ^  \    |  |__   `---|  |----`
 |  |     |      /      /  /_\  \   |   __|      |  |
 |  `----.|  |\  \----./  _____  \  |  |         |  |
  \______|| _| `._____/__/     \__\ |__|         |__|
 
     A       N   E   W       I   N   S   T   A   L   L
               ______ .___  ___.      _______.
              /      ||   \/   |     /       |
             |  ,----'|  \  /  |    |   (----`
             |  |     |  |\/|  |     \   \
             |  `----.|  |  |  | .----)   |
              \______||__|  |__| |_______/


Generating an application ID ... done (CraftCMS--be1f09c9-cd35-4bfe-a01b-d611282eea19)
Generating a security key ... done (HaBt-G01s1pwVPNXmb1iAQZDI0M1lpuh)

Welcome to Craft CMS!

Are you ready to begin the setup? (yes|no) [no]:yes
Generating an application ID ... done (CraftCMS--f06f8153-f389-4603-97b7-c683b8cd422d)

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

Install Craft now? (yes|no) [yes]:yes
Username: [admin] 
Email: [email protected]
Password: 
Confirm: 
Site name: mysite
Site URL: http://craft.example.com
Site language: [en-US] 
installed Craft successfully (time: 6.230s)

Generating project config files from the loaded project config ... done

Next, change the ownership of the Craft CMS directory and PHP session directory to Nginx:

chown -R nginx:nginx /var/www/html/craft
chown -R nginx:nginx /var/lib/php/session

Step 5 – Configure Nginx for Craft CMS

Next, you will need to create an Nginx virtual host configuration file for Craft CMS. You can create it with the following command:

nano /etc/nginx/conf.d/craft.conf

Add the following configuration:

server {

  listen 80;
  server_name craft.example.com;
  root /var/www/html/craft/web;
  index index.php;


  location / {
    try_files $uri/index.html $uri $uri/ /index.php?$query_string;
  }

  location ~ [^/]\.php(/|$) {
    try_files $uri $uri/ /index.php?$query_string;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/run/php-fpm/www.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param HTTP_PROXY "";
  }

}

Save the file, then edit the Nginx main configuration file:

nano /etc/nginx/nginx.conf

Define the hash bucket size:

http {
server_names_hash_bucket_size 64;

Next, verify Nginx for any syntax configuration error using the following command:

nginx -t

You should get the following output:

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

Finally, restart the Nginx service to apply the changes:

systemctl restart nginx

Step 6 – Access Craft CMS

Now, open your web browser and access the Craft CMS website using the URL http://craft.example.com. You should see the following screen:
Craft CMS Welcome Screen
Click on the Go to your control panel. You will be redirected to the Craft CMS login page:
Craft CMS Login Screen
Provide your admin username, password, and click on the Login button. You should see the Craft CMS dashboard on the following screen:
Craft CMS Dashboard Screen

Conclusion

In this post, we explained how to install Craft CMS with Nginx on OracleLinux 8. You can now explore the Craft CMS and start building your website easily from the Craft CMS dashboard. Give it a try on your dedicated server from Atlantic.Net!