Cloud Hosting

How to Install CodoForum software on Ubuntu with Nginx

Jason Mazzota December 23, 2015 by under Cloud Hosting 0 Comments
Verified and Tested 12/23/15

Introduction

This walkthrough will take you through a base installation of CodoForum on an Ubuntu server that has Nginx as the web application and MySQL and PHP installed. At this time, the current download of CodoForum is 3.4.build-19 .

Prerequisites

An Ubuntu server with LEMP (Nginx, PHP, and MySQL ) installed. Use our Ubuntu LEMP guide, if needed. We also offer Nginx with Ubuntu as part of our One-Click Applications on our Cloud Service under the application name LEMP Cloud Hosting.  If you do not have a server already, you may try one of our fast SDD Cloud Servers.

Installing CodoForum – Pre-Web Steps

The first step to installing CodoForum by downloading it with the following command:

wget https://bitbucket.org/evnix/codoforum_downloads/downloads/codoforum.v.3.4.build-19.zip

Next we need to unzip the codoforum zip file with the following command:

unzip codoforum.v.3.4.build-19.zip

Move the contents that you extracted from the zip file to your we directory with the following command:

sudo cp -r codoforum/* /usr/share/nginx/html

Note: The above command uses /usr/share/nginx/html which is the default web directory for Nginx on Ubuntu.

Once everything is uploaded, we will now make the web directories are writable by the web server so that CodoForum can install correctly. Do so with the following command:

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

Once this is complete, we will need to create the Database we will be using for CodoForum. It will ask for this in the configuration. In our case, we will use their default database name codoforum. You can use whatever name you like, just be sure to use it later in the configuration.

We will first start off by setting up the database by running the following command:

mysql -u root -p

When prompted, you will need to enter your MySQL password that you created during your LEMP setup. If you installed LEMP via the One Click Application, the motd (message box) upon SSH to the server should contain your MySQL root password.

In MySQL, enter the following commands:

create database codoforum character set utf8 collate utf8_bin;

Set a secure password where it says [insert-password-here]

grant all privileges on codoforum.* to [email protected] identified by '[insert-password-here]';
flush privileges;
exit

 

Installing CodoForum – Web Steps

Now we will go to the web and finish the install. Simply go to your IP address in the browser and navigate to the admin folder. In our case this is http://myIP/codoforum/admin. This will take you to the install process. You may follow the pictures and instructions below.

1. License Agreement. You can hit Next here after reading this if you would like.

Website conf -Page 1-

Website conf -Page 1-

 

2. If the directories are correct you will be brought to the following page. As we have MySQL installed, our Database driver will be MySQL. The Database name will be left as the default codoforum for us but this is where you would put the database name for the database you made earlier on. The Database username will be root unless you have changed this. As this is a basic instruction we will leave this in place. The Database password will be the password for root. The Database host will be localhost unless you have the database on another server. We can make our Admin user. You may use what you’d like for the username, password, and email, however, we recommend using the accurate information here. We will be keeping our username as admin.

anet-codoforum-07

Website conf -Page 1-

 

3. Once you click Submit on the previous page, you should be brought to the below page. The last thing to do is either rename or remove the install directory. In our case, we will be removing it. After it’s been removed, you can either view the site or the backend.

(while still in the /usr/share/nginx/html folder in the SSH session)
rm -rf install
Website conf -Page 3-

Website conf -Page 3-

 

Main site:

Codoforum -Main site-

Codoforum -Main site-

 

Admin page:

Codoforum -Admin site-

Codoforum -Admin site-

 

You have now installed Codoforum and can begin using it/customizing it/creating users and posts. If you want the forum to be able to be accessed quickly, we would recommend creating an A record and handling the redirection via a 301 redirect or .htaccess file. One important thing to remember is that your admin page is:

http://yourServerIP/codoforum/admin/

Also, you may notice that the pictures don’t seem to load for profiles or will have errors. You will need to install the GD extension for PHP to get these working.


How to Install ELK Stack on Debian 8

Eric Izoita December 21, 2015 by under Cloud Hosting 0 Comments

Introduction

The ELK stack is a popular set of tools consisting of Elasticsearch, Logstash, and Kibana. These three tools form a software stack that can function as an extremely powerful centralized network data analytics and server log visualization tool. The ELK stack is also designed to be very capable of scaling out across multiple servers for load balancing. In this how-to we will be installing all components of the ELK stack onto a single server.

Prerequisites

  • A server running Debian 8. If you do not have a server already, Atlantic.net offers reliable cloud hosting servers you can spin up in under 30 seconds.

Other operating systems are supported, but this article concentrates on Debian 8.

Read More


Why Use Symfony? 6 Arguments for Using Symfony PHP Framework, from a Developer’s Perspective

Adnan Raja December 16, 2015 by under Cloud Hosting 0 Comments

Symfony is one of the most popular PHP frameworks, with users including Yahoo and Drupal. What are the advantages and disadvantages of frameworks? What are the particular strengths of Symfony?

  • What is a PHP Framework?
  • Pros & Cons of a Framework vs. Straight Code
  • Why Symfony? (Developer Perspective)
  • 6 Strategic Arguments for Symfony
  • Symfony in Flight

What Is a PHP Framework?

A PHP framework is a library, a structure through which you can create applications. You can access various APIs (application program interfaces) and figure out how you want to organize your app.

Read More


How to upgrade from Fedora 22 to Fedora 23

Michael Douse December 10, 2015 by under Cloud Hosting 0 Comments

Verified and Tested 11/12/15

Introduction

In this article, we will go over how to upgrade Fedora 22 to Fedora 23 utilizing DNF.

Prerequisites

– You will need root privileges.

– A Fedora 22 cloud server.  If you do not already have a server, check out our full line-up of scalable and reliable cloud servers.

Getting Ready

Before we begin, let’s confirm the version of Fedora we are running with the following command:

cat /etc/redhat-release

Your output should look like this:

Fedora release 22 (Twenty Two)

Next we will update the repository metadata and ensure we have the latest package versions on the system:

dnf upgrade -y

Then download and install the Fedora system upgrade tool:

dnf install dnf-plugin-system-upgrade -y

It’s now time to download all the Fedora 23 upgrade packages that we will need for the next step:

 dnf system-upgrade download --releasever=23 -y

If you utilize packages from 3rd party repositories that have not published updates associated with the release, then the upgrade may fail. In this case, you will not be able to continue with the upgrade unless you issue the following command:

dnf system-upgrade download --releasever=23 --allowerasing

*Warning: This will remove the packages that have unsatisfied dependencies. Be sure to review the output to determine which packages will be removed and confirm if it acceptable to you.


Starting The Upgrade

Once the packages have been downloaded, you will be prompted to start the upgrade with the following command:

dnf system-upgrade reboot

The system will now reboot and begin the upgrade. You can monitor the progress from the Cloud Control Panel VNC console. See HERE for instructions on how to access the VNC console. Now just sit back and wait for the upgrade to complete. When it is finished, the system will reboot once more, and you will now be running Fedora 23! You can verify by running the same command as before:

cat /etc/redhat-release

Output:

Fedora release 23 (Twenty Three)

That’s it. Enjoy!


How to Install Webmin on CentOS 6.7

Jason Mazzota December 9, 2015 by under Cloud Hosting 0 Comments
Verified and Tested 12/8/15

Introduction

In this tutorial, we will be instructing you on how to install Webmin, a web-based interface for system administration, on a server running a base CentOS 6.7 server. With Webmin you can setup specified user accounts, web sites through Apache, your DNS locally, and more. Webmin removes the need to manually edit configuration files and lets you manage the system from a GUI (Graphical User Interface.)

Prerequisites

For our tutorial, you will only need to have a server running CentOS 6.7 and access to the Internet. If you do not have a CentOS server, Atlantic.Net offers fast SSD Cloud servers, up in 30 seconds.

Read More


How to: Object-Oriented Programming – More with Classes and Objects

Bjørn Furuknap December 7, 2015 by under Cloud Hosting 0 Comments

Bonus Round

Welcome back to our Introduction to Object-Oriented Programming! Perhaps it would be more appropriate to say, “Welcome to the Bonus Round of our Introduction to Object-Oriented Programming!”. This article and the one that follows it are for those of you who want to learn a little more about some of the foundations of Object Orientation and who enjoy some bonus content!

To review, if you’ve followed along with some of the first five articles in this series, then you’ve learned quite a few things:

This article and the next will take what you’ve learned from that introduction and show you more about how you can use some of the principles of object orientation (often abbreviated OO) to make efficient and well-organized code. We will start with a new program that will allow us to review some basic concepts and lead into some new concepts, such as constructors and inheritance.

Again, we’ll be programming in C# using Microsoft’s Visual Studio. If you’d like to follow along (and haven’t done so already) you can find the setup right here.

If you follow the setup in that article up until the “Under the Hood” section, you’ll be right where we’ll be starting. The only thing I will do differently from that article is that I will not be using the default project name “ConsoleApplication1”. Instead, I will call my project “PettingZoo” (in one word) because we will build a petting zoo as our example program.

Note: Object orientation is available in many languages and platforms, and the concepts are very similar. I have chosen C# because it is easy to get started and all the resources you need are free of charge. You may have other languages and platforms you want to use, and that’s fine, too. We’re here to learn object orientation, not any language or implementation in particular.

.

Initial Setup

Before we begin, verify that you have a console application created in Visual Studio. It should look something like Figure 1.

Figure 1: Initial PettingZoo Program Setup

Figure 1: Initial PettingZoo Program Setup

With this console application available in Visual Studio, we can start creating our first class. In C#, there are multiple ways to create a class. In some languages, such as Java, you need to create classes in specific ways using specific file name and folder patterns, but C# just cares that we say that something is a class.

Note that even in the default console application, you already have one class called Program. Using the keyword class followed by the name of the class is how you define a class in C#.

For our approach, we’ll create a new code file to hold our classes. Right-click on the PettingZoo node in the Solution Explorer pane, and then click Add->Class, as shown in Figure 2.

Figure 2: Adding a Class with Solution Explorer

Figure 2: Adding a Class with Solution Explorer

In the dialog box that opens, find the Code element either by searching or navigating, and call your class file something like Animals.cs, as shown in Figure 3.

Figure 3: Adding Class File Dialog Box

Figure 3: Adding Class File Dialog Box

You should now get a new class file created by Visual Studio that contains something like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PettingZoo
{
    class Animals
    {
    }
}

Note that by default Visual Studio creates both a class file and a class definition within based on the file name you chose. In some languages–like Java–this structure is a requirement, but in C#, it’s not so strict. We will change the class name in a moment, but leave it for now.

In the file Visual Studio just created, you will notice a number of using statements as well as a namespace code block. These lines aren’t important to our class, but–in case you’re curious–a namespace in C# is a way to organize names in your project. You can have multiple classes with the same name, for example, organized under different namespaces.

As long as you work inside a single namespace, addressing classes is fairly straightforward. But if you need to organize your project into more complex divisions, you may need to utilize different namespaces, in which case the using statements allow you to create shortcuts to those namespaces.

.

Classes and Objects

The file you now have contains a premade class with a name based on the filename you chose. We’re not going to have an Animals class, though, so let’s change that to something else. In a petting zoo, we need dogs, of course, so change the name of the class from Animals to Dog:

class Dog
{
}

Note the change from Animals (plural) to Dog (singular). We will create another class later called Animal, so be careful when you read the code that you pick up on nuances like that.

Before we start adding any content to the class, let’s examine the difference between classes and objects. Remember that a class is the template for how objects should be. A simplistic and not terribly accurate analogy is that of a recipe and a cake.

(This section is a review of classes and objects adapted from the explanation presented in the linked article above. If you want to skip this refresher and get straight to the programming, jump right to the next section! Otherwise, enjoy some cake!)

The recipe tells you how to make a cake and is thus–in OO terms–a class. A cake is the result of the recipe execution and–again, in OO terms–is an object. Another term used frequently is instance, to indicate that the cake is an instance of the execution of a recipe.

As with cakes and recipes, each cake is a unique cake. What you do to one cake does not affect any other cakes. Putting frosting on one cupcake doesn’t mean all cupcakes now have frosting. Similarly, if you eat one cupcake, you still have all the others left.

However, having a recipe and knowing it produces a cake isn’t enough. You also need a kitchen in which to bake the cake. In OO terms, this is the program where you create the object, and in our case, that would be the main Program.cs file.

.

Back to the PettingZoo

Let’s use our new class to create a Dog object, so open the Program.cs file and add the following line inside the static void main code block:

Dog myDog = new Dog();

This line will create a new Dog object from the Dog class and store it in the myDog variable. Let me break this line down into three parts so I can explain what goes on.

[1]Dog [2]myDog = [3]new Dog();

The first element [1], Dog, is the type of variable we want to create. In statically typed languages like C# and Java, we need to declare what type a variable is before we can assign values to it. Languages that are dynamically typed, like JavaScript or Perl, does not require this and puts the responsibility of tracking what type of data a variable contains on the developer.

The second element [2], myDog, is the variable name we use to access the object. This is not necessarily the name of the dog we create but rather what we use to reference this particular instance of a Dog class.

Note: For more on variables and data types like string, check out our introduction to programming article on variables and types.

.
Finally, the third element [3], new Dog(), tells us that we want to create–or instantiate–a new object based on the Dog class. Notice that there are parentheses after the class name, which means this is actually a method. We’ll get back to this method, which is a special method called a constructor (we’ll go deeper into constructors in the next article linked below).

With our program now creating a new object from the Dog class that it stores in the myDog variable, we can start accessing the properties and method of our object. Except, of course, that our class is completely empty and devoid of content! Let’s fix that.
.

Properties and Methods

Let’s go back to our Animals.cs file, where our Dog class has a name but nothing else. However, everything we put inside this code block will become part of the class definition. Remember, classes have properties and methods that define, respectively, what an object is and what it can do.

Let’s create both a property and a method, and then we’ll discuss what each does. Inside your code block’s curly brackets, {}, add the following two lines:

string Name;
void Speak() { Console.WriteLine("Woof"); }

The first line (string Name;) is a property or field. In object orientation, properties define what something is. In our case, we want our dog to have a name, so we have created a string property to hold the name of the dog.

Remember that object orientation seeks to create programmatic representations of real objects. Of course, a name alone does not make a dog, but OO does not seek to duplicate all properties of every object, just those we need. We will add more properties later.

The second line is a method definition (or method signature) and is a bit more complex, so, just like before, let me break it up a bit and show you what each element does.

[1]void [2]Speak() [3]{ Console.WriteLine("Woof"); }

Element [1], void, is the return type of the method, or the type of output that the method will yield when it is executed. In statically typed languages like C# and Java, in addition to declaring variable types, we must always declare what type of data we return from methods. Dynamically typed languages leave the responsibility of determining what comes out of a method to the developer.

In our case, at least initially, we just want the dog to say “Woof” when we ask it to speak, so we don’t need to return anything. This will change later, when we cover inheritance in the next article.

However, even though we don’t want to return any specific value, we still need to be explicit about it in the program. To do so, we can declare that the method returns a void value, which in C# and similar languages means that we’re not returning anything.

Element [2], Speak(), is the method name, and it is what we use to call or execute the method. Note that methods, like properties, belong to the object.

Element [3], the code block, is the code that the program will execute when we call the method. You may also see this sort of code block also called the method body. Right now, within this code block, we’ll just tell the console to write a line containing “Woof”.
.

Making Your Method Public

Now that we have a method, we can call or execute it from our program and have the dog bark. There’s a problem, however, which gives me a great opportunity to review another of the key concepts of object orientation.

Normally, to access properties and methods of an object, you would first write the name of the variable holding your object and then the name of your property or method. For example, to get the value of the Name string property, you could write:

string dogName = myDog.Name;

To execute the Speak() method, you could then write:

myDog.Speak();

However, if you do this in Program.cs, you will get an error message like shown in Figure 4.

Figure 4: Protection Level Error

Figure 4: Protection Level Error

The error, stating “’PettingZoo.Dog.Speak()’ is inaccessible due to its protection level” happens because of a key concept in OO called abstraction.

In short, abstraction takes away the details of how something works when we don’t need to know those details. In our program, we only need to know that the dog can speak, but do not really care about how it does it.

Abstraction instead allows the class designer to come up with access points into the class through which they can work with the objects. Many languages enable this access through access modifiers.

C#, by default, hides properties and methods from outside of the class. The policy on this sort of separation differs in other languages, though, and some languages like JavaScript do not even offer this level of protection.

However, the principle remains that you make public what you want everyone to use and hide the rest. The making public part, in C# at least, simply means adding the keyword public in front of the properties and methods you want someone to access. So, if you update the Dog class to add public in front of the void Speak() line in Animals.cs, the red squigglies go away in Program.cs, as shown in Figure 5.

Figure 5: Public Method Declaration

Figure 5: Public Method Declaration

As an added bonus, when you make your method public, Visual Studio will add the method to the available options through the IntelliSense autocomplete system. When you type myDog and hit the period, you get a list of all public properties and methods of that object, as shown in Figure 6.

Figure 6: Visual Studio Intellisense Auto-Complete with Our New Public Method

Figure 6: Visual Studio Intellisense Auto-Complete with Our New Public Method

Other code editors have similar auto-complete systems. These auto-completes are one of the main benefits of these editors for programmers: you’ll learn to love these features as you evolve as a programmer!

.
Now that we have fixed all the errors, we should be able to run our program and see that the dog barks. You can place a breakpoint in your Program.cs by clicking in the left margin or placing your cursor on the bracket after myDog.Speak() and hitting F9. Then, hit F5 to run the program. You should see the console pop up, and the output from your dog barking should appear, as shown in Figure 7.

Figure 7: Our Dog Speaks!

Figure 7: Our Dog Speaks!

Of course, now we can create a litter of dogs by creating multiple variables and instantiating objects into them. You can try something like Figure 8, for example:

Figure 8: Two Dogs Speaking

Figure 8: Two Dogs Speaking

Got a similar result? Great, pat yourself on the back, but only once, because we still have more work to do. After all, we’ve been promising that object orientation allows us to create unique objects, and all we’ve done is create two identical “dogs”. Next, we’ll show you how to use constructors to create separate and unique objects.
.
.


How to : Object-Oriented Programming – Constructors and Inheritance

Bjørn Furuknap December 4, 2015 by under Cloud Hosting 0 Comments

Previously

We have almost reached the end of our journey through this bonus round of our Introduction to Object-Oriented Programming! In our last article, we started our Petting Zoo example with a review of classes, objects, and methods. If you missed the beginning of this series, you can catch back up with us here. Otherwise, let’s dive back in!
.

Constructors

If you did the exercise with two Dog objects, it was a bit boring, right? After all, we have nothing to separate the dogs from each other and no way of knowing, without looking at the source code, which dog produced which bark.

In the previous article, I mentioned that when you create objects, you call a special method called a constructor. The constructor looks like the class name written as a method. For example, for a Dog class, the constructor would be called Dog().

The special thing about constructors is that they are the path to any new object, so they are a great place to call code that initializes an object with default values. Further, the return value from a constructor method is always an object of the class itself, which is why we can assign the return value of the constructor to a variable of the type of class we create.

However, so far, we have not actually created a constructor at all, so how come we can still call that method?

In many languages, C# included, the language gives you a free and empty constructor without you having to do anything. It is implied that you want a constructor; otherwise there would be no way of using the class for anything, so the languages just assume that you have written one.

This invisible and free constructor is called the default constructor, and, in our example, it will look like this:

public Dog(){ }

Notice that this syntax is very similar to the Speak() method we created earlier, except that we do not explicitly return a value nor do we even declare the return type of the method. As I mentioned earlier, a constructor always returns an instance of the class to which it belongs.

In this case, that is the class Dog, and that is why when we write Dog myDog = new Dog(), we can assign the new object to a variable named myDog which is of type Dog.

So let’s add the default constructor to our Dog class. You can either copy the line above or, in Visual Studio, you can use a shortcut: type ctor and hit Tab twice. It should generate the default constructor for you, as shown in Figure 9:

Figure 9: Adding a Constructor with 'ctor'

Figure 9: Adding a Constructor with ‘ctor’

The default constructor doesn’t actually give us anything new because it is now explicitly doing what was done implicitly before. However, it is a method, so we can now add content inside the brackets that will execute whenever we call this constructor. And because the constructor runs as the very first thing in an object’s construction, it is a perfect place to add initialization code.

For example, we could set the Name property of our objects to something by adding code such as this:

public Dog()
{
    this.Name = "Snoopy";
}

This example will set the Name property of any new objects to “Snoopy”.

Of course, that’s not very useful because not all dogs are called “Snoopy”, so instead, let us change the method signature of the constructor so that it accepts a parameter.

The parentheses of methods aren’t just there to look pretty; they serve to contain parameters that we can use to pass values to a method. This function applies to all methods, not just constructors, but let’s do it for a constructor first.

Change the default constructor signature to this:

public Dog(string dogName)

This addition allows us to send a string parameter into the constructor, and that when we do, we can refer to that parameter by the name dogName.

Then, add the following line to the method block:

this.Name = dogName;

This line sets this object’s property Name to the parameter we sent into the constructor.

Note that when you change the constructor’s signature, you get a case of the red squigglies in your Program.cs file, as shown in Figure 10.

Figure 10: A Case of the Red Squigglies from Our New Constructor

Figure 10: A Case of the Red Squigglies from Our New Constructor

When we add our own explicit constructors, C# and .NET will not implicitly create a default constructor for us. In our Program.cs file, we are still creating the Dog objects using the default parameter-less constructor, which now no longer exists.

To fix this problem, we need to add a parameter to our constructor call in Program.cs. We can, for example, update our object construction line as such:

Dog myDog = new Dog(“Snoopy”);

Doing so will remove the red squigglies and allow you to run the code again. If you leave or set your breakpoint after the last code line, you can look at the Locals panel and verify that your object’s Name property has indeed been set, as shown in Figure 11.

Figure 11: Seeing our Name Property Set Correctly

Figure 11: Seeing our Name Property Set Correctly

Got it? Good! We now have the ability to name our dog, but it isn’t really a useful program if people have to debug it to see what we’re doing. So let’s mix up the code a bit to make sure that we display the name of the dog that is barking.

Update your Dog objects and change the Speak() method as such:

public void Speak() { Console.WriteLine(this.Name + " says: Woof"); }

The change we have made now tells the WriteLine method to concatenate the name of this object with the literal string “ says: Woof” which should give us output that better displays our efforts. Try running the program now, and you should see something resembling Figure 12.

Figure 12: Snoopy Says: Woof

Figure 12: Snoopy Says: Woof

Nice work! You can now create many dogs with different names, and they will all bark at your command.

Of course, a petting zoo with only dogs is somewhat boring. I mean, I love dogs, but maybe we could add some additional animals to spice up the experience a bit?
.

Inheritance

Let’s start out by adding a new Cat class to our Animals.cs file. Add the following code next to the Dog class, but still inside the PettingZoo namespace brackets:

class Cat
{
    public Cat(string catName)
    {
        this.Name = catName;
    }
    string Name;
    public void Speak() { Console.WriteLine(this.Name + " says: Meow!"); }
}

Then, let’s create a Cat object in Program.cs and have it speak:

Cat myCat = new Cat("Garfield");
myCat.Speak();

Running this program now should give you output resembling Figure 13.

Figure 13: Garfield Says: Meow

Figure 13: Garfield Says: Meow

Our program is predictable and works, but did you notice how similar the two classes really are? See how much code we’ve duplicated across the two classes? Wasn’t object orientation supposed to save us from writing code multiple times?

The answer is yes. We can–and should–simplify this code to reduce the amount of duplication. What we are about to go into will demonstrate a feature of OO called inheritance.

Inheritance in object orientation allows you to create a hierarchy of classes and have each class inherit the properties and methods of a parent class. For example, for our petting zoo, we can create a parent Animal class and have Dog and Cat inherit from that class. Then, we can move parts of our code into the Animal class so that both the Dog and Cat classes will inherit that code.

If, however, we move the duplicate parts of our code to this Animal class, then the Dog and Cat classes would each inherit the same properties and methods, making the children clones of the parent classes. This organization isn’t very useful because we want to have distinct types of animals. It would be terribly boring if cats, dogs, and all other animals were the same. In fact, for the purposes of our program, it wouldn’t make sense to call them different things at all.

Now, if inheritance meant that we could only create child classes that were identical to their parent classes, there wouldn’t be much point to going to all of this effort. So while we inherit all parts of a parent class, we can also override certain parts of a parent class in the child classes to make the child classes distinct.

Let’s go through this and see how it works, shall we?
.

Creating Parent and Child Classes

We’re going to take a few steps back and recreate the Dog and Cat classes in a better way. To start off, we need a parent class that will define the shared properties and methods of the child classes.

In your Animals.cs file, remove the Dog and Cat classes and add the following class definition:

class Animal
{
    public string Name;
    public string Sound;
    public void Speak() { Console.WriteLine(this.Name + " says " + this.Sound); }
}

This class looks unsurprisingly like the previous Dog and Cat classes, with the noted exceptions that we have made all properties and methods public and that we have introduced a new property called Sound of type string. Finally, we have updated the Speak method to use the Sound variable.

At this point, your Program.cs will not work and, if you click on that tab, you should see several error messages, which is only natural because we have removed the Cat and Dog classes. Let’s recreate them and do so using inheritance. In your Animals.cs file, right after the Animal class, add the following code:

class Dog : Animal { }
class Cat : Animal { }

These new classes are much shorter than before and do not replicate any code. The new syntax here is a colon followed by the class name Animal, which tells C# that we want both Dog and Cat to inherit from the Animal class. In effect, Dog and Cat become child classes of Animal as illustrated in the diagram shown in Figure 14.

Figure 14: Diagram of Animal Class Inheritance

Figure 14: Diagram of Animal Class Inheritance

Note: I’ve been using the term Property so far, which is slightly inaccurate because the correct term is field as you can see in the diagram in Figure 14. Field is less clear outside the scope of programming, however, so I have used Property instead. Technically, a property is a wrapper around a field in C#.

.
We still have a problem with our Program.cs file, though, because of the custom constructor we created. If you try to run or debug our program, then you should see an error message saying that “‘PettingZoo.Cat’ does not contain a constructor that takes 1 arguments” and similar one for “PettingZoo.Dog”.

To fix this error., we need to add the constructors back in. This time, though, we’re going to utilize inheritance to inherit the constructor and show how you can extend the constructor to change the functionality of a parent class.

First, we need to create a base constructor for Animal, which will resemble the previous constructors we created earlier. Add the following code to your Animal class:

public Animal(string animalName)
{
    this.Name = animalName;
}

As before, our constructor sets the name of the animal to what we pass into it. However, this isn’t enough because we also need to add a constructor to both the Dog and Cat classes. We will use this to define which sound each animal makes too.

class Dog : Animal
{
    public Dog(string dogName) : base(dogName)
    {
        this.Sound = "Woof";
    }
}
class Cat : Animal
{
    public Cat(string catName) : base(catName)
    {
        this.Sound = "Meow";
    }
}

For both classes, we add a constructor that accepts a Name parameter. We also set this object’s Sound property to the sound we want the animal to make.

However, unlike before, we now call the parent class constructor and pass in the Name parameter from the parent constructor. This call comes through the : base() method and by adding the received dogName or catName parameters inside the parentheses.

Note: This : base() syntax is unique to constructors. We will see other ways of changing or extending case functionality later.

.
With these updates to our code, we can now run our program again and see a result similar to Figure 15.

Figure 15: Animals Speak, Using Inheritance

Figure 15: Animals Speak, Using Inheritance

Note that we have neither a Sound nor a Name property defined in either the Dog or Cat classes. We also do not we have a Speak() method. Instead, they reside in the parent Animal class, and the Dog and Cat classes inherit these properties and methods.

We can similarly create other classes now, for any type of animal and we will only need to replicate the pattern of the Dog and Cat classes. For example, we might create these classes:

class Parrot : Animal
{
    public Parrot(string parrotName)
        : base(parrotName)
    {
        this.Sound = "I want a cracker!";
    }
}
class Pig : Animal
{
    public Pig(string pigName)
        : base(pigName)
    {
        this.Sound = "Oink";
    }
}

Then, we can instantiate these classes in Program.cs:

Parrot myParrot = new Parrot("Polly");
myParrot.Speak();

Pig myPig = new Pig("Bacon");
myPig.Speak();

Now we will have a veritable zoo on our hands when we run the program, as shown in Figure 16.

Figure 16: A Zoo of Four Animals Speaking

Figure 16: A Zoo of Four Animals Speaking

You could create further sub-child classes of existing child classes, too. For example, you might separate the Dog class into Beagle and Pointer or have the Parrot class inherit from a parent Bird class that, in turn, inherits from Animal. Creating this sort of hierarchy is beyond the scope of this article, however, so let’s move on and finally look at how we can override, change, or extend the functionality of parent classes in child classes.
.

Modifying Inheritance

We can change the method of a parent class by using a technique called overriding. The syntax for overriding may differ between languages, but the principle of changing the parent’s method in the child class remains the same.

In C#, we add the keyword override followed by the method signature you want to override. We also must declare in the parent class that we are allowing children to override the methods by adding the virtual keyword to the method signature in the parent class. (Other languages may not require this additional indication.)

In our program, we need to update the Speak() method in the Animal class.

public virtual void Speak() { Console.WriteLine(this.Name + " says " + this.Sound); }

Now we can insert our override of the Speak() method in the Dog class at the beginning of our code block for this class.

class Dog : Animal
{
    public override void Speak()
    {
        base.Speak();
        Console.WriteLine("...and then runs around, chasing his tail");
    }
[remaining code omitted]

This code tells us that we want to override what happens in the parent method Speak(). We will still execute the parent method using the base.Speak() call before we output an extra line right afterwards.

Why would you want to do so? Well, perhaps we want our dogs to be as enthusiastic as they can be in person. Run the program and see for yourself:

Figure 17: Our Dog Overrides His Class Method

Figure 17: Our Dog Overrides His Class Method

First, Snoopy barks as normal: the base.Speak() method calls the Speak() method from the parent Animal class. Then the rest of the code outputs a second line to the console. Effectively, we extend the parent class by adding new functionality to the child class only. See how the Cat class is unaffected.

Of course, cats are notoriously difficult to get to do as you wish, so let’s reflect that in code. Update the Cat class and add the following method override, similar to the Dog class.

class Cat : Animal
{
    public override void Speak()
    {
        Console.WriteLine(Name + " doesn't speak but just sits there wondering when you will feed it.");
    }
[remaining code omitted]

Unlike what we did in the Dog override, we do not call the base.Speak() method this time. Without that call, we never execute the Animal Speak() method and completely change what happens in this method. See for yourself:

Figure 18: Our Cat Also Overrides His Class Method

Figure 18: Our Cat Also Overrides His Class Method

Also notice that as we have rebuilt our classes, we have not changed the Program.cs code. These changes serve as a good example of why object orientation is a very powerful technique; we have completely changed the underlying code without touching the program that uses that code. [Object orientation has allowed us to isolate many of the implementation details and simply expose a small set of interface with which the program needs to interact.]

Where We Bent the Rules

Before we wrap up, I want to point out a few things, chiefly some “bad” things we have done.

First, in our classes, we call the Console.WriteLine() method directly. This usage is not a good design decision because classes should be independent of how we output the results of the classes.

A better approach would be to return data from the classes instead and then output that as part of the program. We would then allow the program to decide what to do with the output rather than the classes, allowing us to use the same classes across many different types of programs, whether they are web pages, Windows Forms, QT, or Console applications.

Second, in our later examples, all the properties were public. Making these properties public weakens the security aspect of object orientation, where we seek to protect the data in the classes from manipulation from the outside. However, protection of properties and methods quickly becomes complex when you are dealing with inheritance so I wanted to avoid that complication, at least at this introductory stage.

Finally, there’s really no point in having Sound set as part of the child constructor at all because we were duplicating that code, too. It would be a better design to create a constructor in the parent class that accepted both a name and a sound, and then just calling that as part of the child constructor. However, again, for the sake of simplicity, I didn’t want to introduce differing constructor signatures at this stage.

So, while we’ve learned a lot in this bonus tutorial, you can see there’s still more to learn. Don’t worry too much about it just yet, however. You can take a moment to congratulate yourself on having followed along all the way. If you have followed all the steps, you have learned:

  • Why we use object orientation
  • How to create classes
  • How to create properties and methods
  • How to create constructors and what they do
  • How to take advantage of inheritance and why it’s a powerful feature of object orientation

I hope you enjoyed this extra lesson and are interested in exploring more. Be sure to check back with us for new content on the Atlantic.Net blog, and consider one our industry-leading cloud hosting servers.
.


How to Install ownCloud on CentOS 7

Paul Figuenick December 2, 2015 by under Cloud Hosting 0 Comments

Introduction

In this article, we will go over how to install ownCloud on your very own CentOS 7 cloud server.

What is ownCloud you ask?  It is a self-hosted file sync and share server similar to Dropbox but instead of hosting files off of servers administered by another company, everything is hosted on your server. It lets you store your files, folders, contacts, photo galleries, calendars and more on your personal server.  There are many other features, such as WebDAV, sharing your files with anyone, syncing all files across mobile and desktop devices just to name a few.

Prerequisites

You need a CentOS 7 server that is configured with a public IP address. If you do not have a server already, consider our reliable and cheap Cloud hosting and spin a new server up in under 30 seconds.

Steps To Install ownCloud

First we must install Wget.

yum install wget -y

Then we must add the EPEL repository to CentOS 7.  EPEL stands for Extra Packages for Enterprise Linux and is a repository from the Fedora team that are high quality add on packages.   This is done with the following commands.

Before adding the repository, we must trust it by importing the key for it, and the following command does so.

rpm --import https://download.owncloud.org/download/repositories/stable/CentOS_7/repodata/repomd.xml.key

Next we add the EPEL repository.

rpm -Uhv http://dl.fedoraproject.org/pub/epel/7/$(uname -i)/e/epel-release-7-5.noarch.rpm
wget http://download.owncloud.org/download/repositories/stable/CentOS_7/ce:stable.repo -O /etc/yum.repos.d/ce:stable.repo
yum clean expire-cache

Now we install ownCloud.

yum install owncloud -y

Your ownCloud server is now installed.  To finish setup, you will need to setup your Administrator account which is done by going to your server IP address followed by /owncloud .  For example http://ipaddress/owncloud .  You will use this to access your server via the web portal.  Once created, you will come to this screen that is where you administer you ownCloud.

ownCloud

A few things that you can do from here are creating folders, upload files to share across the internet, and creating links to said files.  You can also download ownCloud clients for Windows, OSX, Linux, Android, iPhone, and iPad.

App

You can also enable built-in apps that allow you to do such things as setup a photo gallery, add a music player/server for your music you uploaded, and a RSS/Atom news reader to name a few.

App

Congratulations on your newly setup ownCloud server!  Have fun and happy filesharing!


How to: Getting Started with Ansible

Atlantic.Net NOC November 30, 2015 by under Cloud Hosting 0 Comments

Introduction

Ansible is a system administration tool that allows for the administration of multiple devices from one central device. It compares to tools like Puppet or Chef, but whereas those packages require the installation of agents on the client systems, Ansible operates by passing commands over ssh without the need for agents at all. We’ll take a look at some of the administrative tasks Ansible is capable of so you can get a better idea of whether Ansible might be right for you.
.

Prerequisites

  • A Linux, BSD, or OSX control device.
  • ssh access (firewall and credentials) to client devices from your control device. Ansible prefers the use of ssh keys to access client devices, but we’ll also show you options using username and password.
  • Python 2.6 or 2.7 installed on the control device.

.

Installation

Ansible is available via the package managers from the major Linux/BSD/OSX distributions. It’s also available via Python’s pip installer.

CentOS/Fedora:

sudo yum install ansible

Ubuntu (you’ll need to add the Ansible PPA first):

sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible

Arch Linux:

pacman -S ansible

FreeBSD:

sudo pkg install ansible

Python package manager, pip (OSX users can install with pip as well):

sudo pip install ansible

Setting up Access to Ansible Clients

Hosts

One of the benefits of using Ansible is the ability to manage multiple clients from one control device–from the same terminal interface. You can specify various groups of client servers based on function, location, and/or OS by creating groups in the /etc/ansible/hosts file.

[mailservers]
smtp.orl-fl.example.com
smtp.dal-tx.example.com

[db_servers]
db.orl-fl.example.com
db.sfo-ca.example.com

[orlando]
smtp.orl-fl.example.com
db.orl-fl.examle.com

[nameservers]
ns[01:12].example.com

A name enclosed in square brackets [] defines a group name and includes hosts in the list that follows it. You may also indicate a sequential range within a hostname pattern with square brackets and a colon, as in ns[01:12].example.com above.

A client may exist in multiple groups. The group name works as an alias for the group list, making it easier to reference which group of servers you will be targeting with your particular Ansible command or playbook.
.

ssh Keys

Ansible works best when your control server–the one from which you’ll be running your Ansible commands–can use ssh keys to access client hosts. When you run an Ansible command without additional options, it defaults to attempting to access remote clients via ssh keys.

Tip: If you have secured your private ssh key with a passphrase, it can be inconvenient and inefficient to have to enter that passphrase each time you need to decrypt it for each ssh session you’ll be opening with Ansible. To simplify this process, open a separate shell with ssh-agent. When you import a private key into this shell, you only have to enter your passphrase once to add the unencrypted private key.

ssh-agent bash
ssh-add ~/.ssh/id_rsa

The first command opens a new bash shell. The ssh-add command will prompt you for your private key’s passphrase and then imports the RSA private key into this shell. You may, of course, substitute the appropriate private key, if using id_ecdsa or id_dsa, for example.

.

.

ssh Access (Without ssh Keys)

If you have client servers that don’t have ssh keys set up, you can still use Ansible with your current user and prompt for your user password. For example, we might want to use the ping module to verify that all of our hosts in the db_servers group are responsive.

ansible db_servers -m ping --ask-pass

This command will first prompt for the current user’s ssh password to use to access all servers in the db_servers group before running the module on each client.

Note: This command will require that your user exists on each client, is allowed ssh access, and uses the same password.

Also, the ping module isn’t related to the ICMP ping that tests network connectivity. Its use with the ansible command verifies that a client server is accessible with the indicated user and that the client server has a version of Python that Ansible can work with. The ping module should return a pong response upon successful completion..

.

ssh Access (With Password)

Default Ansible commands also presume that, in addition to using ssh keys, you are using passwordless sudo. If you have client servers that that require a password to obtain sudo access, you can use additional options to become sudo and prompt for a sudo password. So, for example, to reboot all servers in the mailservers group using the username username.

ansible mailservers -a "/sbin/reboot" -u username --become --ask-become-pass

The --become option indicates that the user will become a privileged user (sudo), and the --ask-become-pass option prompts Ansible to ask for the password to become that privileged user before executing the command.

The --become and --ask-become-pass options are newer options (as of Ansible version 1.9) meant to replace the older --sudo and --ask-sudo-pass (-K) options, respectively. These older versions still work. The replacement of sudo for become broadens the scope of these options to include integration with tools that use means other than sudo to enable privilege escalation.

.

Some Basic Ansible CLI Commands

While the real power of Ansible lies in the use of playbooks, you can also run the ansible command to do some quick client management for instances where it doesn’t make sense to create a playbook or where you might need to only push a single command to a group of client devices.

The ansible command follows the pattern ansible [group] OPTIONS.
.

Run Yum Updates

If, for example, you would like to run yum updates on the servers in your mailservers group, you could accomplish this task with the following Ansible command:

ansible mailservers -m yum -a "name=* state=latest" --become

This command updates all servers in the mailservers group with the yum module (-m). The -a option indicates a particular argument in double quotes–in this case, updating all installed packages (using the * wildcard) to their latest state.
.

Copy File to Clients

You can use Ansible to distribute a file to a group of client servers.

ansible orlando -m copy -a "src=/home/scripts/foo.sh dest=/opt/scripts/foo.sh"

This command invokes the copy module and indicates the src (source) and dest (destination) in quotes for the arguments. The source location defaults to the device that this Ansible command is running on and can be absolute or relative. The destination location is the location on the remote client device and must always be absolute.

You may also use the copy module to further refine the attributes of the file you are copying over.

ansible orlando -m copy -a "src=/home/scripts/foo.sh dest=/opt/scripts/foo.sh owner=foo group=bar mode=0755"

This command additionally changes the owner, group, and file permissions of the file on each client in the orlando group.
.

Execute Shell Command

You may also execute a script on each client with the shell module.

ansible orlando -m shell -a '/opt/scripts/foo.sh >> /home/foo/bar.txt' 

This command would execute the foo.sh script and redirect its output to the /home/foo/bar.txt file. Note the single quotes here. You’ll need single quotes instead of double so that you can pass the >> operator to the remote shell.
.

An Ansible Amuse-Bouche

There are many more commands and modules you can use, but this sampling should provide a good introduction to how useful Ansible can be if you manage even just a small number of servers. If you find yourself in the sometimes unenviable position of having to perform repetitive tasks across your server infrastructure, we hope these examples have given you a taste of how Ansible might help you to work smarter (and more efficiently!).

Please be sure to check back with us in the future for more articles on server administration and other things you can do with Ansible.  Atlantic.Net offers a broad collection of flexible cloud hosting solutions for a small start-up to a well established enterprise company.
.
.


How to: Socket Programming in Python

Wolfram Donat November 24, 2015 by under Cloud Hosting 0 Comments

Introduction

Network and communication programming are particularly powerful uses of any programming language. It is much more common these days for computers to interface with one another (or with an entire network, such as the Internet) than it is for a machine to act alone, and knowing exactly how that communication takes place is an important skill for any programmer. If you happen to be a Python aficionado, you may be aware that Python has several complete libraries designed to make network programming simple.
.

Prerequisites

  • Any version of Python (See our Guide for installing Python 2.7 in Centos)
  • Basic understanding of Python

Read More


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources

We use cookies for advertising, social media and analytics purposes. Read about how we use cookies in our updated Privacy Policy. If you continue to use this site, you consent to our use of cookies and our Privacy Policy.