How to Install Bolt CMS with Nginx on Ubuntu 20.04
Bolt is a free, open-source, lightweight and simple content management system based on PHP. It is designed for ease of use and helps you to create powerful and dynamic content websites easily. It is built on Silex microframework and is a great alternative for those looking for a modern PHP system. It is created using modern open-source libraries and is best suited to build sites in HTML5 with modern markup.
In this tutorial, we will show you how to install Bolt CMS with Nginx and Let's Encrypt SSL on Ubuntu 20.04.
Prerequisites
- A server running Ubuntu 20.04.
- A valid domain name pointed with your server IP.
- A root password is configured the server.
Getting Started
Before starting, it is always recommended to update your system with the latest version of packages. You can update it with the following command:
apt-get update -y
Once all the packages are updated, install other dependencies by running the following command:
apt-get install software-properties-common gnupg2 unzip git -y
After installing all the dependencies, you can proceed to the next step.
Install LEMP Server
First, install Nginx and MariaDB server by running the following command:
apt-get install nginx mariadb-server -y
Next, you will need to install PHP version 7.2 in your server. By default, Ubuntu 20.04 ships with PHP version 7.4. So you will need to add Ondrej PHP repository in your system.
You can add the PHP repository with the following command:
add-apt-repository ppa:ondrej/php
Once the repository is added, update the repository and install the PHP and other required extensions with the following command:
apt-get update -y
apt-get install php7.2 php7.2-cli php7.2-fpm php7.2-common php7.2-mbstring php7.2-zip php7.2-pgsql php7.2-sqlite3 php7.2-curl php7.2-gd php7.2-mysql php7.2-intl php7.2-json php7.2-opcache php7.2-xml -y
Once all the packages are installed, you can proceed to the next step.
Create a Database for Bolt
Next, you will need to create a database and user for Bolt. First, log in to the MariaDB with the following command:
mysql
Once login, create a database and user with the following command:
MariaDB [(none)]> CREATE DATABASE boltdb;
MariaDB [(none)]> CREATE USER 'bolt'@'localhost' IDENTIFIED BY 'password';
Next, grant all the privileges to the Bolt database with the following command:
MariaDB [(none)]> GRANT ALL ON boltdb.* TO 'bolt'@'localhost';
Next, flush the privileges and exit from the MariaDB shell with the following command:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
Once you are finished, you can proceed to the next step.
Download Bolt CMS
First, you will need to download the latest version of Bolt CMS from the Git repository. You can download it to the Nginx root directory by running the following command:
cd /var/www/html
git clone https://github.com/bolt/bolt.git
Once the Bolt is downloaded, change the directory to bolt and copy the sample config file:
cd bolt
cp app/config/config.yml.dist app/config/config.yml
Next, edit the config.yml file and define your database settings:
nano app/config/config.yml
Remove the default sqlite database line and add the following lines:
database: driver: mysql username: bolt password: password databasename: boltdb host: localhost prefix: prefix_
Save and close the file when you are finished.
Next, you will need to install the Composer in your system. Composer is a dependency manager for PHP. You can install it with the following command:
wget -O composer-setup.php https://getcomposer.org/installer
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Once the Composer is installed, you should get the following output:
All settings correct for using Composer Downloading... Composer (version 2.0.2) successfully installed to: /usr/local/bin/composer Use it: php /usr/local/bin/composer
Next, install the required PHP dependencies for Bolt CMS with the following command:
composer install
Once all the dependencies are installed, change the ownership and permissions of the bold directory:
chown -R www-data:www-data /var/www/html/bolt
chmod -R 755 /var/www/html/bolt
Once you are finished, you can proceed to the next step.
Configure Nginx for Bolt
Next, you will need to create an Nginx virtual host configuration file for Bolt CMS. You can create it with the following command:
nano /etc/nginx/sites-available/bolt.conf
Add the following lines:
server { listen 80; root /var/www/html/bolt; index index.php index.html index.htm; server_name bolt.example.com; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ [^/]\.php(/|$) { try_files /index.php =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_index index.php; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location = /bolt { try_files $uri /index.php?$query_string; } location ^~ /bolt/ { try_files $uri /index.php?$query_string; } }
Save and close the file when you are finished then enable the Nginx virtual host file using the following command:
ln -s /etc/nginx/sites-available/bolt.conf /etc/nginx/sites-enabled/bolt.conf
Next, verify the Nginx for any configuration error with the following command:
nginx -t
You should see 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
At this point, Nginx is configured to serve Bolt CMS. You can now proceed to the next step.
Access Bolt CMS
Now, open your web browser and type the URL http://bolt.example.com. You will be redirected to the following page:
Provide your desired username, password, email and click on the Create the first user button. You should see the Bolt CMS dashboard in the following page:
Now, click on the View site button. You should see the Bolt CMS simple site page in the following page:
Secure BoltCMS with Let's Encrypt SSL
It is always a good idea to secure your website with Let's Encrypt SSL. First, install the Certbot Let's Encrypt client in your server with the following command:
apt-get install python3-certbot-nginx -y
Once installed, secure your website with Let's Encrypt SSL by running the following command:
certbot --nginx -d bolt.example.com
You will be asked to provide a valid email address and accept the term of service as shown below:
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator nginx, Installer nginx 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 Obtaining a new certificate Performing the following challenges: http-01 challenge for bolt.example.com Waiting for verification... Cleaning up challenges Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/bolt.conf
Next, choose whether or not to redirect HTTP traffic to HTTPS as shown bellow:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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
Type 2 and hit Enter to finish the installation. You should see the following output:
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/bolt.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://bolt.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=bolt.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/bolt.example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/bolt.example.com/privkey.pem Your cert will expire on 2020-10-30. 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" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - 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 - We were unable to subscribe you the EFF mailing list because your e-mail address appears to be invalid. You can try again later by visiting https://act.eff.org.
Now, your BoltCMS website is secured with Let's Encrypt SSL. You can access it securely using the URL https://bolt.example.com
Conclusion
Congratulations! you have successfully installed Bolt CMS with Nginx and Let's Encrypt SSL on Ubuntu 20.04 server. You can now easily create your own website using the Bolt dashboard. Feel free to ask me if you have any questions.