How to Install and Configure Paste

Alibaba Cloud
7 min readDec 11, 2018

By Arslan Ud Din Shafiq, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Paste is an open source application for storing code for an extended period of time. Forked from Pastebin.com, Paste is free to use and has a lot of new features to make development easier. In this tutorial, I will be installing and setting up Paste 2.1 using an Alibaba Cloud Elastic Compute Service (ECS) with Ubuntu 16.04.

Prerequisites

  1. You must have Alibaba Cloud Elastic Compute Service (ECS) activated and verified your valid payment method. If you are a new user, you can get a free account in your Alibaba Cloud account. If you don’t know about how to setup your ECS instance, you can refer to this tutorial or quick-start guide. Your ECS instance must have at least 1GB RAM and 1 Core processor.
  2. A domain name registered from Alibaba Cloud. If you have already registered a domain from Alibaba Cloud or any other host, you can update its domain nameserver records.
  3. Domain name must be pointed to your Alibaba Cloud ECS’s IP address
  4. Access to VNC console in your Alibaba Cloud or SSH client installed in your PC
  5. Set up your server’s hostname and create user with root privileges.

Setting Up Your Server

Before proceeding with installation of any kind of package, use the following command to update your Ubuntu system. To execute this command, remember to login from non-root user with sudo privileges.

# sudo apt update && sudo apt upgrade

You will need to install unzip which will be used to unzip the compressed zip folder. To install unzip, execute the command.

# sudo apt-get install unzip -y

Install PHP

Paste requires installation of PHP 5.6 or newer version of PHP. In this tutorial, you will install PHP 7.2. To install PHP 7.2, execute the following steps.

First, you will need to install python software properties and software properties common. To do so, execute the command below.

# sudo apt-get install software-properties-common python-software-properties

You will need to add repository for newer versions of PHP. To do so, execute the commands below.

# sudo add-apt-repository ppa:ondrej/php

Then, update the system to refresh the available repositories. To do so, execute the command for updating Ubuntu system.

# sudo apt update

Now let’s install PHP 7.2. To install PHP 7.2, execute the following command.

# sudo apt install -y php7.2

Paste requires the following PHP extensions:

  1. php7.2-imagick
  2. php7.2-common
  3. php7.2-mbstring
  4. php7.2-gd
  5. php7.2-xml
  6. php7.2-mysql
  7. php7.2-curl
  8. php7.2-zip
  9. php7.2-tidy
  10. libapache2-mod-php

To install the above extensions of PHP, execute the following command.

# sudo apt-get -y install php-gd php-mbstring php-common php-mysql php-imagick php-xml libapache2-mod-php php-curl php-tidy php-zip

When you have done installation of the above extensions, apache2 will be installed automatically. Hence, you don’t need to install apache explicitly.

To check your PHP installation, you can execute the following command to check installed PHP version.

# php --version

Install MariaDB

Paste supports MySQL. In this tutorial, you will use MariaDB server. By default, Ubuntu repository has older version of MariaDB server. To use new version of MariaDB, you will need to add MariaDB repository to your Ubuntu system. To do so, follow the steps below.

Verify the keys by executing command.

# sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

Add the repository using the command.

# sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirror.nodesdirect.com/mariadb/repo/10.2/ubuntu xenial main'

Update the system by using command.

# sudo apt update

Install MariaDB using the following command.

# sudo apt install -y mariadb-server

Start and enable the MariaDB server so that after reboot, the server can start automatically.

# sudo systemctl start mariadb
# sudo systemctl enable mariadb

Run the following command to enhance security of MariaDB server and set password for the root user.

# sudo mysql_secure_installation

Now connect to the MySQL shell as root user using the command below and enter your password.

# sudo mysql -u root -p

Execute the following MySQL queries in your MariaDB server.

CREATE DATABASE pastedb CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'aareez'@'localhost' IDENTIFIED BY '654321Ab';
GRANT ALL PRIVILEGES ON pastedb.* TO 'aareez'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Install Paste

To install Paste, you will need to follow the steps.

Navigate to /var/www/ using the command.

# cd /var/www

Now download Paste from sourceforge using the command below.

# sudo wget --content-disposition https://sourceforge.net/projects/phpaste/files/latest/download?source=files

Now unzip the downloaded zip compressed folder by executing the command below.

# sudo unzip paste-2.1.zip

Now remove the zip folder paste-2.1.zip using the command below.

# sudo rm paste-2.1.zip

Now provide ownership of /var/www/ to www-data so that apache server can access the required files.

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

Configure Apache Server

Let’s create virtual host configuration file for Paste. Execute the following command, a file will be opened in nano text editor.

# sudo nano /etc/apache2/sites-available/paste.conf

Copy and paste the following code and save the file.

<VirtualHost *:80> 
ServerAdmin admin@xyz.com
ServerName softpedia.xyz
DocumentRoot /var/www/
DirectoryIndex index.php index.htm index.html
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/Paste_error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/Paste_access.log combined
</VirtualHost>

Execute the command below to disable default site.

# sudo a2dissite 000-default.conf

Now you will need to enable the newly created virtual host. To do so, execute the command below.

# sudo a2ensite paste

Now you will need to enable rewrite mod. You can do so by editing configuration file in apache2 directory or you can simply execute the command below.

# sudo a2enmod rewrite

Now you will need to enable SSL engine. You can do so by editing configuration file in apache2 directory or you can simply execute the command below.

# sudo a2enmod ssl

Now you will have to restart apache server to apply the changes and load the settings by executing command below.

# sudo service apache2 restart

Now you can access Paste via your domain name or ECS IP address. You will see the following screen.

Let’s configure database:

To configure database, fill the database credentials details and hit install button.

After configuration of database, you will be asked to select username and password

After submission, you will see the following screen.

Now you may visit admin dashboard or main site. To avoid security issues, you will need to remove /install directory from your server. To do so, execute the command below.

# sudo rm -r /var/www/install

After accessing admin panel, you will see the following screen.

Install SSL Certificate

To install SSL certificate using let’s encrypt, you will use Certbot. To do so, execute the following steps.

Update the package using command.

# sudo apt-get update

To install software-properties-common, execute the command below.

# sudo apt-get install software-properties-common

Add the certbot repository by using command below.

# sudo add-apt-repository ppa:certbot/certbot

Update the package to load the added certbot repository using command.

# sudo apt-get update

Stop apache before issuance of SSL certificate.

# sudo systemctl stop apache2

Now install python-certbot-apache using the command below.

# sudo apt-get install python-certbot-apache

Execute the following command to get let’s encrypt SSL issued.

# sudo certbot --apache -d softpedia.xyz

Select the option 2 to redirect the link to https and update virtual host settings for SSL.

After successful issuance of SSL certificate, you will see the following screen.

Now restart apache server.

# sudo systemctl start apache2

Now you can access your website using https protocol. https://your_domain_name.tld

Set Up Firewalls for Required Ports

If you have activated firewalls, you will have to define a rule in Alibaba Cloud security group for your cloud server to add exception for port 80/tcp and 443/tcp. You can enable these ports while creating ECS instance, but in case, if you have forgotten to unblock these ports, you can follow the procedure below. By default, these ports are blocked by the firewalls.

If you are unsure how to set this up, visit the documentation page for Security Groups.

Congratulations, you have successfully installed and configured Paste on your server!

Reference:https://www.alibabacloud.com/blog/how-to-install-and-configure-paste_594250?spm=a2c41.12391209.0.0

--

--

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com