How to Install WonderCMS with Nginx on Debian 11 Bullseye

WonderCMS is a fast and straightforward content management system requiring no database to create websites. It offers rich features such as custom login URL, SEO friendly design with WYSIWYG elements for editing your site in plain text or HTML code formats; flexible CSS framework so you can change up the look on individual pages without affecting other parts of the webpage, including headings/font sizes, etc. Along with native markdown support, which allows users easy ways to publish articles online using only paragraphs.

In the following tutorial, you will learn how to install WonderCMS using Nginx and PHP along with importing up-to-date repositories or using the default version and how to create a server block and set it up using the command line terminal on Debian 11 Bullseye desktop or server.

Install Nginx

To kickstart the installation, you will need to install the Nginx web server. A method is to install the latest Nginx mainline or stable from the Ondřej Surý repository to have the most updated software. Many Ubuntu users would know his PPA, and you can do the same in Debian.

For users who only wish to use the Debian default APT version of Nginx, use the following command below or skip and import the latest NGINX mainline or stable.

Install Nginx – Debian 11 Repository

sudo apt install nginx nginx-full

To use the latest version of either Nginx mainline or stable, you will need first to import the repository.

Import ONE REPOSITORY ONLY!

Option 1 – Import mainline repository:

curl -sSL https://packages.sury.org/nginx-mainline/README.txt | sudo bash -x

Option 2 – Import stable repository:

curl -sSL https://packages.sury.org/nginx/README.txt | sudo bash -x

Update your repository to reflect the new change:

sudo apt update

Now that you have installed the Nginx repository and updated the repository list, install Nginx with the following:

sudo apt install nginx-core nginx-common nginx nginx-full -y

Note that you may be prompted to keep or replace your existing /etc/nginx/nginx.conf configuration file during the installation. It is recommended to keep your current configuration file by pressing (n).

Installing Nginx with the custom repository comes with additional modules compiled, one of the most sorts after and recommended modules to enable is the Brotli module.

To install brotli, open your nginx.conf configuration file:

nano /etc/nginx/nginx.conf

Now add the additional lines before in the HTTP{} section:

brotli on;
brotli_comp_level 6;
brotli_static on;
brotli_types application/atom+xml application/javascript application/json application/rss+xml
   application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype
   application/x-font-ttf application/x-javascript application/xhtml+xml application/xml
   font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon
   image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml;

The brotli_comp_level can be set between 1 (lowest) and 11 (highest). Typically, most servers sit in the middle, but if your server is a monster, set to 11 and monitor CPU usage levels.

Next, test to make sure the changes are working correctly before making it live:

sudo nginx -t

If the changes are working correctly, you should see the following:

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

Now make the changes live by restarting your server:

sudo systemctl restart nginx

Next, enable Nginx on system boot:

sudo systemctl enable nginx --now

Install PHP & PHP-FPM

We are now installing PHP, which is the backend communicator or the middle man. PHP 8.0 is becoming relatively stable, and the newer versions of PHP 8.1 are now available.

The tutorial will focus on importing Ondřej Surý’s latest PHP version, the maintainer for Debian PHP. This is always up to date even when new PHP versions are dropped.

Import Ondřej Surý PHP Repository

The first step is to import and install the GPG and repository.

In your terminal, use the following command.

curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x

This command will install the PHP repository and update your APT repository.

Next, update the repository list as the new repository will require some existing packages to be upgraded and is advised to do before installing any versions of PHP.

sudo apt upgrade

Option 1. Install PHP 7.4

The default of many CMS minimum PHP versions is to install PHP 7.4. While this is considered incredibly stable, ideally, you should install PHP 8.0 if possible for performance and security benefits.

In your terminal, execute the following command.

sudo apt install php7.4 php7.4-fpm php7.4-mbstring php7.4-curl php7.4-zip

Next, start and enable PHP 7.4-FPM to be automatically started on boot.

sudo systemctl enable php7.4-fpm --now

Option 2. Install PHP 8.0

Most users should be installing PHP 8.0 for their web applications with 7.4 considered old stable, similar to 7.4 in your terminal; execute the following command.

sudo apt install php8.0 php8.0-fpm php8.0-mbstring php8.0-curl php8.0-zip

Next, start and enable PHP 8.0-FPM to be automatically started on boot.

sudo systemctl enable php8.0-fpm --now

Option 3. Install PHP 8.1

The third option is to install PHP 8.1, the latest release at the time of this tutorial. Similar to 8.0 and 7.4, run the following command to install PHP 8.1 for WonderCMS.

sudo apt install php8.1 php8.1-fpm php8.1-mbstring php8.1-curl php8.1-zip

Next, start and enable PHP 8.1-FPM to be automatically started on boot.

sudo systemctl enable php8.1-fpm --now

Install WonderCMS

Download WonderCMS

First things first, download the WonderCMS archive package by visiting the official download page to grab the latest link and download using your terminal command with either wget or curl command.

Example:

wget https://github.com/robiso/wondercms/releases/download/3.3.1/wondercms-331.zip

Create Folder Structure for WonderCMS

Now you have the archive downloaded, proceed to unzip it and move it to your www directory.

Create the directory for WonderCMS:

sudo mkdir -p /var/www/wondercms

UnzipWonderCMS to the www directory:

sudo unzip wondercms*.zip -d /var/www/

You must set the directory owner permissions to WWW, or else you will have trouble with WonderCMS write permissions.

Set chown permission (important):

sudo chown -R www-data:www-data /var/www/wondercms/

Set chmod permission (important):

sudo find /var/www/wondercms -type d -exec chmod 755 {} \;
sudo find /var/www/wondercms -type f -exec chmod 644 {} \;

Create Nginx Server Block Configuration

The next stage is to create the server block for WonderCMS for new users to Nginx; this is the website configuration file for the web application on the back-end, the same as virtual host for users migrating from Apache type web applications.

First, create a server block using the following command, be sure to replace the example.com with your domain name or name of choice.

sudo nano /etc/nginx/sites-available/example.com.conf

Below is an example; you can choose the parts; however, the “location ~ \.php$” needs to be in the Nginx configuration file.

NOTE: Make sure to change www.example.com and example.com and the root path.

server {
        listen 80;
        # adapt to your server name
        server_name www.wonder-example.com;
        # adapt the path
        root /var/www/wondercms;
        index index.php;
        # prevent directory listing
        autoindex off;

        # rewrite url to make it pretty
        location / {
            try_files $uri $uri/ @rewrite;
        }
            location @rewrite {
            rewrite ^/(.+)$ /index.php?page=$1 last;
        }

        # prevent access to database.js
        location ~ database.js {
            return 403;
        }

        location ~ cache.json {
            return 403;
        }

        # use php-fpm for dealing with php files

location ~ \.php$ {
      fastcgi_pass unix:/run/php/php8.1-fpm.sock;

      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
      include snippets/fastcgi-php.conf;
      fastcgi_buffer_size 128k;
      fastcgi_buffers 4 128k;
      fastcgi_intercept_errors on; 
        }
    }

Note, if you are using PHP 8.xx find and replace the above line “fastcgi_pass unix:/run/php/php7.4-fpm.sock;” to "fastcgi_pass unix:/run/php/php8.0-fpm.sock;" for 8.0 or "fastcgi_pass unix:/run/php/php8.1-fpm.sock;" for 8.1.

Next, you will need to enable the Nginx configuration file from “sites-available”. To do this, you will create a symlink to “sites-enabled” as follows.

sudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/

Make sure to replace "example.conf" it with your configuration file name.

You now can do a dry run then restart your Nginx server if everything is ok.

sudo nginx -t

After checking and everything is ok with your Nginx dry run test, restart the Nginx service.

sudo systemctl restart nginx

PHP.ini Configuration

Before moving onto the web UI installation part, you should adjust your PHP for optimal use for WonderCMS. These settings are more of a guide, and you can increase decrease as you see fit.

First, bring up your php.ini. Note that your location may differ depending on your PHP version number.

sudo nano /etc/php/{version}/fpm/php.ini

Next, ideally, you can further improve your CMS by adjusting some of the settings below. Note that if you are on a low resource 1VCPU, 1GB, you will not do much. However, the settings below are just a guide, do some research or use these and tinker away.

##increase upload max size recommend 50 to 100mb example only## 
 upload_max_filesize = 100MB

##increase post max size recommend 50 to 100mb  example only##
 post_max_size = 100MB

## increase max execution time recommend 120 to 300##
 max_execution_time = 120

## increase GET/POST/COOKIE input variables recommend 5000 to 10000##
max_input_vars = 5000

## increase memory limit recommend 256mb or 512mb##
memory_limit = 256M

Now restart your PHP-FPM server.

sudo systemctl restart php{version}-fpm

The PHP settings you adjusted are for the PHP backend. You will also need to change the Nginx server block to allow large body sizes. This is done by re-opening your server block and adding the following line.

Open up your server block.

sudo nano /etc/nginx/sites-available/example.com

Adjust this line to increase body size.

client_max_body_size 100M;

Remember, keep the client max size the same as your PHP file setting.

Next, test the changes, then restart your Nginx server if everything is ok.

sudo nginx -t

After checking and everything is ok with your Nginx dry run test, restart the Nginx service.

sudo systemctl restart nginx

Install WonderCMS WebUI

Now that all the backend setup and configuration are complete, you can go to your domain and begin installing.

##go to installation address##
 https://www.yoursite.com

The first page you will see is a temporary password and the login button.

Click login to proceed.

Example:

How to Install WonderCMS with Nginx on Debian 11 Bullseye

Enter your password to continue using the password available on the Welcome to your website login page. If you forgot or did not copy, click back and re-copy, then re-login.

Example:

How to Install WonderCMS with Nginx on Debian 11 Bullseye

Once logged in, you will hit your CMS page that looks like the original login page, do not be fooled; this is an open-edit page. At the top, you will see change settings, and this is highly advised immediately to secure your Website further.

Example (Click Image to Enlarge):

How to Install WonderCMS with Nginx on Debian 11 Bullseye

Once you open the settings page, from here, you can adjust plugins security settings and pretty much start customizing your website back end before hitting the WonderCMS page editor.

Example (Click Image to Enlarge):

How to Install WonderCMS with Nginx on Debian 11 Bullseye

Congratulations, you have successfully installed the latest version of WonderCMS with Nginx and PHP.

Secure Nginx with Let’s Encrypt SSL Free Certificate

Ideally, you would want to run your Nginx on HTTPS using an SSL certificate. The best way to do this is to use Let’s Encrypt, a free, automated, and open certificate authority run by the nonprofit Internet Security Research Group (ISRG).

First, install the certbot package as follows:

sudo apt install python3-certbot-nginx -y

Once installed, run the following command to start the creation of your certificate:

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d www.example.com

This ideal setup includes force HTTPS 301 redirects, a Strict-Transport-Security header, and OCSP Stapling. Just make sure to adjust the e-mail and domain name to your requirements.

Now your URL will be HTTPS://www.example.com instead of HTTP://www.example.com.

If you use the old HTTP URL, it will automatically redirect to HTTPS.

Optionally, you can set a cron job to renew the certificates automatically. Certbot offers a script that does this automatically, and you can first test to make sure everything is working by performing a dry run.

sudo certbot renew --dry-run

If everything is working, open your crontab window using the following terminal command.

sudo crontab -e

Next, please specify the time when it should auto-renew. This should be checked daily at a minimum, and if the certificate needs to be renewed, the script will not update the certificate. If you need help finding a good time to set, use the crontab.guru free tool.

00 00 */1 * * /usr/sbin/certbot-auto renew

Comments and Conclusion

In the tutorial, you have learned a few ways to install the latest or default Nginx and PHP versions along with WonderCMS on Debian 11 Bullseye.

All in all, it is a great CMS and would suit anyone looking for an easy-to-use CMS that doesn’t require any hosting. If you want a self-hosted CMS with a great community and design, then WonderCMS is the perfect option!



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!