How to Install Pico CMS on Ubuntu 18.04 LTS

Pico is an open source simple and fast flat file CMS written in PHP. This means there is no administration backend and database to deal with. You simply create .md files in the content folder and that becomes a page. Pico uses the Twig templating engine, for powerful and flexible themes. Pico source code is available on Github. In this tutorial, we will install Pico CMS with Nginx on Ubuntu 18.04 LTS system.

Requirements

Requirements for running Pico are:

  • Nginx
  • PHP version 5.3.6 or greater
  • Composer

Prerequisites

  • An Ubuntu 18.04 LTS operating system.
  • A non-root user with sudo privileges.

Initial steps

Check your Ubuntu version:

lsb_release -ds
# Ubuntu 18.04.2 LTS

Set up the timezone:

sudo dpkg-reconfigure tzdata

Update your operating system packages (software). This is an important first step because it ensures you have the latest updates and security fixes for your operating system's default software packages:

sudo apt update && sudo apt upgrade -y

Install some essential packages that are necessary for basic administration of Ubuntu operating system:

sudo apt install -y curl wget vim git unzip socat bash-completion apt-transport-https

Step 1 - Install PHP

Install PHP, as well as the necessary PHP extensions:

sudo apt install -y php7.2 php7.2-cli php7.2-fpm php7.2-common php7.2-curl php7.2-gd php7.2-json php7.2-zip php7.2-xml php7.2-mbstring

To show PHP compiled in modules, you can run:

php -m

ctype
curl
exif
fileinfo
. . .
. . .

Check the PHP version:

php --version

# PHP 7.2.17-0ubuntu0.18.04.1 (cli) (built: Apr 18 2019 14:12:38) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
# with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

PHP-FPM service is automatically started and enabled on reboot on Ubuntu 18.04 system, so there is no need to start and enable it manually. We can move on to the next step, which is the database installation and setup.

Step 2 - Install acme.sh client and obtain Let's Encrypt certificate (optional)

Securing your forum with HTTPS is not necessary, but it is a good practice to secure your site traffic. In order to obtain TLS certificate from Let's Encrypt we will use acme.sh client. Acme.sh is a pure UNIX shell software for obtaining TLS certificates from Let's Encrypt with zero dependencies. 

Download and install acme.sh:

sudo su - root
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh 
./acme.sh --install --accountemail [email protected]
source ~/.bashrc
cd ~

Check acme.sh version:

acme.sh --version
# v2.8.0

Obtain RSA and ECC/ECDSA certificates for your domain/hostname:

# RSA 2048
acme.sh --issue --standalone -d example.com --keylength 2048
# ECDSA
acme.sh --issue --standalone -d example.com --keylength ec-256

If you want fake certificates for testing you can add --staging flag to the above commands.

After running the above commands, your certificates and keys will be in:

  • For RSA: /home/username/example.com directory.
  • For ECC/ECDSA: /home/username/example.com_ecc directory.

To list your issued certs you can run:

acme.sh --list

Create a directory to store your certs. We will use /etc/letsencrypt directory.

mkdir -p /etc/letsecnrypt/example.com
sudo mkdir -p /etc/letsencrypt/example.com_ecc

Install/copy certificates to /etc/letsencrypt directory.

# RSA
acme.sh --install-cert -d example.com --cert-file /etc/letsencrypt/example.com/cert.pem --key-file /etc/letsencrypt/example.com/private.key --fullchain-file /etc/letsencrypt/example.com/fullchain.pem --reloadcmd "sudo systemctl reload nginx.service"
# ECC/ECDSA
acme.sh --install-cert -d example.com --ecc --cert-file /etc/letsencrypt/example.com_ecc/cert.pem --key-file /etc/letsencrypt/example.com_ecc/private.key --fullchain-file /etc/letsencrypt/example.com_ecc/fullchain.pem --reloadcmd "sudo systemctl reload nginx.service"

All the certificates will be automatically renewed every 60 days.

After obtaining certs exit from root user and return back to normal sudo user:

exit

Step 3 - Install and configure NGINX

Install NGINX:

sudo apt install -y nginx

Check the NGINX version:

sudo nginx -v
# nginx version: nginx/1.14.0 (Ubuntu)

Next, configure NGINX for Pico CMS. Run sudo vim /etc/nginx/sites-available/pico.conf and add the following configuration.

server {
  
  listen 80;
  listen 443 ssl;
  server_name example.com;
  root /var/www/pico;
ssl_certificate /etc/letsencrypt/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/example.com/private.key;
ssl_certificate /etc/letsencrypt/example.com_ecc/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/example.com_ecc/private.key;
index index.php; location ~ ^/((config|content|vendor|composer\.(json|lock|phar))(/|$)|(.+/)?\.(?!well-known(/|$))) { deny all; } location / { index index.php; try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri =404; fastcgi_index index.php; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_param PICO_URL_REWRITING 1; } }

Activate the new pico.conf configuration by linking the file to the sites-enabled directory:

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

Check NGINX configuration for syntax errors:

sudo nginx -t

Reload NGINX service:

sudo systemctl reload nginx.service

Step 4 - Install Composer

Install Composer, the PHP dependency manager globally:

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

php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

sudo mv composer.phar /usr/local/bin/composer

Check the Composer version:

composer --version
# Composer version 1.8.5 2019-04-09 17:46:47

NOTE: Composer installation commands will change in the future, so check https://getcomposer.org/download/ for the most up to date commands if the above commands don't work.

Step 5 - Install Pico CMS

Create a document root directory for Pico CMS:

sudo mkdir -p /var/www/pico

Change ownership of the /var/www/pico directory to [jour_username]:

sudo chown -R [your_username]:[your_username] /var/www/pico

Navigate to the document root directory:

cd /var/www/pico

Download Pico with composer:

composer create-project picocms/pico-composer .

Change ownership of the /var/www/pico directory to www-data:

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

You have successfully installed Pico CMS on Ubuntu 18.04 server. You can now simply create your own content folder in Pico's root directory, create .md files in the content directory and those files become your pages. 

Links

Share this page:

0 Comment(s)