7

How to Install Paste 2.1 on a FreeBSD 11 FAMP VPS

 2 years ago
source link: https://www.vultr.com/docs/how-to-install-paste-2-1-on-a-freebsd-11-famp-vps
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
<?xml encoding="utf-8" ??>

Paste 2.1 is a simple and flexible, free and open source pastebin application for storing code, text and more. It was initially forked from the freely available original source code used by pastebin.com before the domain was sold in 2010. Since that time, the Paste developers have added lots of improvements and features such as a featureful Admin Dashboard with site statstics and settings, IP and user bans, the ability to selectively delete pastes, user accounts with social integration, profile pages, and all of the usual extras such as syntax highlighting for the majority of languages, configurable paste limits and much more.

In this tutorial we are going to install Paste 2.1 on a FreeBSD 11 FAMP VPS using Apache web server, PHP 7.1, and a MariaDB database.

Prerequisites

  • A clean Vultr FreeBSD 11 server instance with SSH access

Step 1: Add a Sudo User

We will start by adding a new sudo user.

First, log into your server as root:

ssh root@YOUR_VULTR_IP_ADDRESS

The sudo command isn't installed by default in the Vultr FreeBSD 11 server instance, so we will first install sudo:

pkg install sudo

Now add a new user called user1 (or your preferred username):

adduser user1

The adduser command will prompt you for lots of details for the user account, so simply select the defaults for most of them when it makes sense to do so. When you are asked whether to Invite user1 into any other groups?, you should enter wheel to add user1 to the wheel group.

Now check the /etc/sudoers file to make sure that the sudoers group is enabled:

visudo

Look for a section like this:

# %wheel        ALL=(ALL)       ALL

This line tells us that users who are members of the wheel group can use the sudo command to gain root privileges. It will be commented out by default so you will need to uncomment it and then save and exit the file.

We can verify the user1 group membership with the groups command:

groups user1

If user1 is not a member of the wheel group, you can use this command to update the user1 group membership:

pw group mod wheel -m user1 

Now use the su command to switch to the new sudo user user1 account:

su - user1

The command prompt will update to indicate that you are now logged into the user1 account. You can verify this with the whoami command:

whoami

Now restart the sshd service so that you can login via ssh with the new non-root sudo user account you have just created:

sudo /etc/rc.d/sshd restart

Exit the user1 account:

exit

Exit the root account (which will disconnect your ssh session):

exit

You can now ssh into the server instance from your local host using the new non-root sudo user user1 account:

ssh user1@YOUR_VULTR_IP_ADDRESS

If you want to execute sudo without having to type a password every time, then open the /etc/sudoers file again, using visudo:

sudo visudo

Edit the section for the wheel group so that it looks like this:

%wheel        ALL=(ALL)       NOPASSWD: ALL

Please note: Disabling the password requirement for the sudo user is not a recommended practice, but it is included here as it can make server configuration much more convenient and less frustrating, especially during longer systems administration sessions. If you are concerned about the security implications, you can always revert the configuration change to the original after you finish your administration tasks.

Whenever you want to log into the root user account from within the sudo user account, you can use one of the following commands:

sudo -i
sudo su -

You can exit the root account and return back to your sudo user account any time by simply typing:

exit

Step 2: Update FreeBSD 11 System

Before installing any packages on the FreeBSD server instance, we will first update the system.

Make sure you are logged in to the server using a non-root sudo user and run the following commands:

sudo freebsd-update fetch
sudo freebsd-update install
sudo pkg update
sudo pkg upgrade

Step 3: Install Apache Web Server

Install the Apache web server:

sudo pkg install apache24

Enter y when prompted.

Now use the sysrc command to enable the Apache service to execute automatically at boot time:

sudo sysrc apache24_enable=yes

The sysrc command updates the /etc/rc.conf configuration file, so if you want to verify the configuration update manually you can simply open the /etc/rc.conf file with your favourite terminal editor:

vi /etc/rc.conf

Now start the Apache service:

sudo service apache24 start

You can quickly check that apache is running by visiting the IP address or domain of the server instance in your browser:

http://YOUR_VULTR_IP_ADDRESS/

You will see the default FreeBSD Apache page displaying the text:

It works!

Check your Apache default configuration file to ensure that the DocumentRoot directive points to the correct directory:

sudo vi /usr/local/etc/apache24/httpd.conf

The DocumentRoot configuration option will look like this:

DocumentRoot "/usr/local/www/apache24/data"

We now need to enable the mod_rewrite Apache module. We can do this by searching the default Apache configuration file for the term mod_rewrite.

By default, the mod_rewrite Apache module will be commented out (which means it is disabled). The configuration line on a clean Vultr FreeBSD 11 instance will look like this:

#LoadModule rewrite_module libexec/apache24/mod_rewrite.so

Simply remove the hash symbol to uncomment the line and load the module. This, of course, applies to any other required Apache modules too:

LoadModule rewrite_module libexec/apache24/mod_rewrite.so

We now need to edit The Directory Apache directive in the same configuration file so that mod_rewrite will work correctly with Paste.

Find the section of the configuration file that starts with <Directory "/usr/local/www/apache24/data"> and change AllowOverride none to AllowOverride All. The end result (with all comments removed) will look something like this:

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Now save and exit the Apache configuration file.

We will restart Apache at the end of this tutorial, but restarting Apache regularly during installation and configuration is certainly a good habit, so let's do it now:

sudo service apache24 restart

Step 4: Install PHP 7.1

We can now install PHP 7.1 along with all of the necessary PHP modules required by Paste:

sudo pkg install php71 mod_php71 php71-gd php71-mbstring php71-mysqli php71-xml php71-curl php71-ctype php71-tokenizer php71-simplexml php71-dom php71-session php71-iconv php71-hash php71-json php71-fileinfo php71-pdo php71-pdo_mysql php71-zlib php71-openssl php71-zip php71-phar

FreeBSD 11 gives us the option to use a development php.ini or a production php.ini. Since we are going to install Paste on a public web server, we'll use the production version. First, back up php.ini-production:

sudo cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini-production.backup

Then soft-link php.ini-production to php.ini:

sudo ln -s /usr/local/etc/php.ini-production /usr/local/etc/php.ini

We need to configure Apache to actually use PHP, so let's create a new file called php.conf in the Apache Includes directory:

sudo vi /usr/local/etc/apache24/Includes/php.conf

Enter the following text into the newly created file:

<IfModule dir_module>
    DirectoryIndex index.php index.html
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
</IfModule>

Save and exit the file.

Now let's restart Apache so that it can reload the configuration changes:

sudo service apache24 restart

Step 5: Install MariaDB (MySQL) Server

FreeBSD 11 defaults to using MariaDB database server, which is an enhanced, fully open source, community developed, drop-in replacement for MySQL server.

Install the latest version of MariaDB database server:

sudo pkg install mariadb102-server mariadb102-client

Start and enable MariaDB server to execute automatically at boot time:

sudo sysrc mysql_enable="yes"
sudo service mysql-server start

Secure your MariaDB server installation:

sudo mysql_secure_installation

When prompted to create a MariaDB/MySQL root user, select "Y" (for yes) and then enter a secure root password. Simply answer "Y" to all of the other yes/no questions as the default suggestions are the most secure options.

Step 6: Create Database for Paste

Log into the MariaDB shell as the MariaDB root user by running the following command:

sudo mysql -u root -p

To access the MariaDB command prompt, simply enter the MariaDB root password when prompted.

Run the following queries to create a MariaDB database and database user for Paste:

CREATE DATABASE paste_db CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'paste_user'@'localhost' IDENTIFIED BY 'UltraSecurePassword';
GRANT ALL PRIVILEGES ON paste_db.* TO 'paste_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

You can replace the database name paste_db and username paste_user with something more to your liking, if you prefer. Also, make sure that you replace "UltraSecurePassword" with an actually secure password.

Step 7: Install Paste Files

Change your current working directory to the default web directory:

cd /usr/local/www/apache24/data

Your current working directory will now be: /usr/local/www/apache24/data. You can check this with the pwd (print working directory) command:

pwd

Now use wget to download the Paste installation package:

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

Please note: You should definitely check for the most recent version by visiting the Paste download page.

List the current directory to check that you have successfully downloaded the file:

ls -la

Remove index.html:

sudo rm index.html

Now uncompress the zip archive:

sudo unzip paste-2.1.zip

Move all of the installation files to the web root directory:

sudo mv paste-2.1/* /usr/local/www/apache24/data

Change ownership of the web files to avoid any permissions problems:

sudo chown -R www:www * ./

Restart Apache again:

sudo service apache24 restart

Now we're ready to move on to the final step.

Step 8: Complete Paste Installation

It's time to visit the IP address of your server instance in your browser, or if you've already configured your Vultr DNS settings (and given it enough time to propagate) you can simply visit your domain instead.

To access the Paste installation page, enter your Vultr instance IP address into your browser address bar, followed by /install/:

http://YOUR_VULTR_IP_ADDRESS/install/

Most of the installation options are self explanatory, but here are a few pointers to help you along:

  1. Ensure that the Pre-installation checks are all green. Specifically, the following 3 files must be writable:

    config.php
    tmp/temp.tdata
    sitemap.xml
    
  2. Enter the following DATABASE INFORMATION:

    Hostname:               localhost
    Database Name:          paste_db
    Username:               paste_user
    Password:               UltraSecurePassword
    

    Make a note of the key value and store it in a safe place, then click Install to continue.

  3. Enter the following Administrator details:

    Username:               admin
    Password:               <secure admin password>
    

    Click Submit to finalize the installation.

To access the admin section simply click on the dashboard button and enter your username and password. If you aren't redirected to the admin login page, you can enter the admin address manually:

http://YOUR_VULTR_IP_ADDRESS/admin/

For security reasons, make sure you delete the /install/ directory from the webroot directory:

sudo rm -rf ./install

If you get an error message when trying to delete the /install/ directory, simply change the permissions of the webroot and try again:

sudo chmod 755 .
sudo rm -rf ./install

You are now ready to start administering your own personal pastebin site.

Want to contribute?

You could earn up to $600 by adding new articles


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK