How To Write a Simple Shell Script on a VPS (Part 3)

Introduction

Conditional statements are indispensable to any useful scripting and full-featured programming language. On the third part of our Shell Script tutorial, you’ll learn all the “if’s” and “else’s” of bash, and how to use them to your advantage. This article has also been written assuming you have already configured your shell script folder according to the first tutorial.

The “if” command

A conditional statement is used to perform certain actions if a condition is true or false. With shell scripts, this is performed by the “if” command. It’s followed by an expression that’s going to be tested. This expression can also be the exit code of the execution of a command, a mathematical expression, beyond other various things. When working with exit codes, the command is pretty straightforward:

if ls folder
then
echo "Folder exists"
fi

If the folder exists, the echo command will run, because ls will have returned exit code 0, as in successful. Otherwise, if the folder doesn’t exist, the text will not be displayed. All “if” statements need to be followed by the “then” command, and ended with “fi”. If you’re not working with exit codes, and want to test a mathematical expression for example, you’ll need the “test” command. There are the following operators in shell script to compare numbers: Continue reading How To Write a Simple Shell Script on a VPS (Part 3)

How To Write a Simple Shell Script on a VPS (Part 2)

Introduction

The second part of this tutorial will teach you more basic commands for shell scripts on a VPS. They are responsible for both displaying and gathering information to and from the user. This article has been written assuming you have already configured your shell script folder according to the first tutorial.

The echo Command

This command enables you to display information for the user. You can display simple text strings, variables, or both of them together. It has two parameters: -n, which makes the text displayed not be followed by a new line, and -e, which enables the following set of “code” inside the string:

\a   - Alert sound
\b   - Backspace character
\c   - Don’t display new line
\e   - Escape character
\n   - New line
\r   - Carriage return
\t   - Horizontal tab
\0xx - ASCII character
\\   - Backslash

For example, the following commands perform exactly the same: Continue reading How To Write a Simple Shell Script on a VPS (Part 2)

How To Write a Simple Shell Script on a VPS

Introduction

This tutorial is aimed at teaching you how to write shell scripts for the most variety of purposes. Shell scripts can be used to run multiple commands, a single command with difficult and extensive arguments, or more user friendly interfaces for distributing your work. Essentially it makes your life easier by automating stuff you’d have to do manually without it.

Setting Up a Folder

Before you start writing your shell script, it’s a good practice to designate it a folder. It’s recommended that, for personal scripts, you do it over at ~/bin. To create that folder, run: Continue reading How To Write a Simple Shell Script on a VPS

How To Install Java on FreeBSD 10.1

How To Install Java on FreeBSD 10.1

Introduction

Java is a popular software platform that allows you to run Java applications and applets.

This tutorial covers how to install the following Java releases on FreeBSD 10.1, using packages and ports:

  • OpenJDK 7 JDK (default)
  • OpenJDK 8 JRE / JDK
  • OpenJDK 6 JRE / JDK

This guide does not cover the installation of Oracle Java because only the 32-bit version is supported on FreeBSD, through the Linux Binary Compatibility feature. Additionally, OpenJDK satisfies the Java needs of most users.

Prerequisites

Before you begin this guide, you should have a FreeBSD 10.1 server. Also, you must connect to your FreeBSD server as a user with superuser privileges (i.e. is allowed to use sudo or change to the root user).

Variations of Java

There are two different Java packages that can be installed: the Java Runtime Environment (JRE) and the Java Development Kit (JDK). JRE is an implementation of the Java Virtual Machine (JVM), which allows you to run compiled Java applications and applets. The JDK includes the JRE and other software that is required for writing, developing, and compiling Java applications and applets.

You may install various versions and releases of Java on a single system, but most people only need one installation. With that in mind, try to only install the version of Java that you need to run or develop your application(s). Continue reading How To Install Java on FreeBSD 10.1

How To Install WordPress with Nginx on a FreeBSD 10.1 Server

Introduction

WordPress is the most popular content management system (CMS) and blogging platform in the world. Using WordPress, you can quickly configure and customize your website, allowing you to add content and tweak the visual elements easily.

In this guide, we will be installing WordPress on a FreeBSD 10.1 machine using Nginx to serve our content. Nginx is a powerful web server that is efficient at handling a large number of concurrent connections. We will leverage this as the base for the WordPress installation we will be setting up in this guide.

Prerequisites and Goals

In order to complete this guide, there are some preliminary steps that should be taken in order to get your server ready.

We will be adding the components in this guide to a configured FEMP (FreeBSD, Nginx, MySQL, and PHP) stack. You can learn how to set up Nginx, MySQL, and PHP on your FreeBSD 10.1 server with our guide here here.

Once you have Nginx, MySQL, and PHP installed and configured on your server, you can continue on with this guide. Our goal in this guide is to install the latest version of WordPress on our FreeBSD server.

There is an existing WordPress package that is installable through FreeBSD’s pkg command, but it currently relies on PHP version 5.4, which will only be receiving security updates from now on. Its total end of life will be in September of 2015.

To ensure that our site is built on a base that will receive support for a long while, we will be downloading and installing the latest version of WordPress from the project’s site and using PHP version 5.6 to process the dynamic content. Continue reading How To Install WordPress with Nginx on a FreeBSD 10.1 Server

How To Install WordPress with Apache on FreeBSD 10.1

How To Install WordPress with Apache on FreeBSD 10.1

Introduction

WordPress is a popular open source content management system (CMS) that can be used to easily set up a blog. It is a very flexible system, through its plugin and template support, that allows users to extend its functionality to meet their specific needs; WordPress can be customized to support anything from a basic blog to a fully-featured eCommerce site.

In this tutorial, we will show you how to set up WordPress with an Apache web server on FreeBSD 10.1.

Prerequisites

Before you begin this guide, you must have a FAMP (FreeBSD, Apache, MySQL, and PHP) stack server setup. This WordPress installation tutorial is based on this FAMP tutorial: How To Install an Apache, MySQL, and PHP (FAMP) Stack on FreeBSD 10.1.

This tutorial assumes that you want to serve WordPress from the root of your web site, e.g. https://example.com/, and that your Apache document root is empty (aside from the default index.html file).

If you do not already have a FAMP setup, follow the linked guide before continuing with this tutorial. Note that this tutorial, like the linked FAMP guide, uses PHP 5.6. Continue reading How To Install WordPress with Apache on FreeBSD 10.1

How To Install an Nginx, MySQL, and PHP (FEMP) Stack on FreeBSD 10.1

Introduction

Nginx, MySQL, and PHP can be combined together easily as a powerful solution for serving dynamic content on the web. These three pieces of software can be installed and configured on a FreeBSD machine to create what is known as a FEMP stack.

In this guide, we will demonstrate how to install a FEMP stack on a FreeBSD 10.1 server. We will be installing the software using packages in order to get up and running more quickly. These packages provide reasonable defaults that work well for most servers.

Install the Components

To begin, we will install all of the software we need using FreeBSD packages system. The “install” command will update our local copy of the available packages and then install the packages we have requested: Continue reading How To Install an Nginx, MySQL, and PHP (FEMP) Stack on FreeBSD 10.1

How To Install an Apache, MySQL, and PHP (FAMP) Stack on FreeBSD 10.1

Introduction

A FAMP stack, which is similar to a LAMP stack on Linux, is a group of open source software that is typically installed together to enable a FreeBSD server to host dynamic websites and web apps. FAMP is an acronym that stands for FreeBSD (operating system), Apache (web server), MySQL (database server), and PHP (to process dynamic PHP content).

In this guide, we’ll get a FAMP stack installed on a FreeBSD 10.1 cloud server using pkg, the FreeBSD package manager.

Prerequisites

Before you begin this guide, you should have a FreeBSD 10.1 server. Also, you must connect to your FreeBSD server as a user with superuser privileges (i.e. is allowed to use sudo or change to the root user).

Step One — Install Apache

The Apache web server is currently the most popular web server in the world, which makes it a great choice for hosting a website.

We can install Apache easily using FreeBSD’s package manager, pkg. A package manager allows us to install most software pain-free from a repository maintained by FreeBSD. You can learn more about how to use pkg here.

To install Apache 2.4 using pkg, use this command: Continue reading How To Install an Apache, MySQL, and PHP (FAMP) Stack on FreeBSD 10.1

How To Install and Manage Ports on FreeBSD 10.1

Introduction

FreeBSD is a powerful operating system capable of functioning in a variety of roles. Part of what makes this operating system an ideal choice in many scenarios is its reputation for flexibility. A large contribution to this reputation comes from FreeBSD’s supported method for installing software from source, known as the ports system.

In this guide, we will discuss some of the benefits of the ports system and will demonstrate how to use it to acquire and manage additional software. We will cover how to install using the make command, how to customize your applications, and how to leverage some common tools to make ports maintenance easier.

Prerequisites

In order to follow along with this guide, you should have access to a FreeBSD 10.1 server and a non-root user account with sudo privileges. This guide can assist you in logging into your FreeBSD server and setting up a reasonable working environment.

Managing Different Types of FreeBSD Software

The FreeBSD team maintains the base FreeBSD operating system as a coherent unit. Its components are updated using a tool called freebsd-update and their behavior is controlled primarily through configuration files located within the /etc directory. While you can install and use alternatives to the bundled software, you cannot easily or safely remove the ones that are included in the base system as these are considered functionally essential parts of the operating system. Continue reading How To Install and Manage Ports on FreeBSD 10.1

How To Manage Packages on FreeBSD 10.1 with Pkg

Introduction

FreeBSD’s binary package manager, pkg, can be used to easily manage the installation of pre-compiled applications, the FreeBSD equivalent Debian and RPM packages. When compared with the other prevalent method of software installation on FreeBSD, compiling ports with the Ports Collection, using packages provides a simpler and faster alternative that works in many situations. Packages, however, are not as flexible as ports because package installations cannot be customized—if you have the need to customize the compilation options of your software installations, use ports instead of packages.

In this tutorial, we will show you how to manage packages on FreeBSD 10.1. This includes installing and deleting packages, among other related tasks.

Prerequisites

To use the commands in this tutorial, you must have root access to a FreeBSD server. That is, you must be able to log in to the server as root or another user that has superuser privileges via the sudo command. If you are planning on using root, you may omit the sudo portion of the example commands. Continue reading How To Manage Packages on FreeBSD 10.1 with Pkg