bookmark_borderUbuntu 22.04 Template now available for KVM Based VPS

Hey There!
We’re happy to announce that Ubuntu 22.04 is now available as an operating system choice on our KVM-based plans in our control panel.

Please refer to the following guide to install the operating system on KVM based VPSes using our Control Panel, Click Here.

Stay tuned for further updates!

Follow us on CrownCloud BlogTwitter, and Facebook for updates regarding current offers and other updates.

bookmark_borderInstalling PostgreSQL on Ubuntu 22.04

Hello,
In this week’s feature highlight, we look at How To Install PostgreSQL on Ubuntu 22.04

PostgreSQL is a powerful, open-source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance.

Install PostgreSQL on Ubuntu

Install PostgreSQL on Ubuntu by using the following command

apt update

apt install postgresql postgresql-contrib

Output:

root@crown:~# apt install postgresql postgresql-contrib
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
postgresql-contrib is already the newest version (13+225ubuntu1).
The following packages were automatically installed and are no longer required:
  libfile-find-rule-perl libnumber-compare-perl libtext-glob-perl
Use 'apt autoremove' to remove them.
Suggested packages:
  postgresql-doc
The following NEW packages will be installed:
  postgresql 

PostgreSQL Roles and Databases

We’ll switch to Postgres account for the next steps, to switch to the postgres account, use the following command,

sudo -i -u postgres

You can access a PostgreSQL prompt using the psql utility

psql

Output:

postgres@crown:~$ psql
psql (14.2 (Ubuntu 14.2-1))
Type "help" for help.

postgres=#

Exit out of the PostgreSQL shell type

\q

Create PostgreSQL Role,

sudo -u postgres createuser --interactive

Output:

Enter name of role to add: john
Shall the new role be a superuser? (y/n) y

Create a PostgreSQL database,

sudo -u postgres createdb john

Open a Postgres Prompt with the New Role.

sudo adduser john

Switch over and connect to the database.

sudo -u john psql

Output:

root@crown:~# sudo -u john psql
could not change directory to "/root": Permission denied
psql (14.2 (Ubuntu 14.2-1))
Type "help" for help.

john=#

Once you logged in as john and check your current connection information.

\conninfo

Output:

john=# \conninfo
You are connected to database "john" as user "john" via socket in "/var/run/postgresql" at port "5432".
john=#

bookmark_borderInstalling LEMP Stack (Nginx, MariaDB, PHP8.1) on Ubuntu 22.04

Hello,
In this week’s feature highlight, we look at How to Install LEMP Stack (Nginx, MariaDB, PHP8.1) on Ubuntu 22.04

LEMP Stack is a combination of free, open source software. The acronym LEMP refers to the first letters of Linux (Operating system), Nginx Server, MySQL (database software), and PHP, PERL or Python, principal components to build a viable general purpose web server.

Updating the system

We first update the system to make sure that all our installed packages are up to date. Your Ubuntu system can be updated easily with the following command.

apt update

apt upgrade

Install Nginx

We will start by installing the Nginx web server. To complete the installation, use the following command.

apt install nginx

Output:

root@crown:~# apt install nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  fontconfig-config fonts-dejavu-core libdeflate0 libfontconfig1 libgd3
  libjbig0 libjpeg-turbo8 libjpeg8 libnginx-mod-http-geoip2
  libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter
  libnginx-mod-mail libnginx-mod-stream libnginx-mod-stream-geoip2 libtiff5
  libwebp7 libxpm4 nginx-common nginx-core
Suggested packages:
  libgd-tools fcgiwrap nginx-doc ssl-cert

Once the installation is complete, enable Nginx (to start automatically upon system boot), start the webserver, and verify the status using the commands below.

systemctl start nginx

systemctl enable nginx

systemctl status nginx

Output:

 root@crown:~#     systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-03-17 14:43:23 UTC; 36min ago
       Docs: man:nginx(8)
    Process: 42595 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=ex>
    Process: 42596 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, sta>
   Main PID: 42597 (nginx)
      Tasks: 2 (limit: 1074)
     Memory: 2.8M
        CPU: 34ms
     CGroup: /system.slice/nginx.service
             ├─42597 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             └─42598 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">

Check the Nginx version,

nginx -v

Output:

root@crown:~#     nginx -v
nginx version: nginx/1.18.0 (Ubuntu)

Verify that the webserver is running and accessible by accessing your server’s IP address.

From your browser,

http://IP_address
image

we need to make the user Nginx the owner of the web directory. By default, it’s owned by the root user.

chown www-data:www-data /usr/share/nginx/html -R

Install MariaDB Server

MariaDB is a popular database server. The installation is simple and requires just a few steps as shown.

apt install mariadb-server mariadb-client

Output:

root@crown:~# apt install mariadb-server mariadb-client
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  galera-4 libcgi-fast-perl libcgi-pm-perl libclone-perl
  libconfig-inifiles-perl libdaxctl1 libdbd-mysql-perl libdbi-perl
  libencode-locale-perl libfcgi-bin libfcgi-perl libfcgi0ldbl
  libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
  libhttp-date-perl libhttp-message-perl libio-html-perl
  liblwp-mediatypes-perl libmariadb3 libmysqlclient21 libndctl6 libpmem1
  libsnappy1v5 libtimedate-perl liburi-perl liburing2 mariadb-client-10.6
  mariadb-client-core-10.6 mariadb-common mariadb-server-10.6
  mariadb-server-core-10.6 mysql-common socat

Once the installation is complete, enable MariaDB (to start automatically upon system boot), start the MariaDB, and verify the status using the commands below.

systemctl start mariadb

systemctl enable mariadb

systemctl status mariadb

Output:

root@crown:~# systemctl status mariadb
● mariadb.service - MariaDB 10.6.7 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-03-17 13:37:36 UTC; 1h 37min ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 26174 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 7 (limit: 1074)
     Memory: 57.2M
        CPU: 1.671s
     CGroup: /system.slice/mariadb.service
             └─26174 /usr/sbin/mariadbd

Finally, you will want to secure your MariaDB installation by issuing the following command.

mysql_secure_installation

Output:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

Once secured, you can connect to MySQL and review the existing databases on your database server by using the following command.

mysql -e "SHOW DATABASES;" -p

Output:

root@vps:~# mysql -e "SHOW DATABASES;" -p
Enter password:
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+

Install PHP 8.1

To Install PHP 8.1, use the command.

apt install php php-fpm php-mysql php-common php-cli php-common php-json php-opcache php-readline php-mbstring php-xml php-gd php-curl

To start php8.1-fpm.

systemctl start php8.1-fpm

To auto-start on boot php8.1-fpm.

systemctl enable php8.1-fpm

To Check status.

systemctl status php8.1-fpm

Output:

 root@crown:~# systemctl status php8.1-fpm
● php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor pr>
     Active: active (running) since Thu 2022-03-17 14:12:02 UTC; 57min ago
       Docs: man:php-fpm8.1(8)
   Main PID: 41457 (php-fpm8.1)
     Status: "Processes active: 0, idle: 2, Requests: 1, slow: 0, Traffic: 0req>
      Tasks: 3 (limit: 1074)
     Memory: 11.6M
        CPU: 359ms
     CGroup: /system.slice/php8.1-fpm.service
             ├─41457 "php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)" >
             ├─41458 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "">
             └─41459 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "">

Setting Up Server Blocks

You need to remove the file default, located in /etc/nginx/sites-enabled.

rm /etc/nginx/sites-enabled/default

Create new server block file under /etc/nginx/conf.d/ directory.

nano /etc/nginx/conf.d/default.conf

Add the following text to the file.

  server {
  listen 80;
  listen [::]:80;
  server_name _;
  root /var/www/html/;
  index index.php index.html index.htm index.nginx-debian.html;

  location / {
    try_files $uri $uri/ /index.php;
  }

  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;
  }

 # A long browser cache lifetime can speed up repeat visits to your page
  location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
       access_log        off;
       log_not_found     off;
       expires           360d;
  }

  # disable access to hidden files
  location ~ /\.ht {
      access_log off;
      log_not_found off;
      deny all;
  }
}

Next, test to make sure that there are no syntax errors in any of your Nginx files.

nginx -t

If there aren’t any problems, restart Nginx to enable your changes.

systemctl reload nginx

Test PHP

To test PHP-FPM with the Nginx Web server, we need to create an info.php file in the webroot directory.

nano /var/www/html/info.php

Add the following PHP code to the file.

<?php phpinfo(); ?>

Now again, access http://localhost/info.php or http://yourserver-ip-address/info.php. You should see a page similar to the below one.

image

This concludes the installation of LEMP Stack on Ubuntu 22.04 server.

bookmark_borderInstalling LAMP Stack with MariaDB on Ubuntu 22.04

Hello,

In this week’s feature highlight, we look at How to Install LAMP Stack with MariaDB on Ubuntu 22.04

A LAMP stack is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Apache web server. The site data is stored in a MySQL or MariaDB database, and dynamic content is processed by PHP.

First, check for any pending system upgrades.

apt update
apt upgrade

Install Apache

Command to install Apache along with its utilities.

apt install -y apache2 apache2-utils

Next, check the Status of Apache.

systemctl status apache2

Output:

root@server:~# systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-03-14 21:07:34 UTC; 45min ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 22154 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 22158 (apache2)
      Tasks: 7 (limit: 1074)
     Memory: 13.7M
        CPU: 294ms
     CGroup: /system.slice/apache2.service
             ├─22158 /usr/sbin/apache2 -k start
             ├─22159 /usr/sbin/apache2 -k start
             ├─22160 /usr/sbin/apache2 -k start
             ├─22161 /usr/sbin/apache2 -k start
             ├─22162 /usr/sbin/apache2 -k start
             ├─22163 /usr/sbin/apache2 -k start
             └─22195 /usr/sbin/apache2 -k start

If Apache is not active can start using the following command.

systemctl start apache2

Use the following command to auto start Apache at boot time.

systemctl enable apache2

You can confirm the Apache2 version with the below command,

apache2 -v

Output:

Server version: Apache/2.4.52 (Ubuntu)
Server built:   2022-02-03T18:25:47

Enable and Configure Firewall

To enable HTTP TCP port,

ufw allow http

Output:

Rules updated Rules updated (v6) Now you can verify whether the apache is installed correctly or not by opening it in a web browser.

http://ip-address

NOTE: Replace with your Server IP address.

images

Install MariaDB Server

To install MariaDB server, run the below command:

apt install mariadb-server mariadb-client

To check the status of MariaDB.

systemctl status mariadb

Output:

root@server:~# systemctl status mariadb

● mariadb.service - MariaDB 10.6.7 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-03-14 20:55:55 UTC; 57min ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 14311 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 7 (limit: 1074)
     Memory: 57.2M
        CPU: 1.266s
     CGroup: /system.slice/mariadb.service
             └─14311 /usr/sbin/mariadbd

To start MariaDB if it is not active.

systemctl start mariadb

Use the following command to auto start MariaDB at boot time.

systemctl enable mariadb

Next, MariaDB database security.

NOTE: In this step, you will be prompted with several questions.

mysql_secure_installation

Output:

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

To login to MariaDB.

 mariadb -u root -p

To exit from MariaDB.

exit

To check MariaDB Version.

mariadb --version

Output:

root@server:~# mariadb --version
mariadb  Ver 15.1 Distrib 10.3.25-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Install PHP

PHP 8.1 is the default version of PHP that would be installed on Ubuntu 22.04.

To install PHP.

apt install php libapache2-mod-php php-mysql php-common php-cli php-common php-json php-opcache php-readline

To Enable the Apache PHP module and restart the Apache Web server.

a2enmod php
systemctl restart apache2

To check PHP Version.

php --version

Output:

root@crown:~# php --version
PHP 8.1.0 (cli) (built: Nov 25 2021 19:57:29) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.0, Copyright (c), by Zend Technologies

To test PHP scripts we need to add the info.php file in the document.

nano /var/www/html/info.php

Add the following to the file.

<?php phpinfo(); ?>

To verify enter the following link in a web browser.

NOTE: Replace with your server IP address below.

http://ip-address/info.php
images

Run PHP-FPM with Apache [Optional]

FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for heavy-loaded sites.

NOTE: This is an optional step, PHP 8.1 is used to run the PHP code but if you want to run PHP code with PHP-FPM follow the below steps.

First, Let us disable PHP,

a2dismod php

Next, Install PHP-FPM.

apt install php8.1-fpm

Enable proxy_fcgi and setenvif module.

a2enmod proxy_fcgi setenvif

Output:

Considering dependency proxy for proxy_fcgi:
Enabling module proxy.
Enabling module proxy_fcgi.
Module setenvif already enabled
To activate the new configuration, you need to run:
  systemctl restart apache2

To enable php8.1-fpm file.

a2enconf php8.1-fpm

Restart the Apache.

systemctl restart apache2

To enable php-fpm.

systemctl enable php8.1-fpm

To start php-fpm.

systemctl start php8.1-fpm

To check the status of php-fpm.

systemctl status php8.1-fpm

Output:

root@crown:~# systemctl status php8.1-fpm
● php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-03-14 22:16:17 UTC; 29s ago
       Docs: man:php-fpm8.1(8)
   Main PID: 24942 (php-fpm8.1)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
      Tasks: 3 (limit: 1074)
     Memory: 7.3M
        CPU: 48ms
     CGroup: /system.slice/php8.1-fpm.service

Now you have successfully installed the LAMP stack (Apache, MariaDB, and PHP8.1) on Ubuntu 22.04.