Home / Cloud Hosting / How to build your own cloud file storage

How to build your own cloud file storage

Are you sick of iCloud, Dropbox, Google Drive and One Drive holding all your information and thinking about having your own file storage system, where you control the data? This is where you need to be. This article is a step by step tutorial on how to setup your own VPS (Virtual Private Server) for web access and install your own cloud system.

For this tutorial I will just focus on using a Linux based VPS with OpenVZ, I will also be using Windows OS to connect to it.

This is a bit of work, so if you’re not the most computer savvy person, then you might want to bookmark this article and pass it onto someone else to build it for you. You are very welcome to follow it and learn something new, which I encourage.

The duration of this tutorial is around 30 minutes.

Get a VPS Account

First thing is you’re going to need a VPS to set this cloud system up. If you’re a business or have a dedicated internet connection that is solid, you can also just build one using a computer. As mentioned this is focused just on setting up OwnCloud onto a VPS.

The VPS I’m using have the following specs:

  • 2 Core CPU
  • 2GB of RAM
  • 25GB HDD on a SSD with RAID-10
  • 1.5 TB bandwidth allowance per month

You can get that VPS here – $11.99/month or $88.99/year USD. They do have a cheaper option that will also work quite well with what we are doing here. It really depends on how much space you want. Their cheapest option is $4.99 a month or $52.99 a year with 10GB space.

Please note that I have chosen this server because they have DdoS protection and run on SSD RAID-10, which is fast. They also run daily backups and will ignore any DMCA requests received if your’e sharing files amongst friends.
Once you register your new VPS, the admin will need to approve your service, which is almost instant. You’ll get an email with your details. The information you will need to look at is the SSH Access information. We’ll be using a program called PuTTY to connect to your server. You can download PuTTY here: http://www.putty.org/

You will need to put your new VPS IP address into PuTTY (where I’ve highlighted yellow in the picture) and click Open. A unix console will open up – similar to MS DOS – and you just need to put in root as your username and your password in the email sent to you.

If you’re having problems connecting, then login into your Virtualizor panel and install Ubuntu or Reboot the system. Your login details will be the servers IP http URL with the port 4082 at the end.

 

Installing Apache, PHP5 and MySQL

Once you’re in then we can get down to setting up your VPS with Apache, PHP5 and MySQL.

1) First you will need to update and upgrade. You can do this very easily and watch the console work it’s magic.

apt-get update

apt-get upgrade

2) Once all that is done, you can install Apache if needed. If you seen apache2 stoppping and starting during the upgrade, then you already have it. You can try and install anyway, but the best way to know is open the IP of your server in a web browser and if a default apache page loads, you have it.

apt-get install apache2

3) When that’s finished you’ll need to Install PHP5.

apt-get install php5 php5-mysql

4) Then type the following to install the required PHP modules we will be needing.

apt-get install php5-gd php5-json php5-curl php5-intl php5-mcrypt php5-imagick

5) Final install is the MySQL database.

apt-get install mysql-server

Put in a password when requested.

Well done, you’ve taken the first steps to creating a web server from a VPS account. Follow the next steps to get it all going.

 

Setting up MySQL and preparing for install

6) You’re going to need to run a script now, so type in:

sudo mysql_secure_installation

This is what you’ll need to select

  • Set root password? [Y/n] n (you put one in when you installed mysql-server)
  • Remove anonymous users? [Y/n] y
  • Disallow root login remotely? [Y/n] y
  • Remove test database and access to it? [Y/n] y
  • Reload privilege tables now? [Y/n] y

 

7) The latest stable version at the time this article was created is 7.0.2, so we will download that to the servers root directory.

wget https://download.owncloud.org/community/owncloud-7.0.2.tar.bz2

8) Now unpack the archive file to html folder.

tar -xvf owncloud-7.0.2.tar.bz2 -C /var/www/html

9) Now you can navigate to your html folder to see if everything is there. You will see a folder called /owncloud/ if you did it correctly.

cd /

cd var/www/html

dir

10) We need to change ownership of the folder OwnCloud before we move on, so type this into the console.

chown www-data:www-data -R /var/www/html/owncloud/

11) Now we are going to create a database and username within mysql. You need to login to your MySQL area from the console and create a username and database for OwnCloud to attach itself to. This is easy.

mysql –u root –p

Enter your root password you created from the previous section.

NOTE: You can make username1 and database1 whatever you want, also PASSWORD is where you should make up an actual password.

mysql> CREATE USER 'username1'@'localhost' IDENTIFIED BY 'PASSWORD';

mysql> CREATE DATABASE database1;

mysql> GRANT ALL ON database1.* TO 'username1'@'localhost';

mysql> FLUSH PRIVILEGES;

mysql> exit

Now just restart apache so the modules load an you’re good to move onto the installation.

service apache2 restart

Done, you’ve setup a username, password and database. You’ve done all the hard work now.

 

Install OwnCloud on your VPS

13) You’re almost done. Just open up your web browser now and put in http://YOURIP/owncloud to install the program. YOURIP is the same IP you logged into PuTTY with.

Now install OwnCloud! It’s pretty easy, just make up an admin username and password, put in the MySQL information from above.

Now you should be able to login using your username and password. Install the apps for desktop and your phone then follow the instructions from there.

You will get a message saying “Your data directory and your files are probably accessible from the internet.” so you’re going to need to move onto the next step to secure your data.

 

Extra Security for OwnCloud

Now we’re going to fix that error and make OwnCloud files more secure. To do this we’re going to need to log back in to the server using PuTTY.

14) Firstly we need to just check your configuration file.

cd /

cd var/www/html/owncloud/config

vi config.php

You should see the data directory path in here, mine looks like this ‘datadirectory’ => ‘/var/www/html/owncloud/data’, which is the path we’re going to change soon. Before we do this, we need to stop the web server and create a directory/path. To exit out of vi type :q!

15) To stop the server we need to just stop apache2

cd /

/etc/init.d/apache2 stop

16) I’m going to put my data into a folder called media, this is how I would do it.

cd media

mkdir cloudx

I’ve just created a folder called cloudx and now I’m going to move the ownlcloud/data file into there. Note: My new data pathway is going to be /media/cloudx/data.

mv /var/www/html/owncloud/data /media/cloudx/

17) Now we can edit the config file to our new path.

cd var/www/html/owncloud/config

vi config.php

Press i to edit the file and type normally. The change the path, mine would look like this datadirectory’ => ‘/media/cloudx/data’, Press ESC to exit edit mode then quit and save by typing :wq and pressing enter.

18) Now we can start apcahe up again and test if everything works.

/etc/init.d/apache2 start

19) Now lets check. Go to your owncloud home page, login and create a new text file called helloserver.txt. When you’re done come back to SSH and see if it exists.

cd /

cd /media/cloudx/data/admin/files

dir

If you can see your file, then you’ve done it!

You can now download the phone apps and start adding data to your cloud.

 

Tidy things up!

20) If you want to get technical now, then I suggest you enable the .htaccess file usage and do a ModRewrite for the index.php file. You can also edit the apache2 default page. This is what I do.

cd /
cd etc/apache2
vi apache2.conf

You will need to look for something that looks like this:

Options Indexes FollowSymLinks
AllowOverride None
Require all granted

and change it to look like this:

Options Indexes FollowSymLinks
AllowOverride All
Require all granted

Then you will need to run a few more lines for it to work.

sudo a2enmod rewrite
service apache2 reload
service apache2 restart

If you forget to run those lines above, you will receive a server error in the web browser. Don’t forget to a2enmod rewrite and restart apache.

 

21) Now you are going to want to edit /var/www/html/index.html which is the default apache2 page. What I do is download a program called WinSCP which you can get here. http://winscp.net/eng/download.php

This acts just like FTP program where you can see everything in a windows environment, not a console. When you install it then you just login like you would using PuTTY.

Navigate to the /var/www/html directory, right click on the index.html file and click edit. A text file will open with a bunch of HTML. You’re going to edit this with the code I’ve provided below.

Click here to see code: https://www.dropbox.com/s/m6k13xd0l01x7j8/replace%20apache%20index.txt?dl=0

The code above points the servers IP back to their home computer. This will act as though the root folder does not exist. Click save and visit the IP in the browser – CTRL F5 – and it should point to 127.0.0.1.

 

22) While we’re in here, navigate to the owncloud directory and edit the .htaccess file. Add the following code to the top of the file.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /(.*)index.php($| |?)
RewriteRule ^ /%1 [R=301,L]

That will hide the /index.php in the URL and only display the directory name.

You’re done!