ভিপিএস (VPS) কেনা, ব্যাসিক কনফিগারেশন, ল্যাম্প ইন্সটলেশন, ডোমেইন ম্যাপিং

ভূমিকা

VPS (Virtual Private Server) হচ্ছে একধরনের ভার্চুয়াল মেশিন বা ভার্চুয়াল কম্পিউটারও বলতে পারেন, যেটা একটা সার্ভিস হিসেবে কেনা যায় বিভিন্ন ক্লাউড সার্ভার প্রোভাইডারদের কাছ থেকে। এই ভার্চুয়াল মেশিন গুলোরও RAM আছে, হার্ডডিস্ক আছে, সিপিইউ আছে এবং সর্বোপরি একটা অপারেটিং সিস্টেম এর উপর চলে। মজার ব্যাপার হচ্ছে এরকম একটা মেশিনের বাস্তব কোন অস্তিত্ব নাই ঠিকই কিন্তু বাস্তব একটা ফিজিক্যাল মেশিনের মতই গঠন ও আচরণ। কিভাবে এই ভার্চুয়াল ইনফ্রাস্ট্রাকচার তৈরি ও মেইন্টেইনড হয় সেটা আজকে আমাদের আলোচনার মুল বিষয় নয়। বরং এরকম একটা ভার্চুয়াল সার্ভার মেশিনকে আমরা কিভাবে ওয়েব সার্ভার হিসেবে তৈরি করব সেখান থেকে কিভাবে ওয়েব কন্টেন্ট প্রোভাইড করবো সেটাই মুখ্য বিষয়।

কিনে ফেলি একটা ভার্চুয়াল প্রাইভেট সার্ভার

বিভিন্ন সার্ভার প্রোভাইডার তাদের মেশিনগুলোকে বিভিন্ন নামে ডাকে। যেমন অ্যামাজন এর ভাষায় এগুলো হচ্ছে ইন্সট্যান্স, Rackspace এর ভাষায় এগুলো ক্লাউড সার্ভার, DigitalOcean এর ভাষায় ড্রপলেট, ইত্যাদি। আমরা আজকের টিউটোরিয়ালের জন্য DigitalOcean এর কাছ থেকে একটি মিনিমাম কনফিগারেশনের সার্ভার কিনবো যেটাতে ৬৪ বিটের উবুন্টু ১৪.০৪ ইন্সটল করা থাকবে এবং আস্তে আস্তে এটা কফিগার করবো ওয়েব সার্ভার হিসেবে।
এই লিঙ্ক থেকে একটি সার্ভার কিনে ফেলতে পারেন (এটি আমার রেফারেল লিঙ্ক। এটা ব্যবহার করে সাইন আপ করলে $10 ক্রেডিট/ব্যালেন্স পাবেন, না করলে নাই) । প্রথমে অ্যাকাউন্ট ডিটেইল দিতে হবে এবং পরে ভ্যালিড পেমেন্ট মেথড অ্যাড করতে হবে। যদিও এরা এক মাস শেষ হলে পেমেন্ট মেথড থেকে বিল চার্জ করবে তার আগে না। আপনি চাইলে সার্ভার মাঝে মাঝে শাটডাউন করে রাখতে পারেন। সেই সময় গুলোতে বিল কাউন্ট হবে না।
Continue reading ভিপিএস (VPS) কেনা, ব্যাসিক কনফিগারেশন, ল্যাম্প ইন্সটলেশন, ডোমেইন ম্যাপিং

Laravel4 Migrations and Seeding

So far we have created the virtual host for our laravel4 application named “thisdayinbangladesh.dev” and also set up the basic laravel4 installation. Now in this lesson we will create the migrations and seeders needed for our application.

“Migrations are a type of version control for your database. They allow a team to modify the database schema and stay up to date on the current schema state. Migrations are typically paired with the Schema Builder to easily manage your application’s scheme.”

“Laravel also includes a simple way to seed your database with test data using seed classes.”

First thing first. Open up the Mac Terminal and enter inside the “thisdayinbangladesh” folder under MAMP’s “htdocs” directory. All of the following commands should be executed from inside the project folder.

Create migration files for all of our currently needed tables:
Execute these commands one by one,

These commands set up the basic migration scripts that we’ll be using to create the database tables

Update the migration files:
Edit “database/migrations/TODAYS_FULL_DATE_create_days_table.php” file and update the “up()” method to include a new column on the “days” table and to remove the “timestamp” column.

Update the “up()” method of “database/migrations/TODAYS_FULL_DATE_create_facts_table.php” file to the following,

Update the “up()” method of “database/migrations/TODAYS_FULL_DATE_create_types_table.php” file to the following,

Update the “up()” method of “database/migrations/TODAYS_FULL_DATE_create_fact_type_table.php” file to the following,

Prepare the Seeder files to add sample data to those tables:
Create a file within the “app/database/seeds” folder that has the same name as the table. So, for our “days” table create a file named “DayTableSeeder.php” inside “seeds” folder containing the following full code,

Here I am inserting some “day-month” patterned days rows in the “days” table using a simple loop. Please, don’t judge my PHP knowledge on this. This is not about showing optimized, minimal, smell free coding.
Also, create other seeder files for those remaining tables into which we want to push some sample data even before launching the app.
Create “FactTableSeeder.php” with following code. Here we are inserting some sample facts that holds the fact’s sample title and sample description just for checking out data retrieval with proper relations later on the next lesson.

Now create the “TypeTableSeeder.php” file with the following code,

And finally create the “FactTypeTableSeeder.php” file with,

As you can see, we are assigning some “facts” to some “types” and making rows in the “fact_type” table pairing “fact_id” with “type_id” as for our sample data.

Update the DatabaseSeeder file:
Update the “run()” method of the “DatabaseSeeder.php” file. That should already be there inside “app/database/seeds” folder with the following code,

Run Migration and Seed:
Execute the following commands one by one.

If the commands executed successfully then you should see those tables along with an extra tables named “migrations” under your “thisdayinbangladesh” database. Also there should be our sample data in each table if the Seeding happens successfully!

Note:
As one “fact” will have multiple “types” and vise versa. You should name the Pivot table (“fact_type” in this case) of the “facts” and “types” table by taking the singular name of the alphabetically first table then the second table with an underscore in the middle.
Also there should be two columns at least, to hold the relation which should be named by taking the singular name of one table with its primary key along with an underscore in the middle. Such as “fact_id”, “type_id”.
But wait, don’t be scared. There is still flexibility while naming those tables and columns for using with Eloquent ORM. You will have to just pass those non-conventional table names or column names as parameters in corresponding methods while creating ORM relations among tables or while creating migrations tables.
We just followed the conventional naming pattern in this lesson to make thing simple and understandable.

What next?:
The next step is to make proper Routing for our application. Which is ready now!

Installing Laravel4 in Mac OSX with MAMP

Re-cap:
In the past and first tutorial of this series we learned how to create a virtual host with MAMP. In this second tutorial, we will install laravel4 PHP framework and will go another step toward developing a full laravel4 application series.

Precautions:

  • Make sure your installed PHP version is greater or equal to 5.3.7
  • Also make sure the MCrypt PHP extension is enabled
  • For pretty URL the mod_rewrite module is enabled on Apache

1. Install Composer Globally:

The following command will just check a few PHP settings and then download composer.phar

You can run these commands to easily access composer from anywhere on your system

2. Create a laravel project named “thisdayinbangladesh” inside our MAMP’s “htdocs” directory:

Going inside the “htdocs” directory

Creating the project there

3. A small permission issue:

Lets enter into our project directory

Change the permission of the storage folder to writable

4. Basic Configuration:

Update line number 29 of the “app/config/app.php” file to

and line 42 to

5. Database configuration:
Though configuring database is not necessary to have a first run but lets complete this step as we will not do any editing on the config files later.

6. Lets have a test run:

Open the URL of your laravel application as we created earlier using virtual host; on the browser. That is http://thisdayinbangladesh.dev/
You should arrive!

How to Set Up Virtual Host with MAMP on a Mac OSX

1. Update the hosts file:
We are going to add an example domain named “thisdayinbangladesh.dev” as a virtual host through this tutorial. Lets first add this in the “hosts” file by typing the following command on the Terminal,
[sourcecode lang=”bash”]sudo nano /etc/hosts[/sourcecode]
Then find the following line,
[sourcecode lang=”bash”]127.0.0.1 localhost[/sourcecode]
update this to following,
[sourcecode lang=”bash”]127.0.0.1 localhost thisdayinbangladesh.dev[/sourcecode]
Also to add our domain to the IPv6 version find the following line somewhere bottom of the file,
[sourcecode lang=”bash”]fe80::1%lo0 localhost[/sourcecode]
update this line to the following one,
[sourcecode lang=”bash”]fe80::1%lo0 localhost thisdayinbangladesh.dev[/sourcecode]
Finally press “ctrl+x” and then “y” to save and exit this file.

2. Update httpd.conf file
Open up this file by typing the following command,
[sourcecode lang=”bash”]sudo nano /Applications/MAMP/conf/apache/httpd.conf[/sourcecode]
find out the following line,
[sourcecode lang=”bash”]#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf[/sourcecode]
It might have a “#” symbol at the very beginning of the line. Delete the symbol to activate this statement. If the line is not anywhere of the “httpd.conf” file then add the above line anywhere of this file. Now, save and exit this file.

3. Update httpd-vhosts.conf file
Now go into the “/Applications/MAMP/conf/apache/” folder by executing,
[sourcecode lang=”bash”]cd /Applications/MAMP/conf/apache/[/sourcecode]
If you can see a folder named “extra” then enter inside it otherwise create this “extra” folder and then enter inside it.
Now update (If there was already a “extra” folder then there should be a “httpd-vhosts.conf” file other wise just create the “httpd-vhosts.conf” file inside “extra” folder) the “httpd-vhosts.conf” file by typing the following,
[sourcecode lang=”bash”]sudo nano httpd-vhosts.conf[/sourcecode]
Then the final “httpd-vhosts.conf” file should have the following code block. Whether you add these lines or updated the existing file.
[sourcecode lang=”bash”]
NameVirtualHost *:80

<VirtualHost 0.0.0.0:80>
DocumentRoot "/Applications/MAMP/htdocs"
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/thisdayinbangladesh/public"
ServerName thisdayinbangladesh.dev
<Directory "/Applications/MAMP/htdocs/thisdayinbangladesh/public">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
[/sourcecode]
Here “thisdayinbangladesh” is a project directory; actually a laravel4 project directory inside my “htdocs” folder and we added the “public” folder thats resides in “thisdayinbangladesh” folder as the document root cause laravel4 needs to point to the “public” folder as the application root URL.
In this stage of this example. You can forget about laravel4 and simply create the directory “/thisdayinbangladesh/public” inside your “htdocs” folder and place a simple “index.html” file there inside the “public” folder.

4. Restart:
Simply stop and re-start the Apache service from your MAMP control panel. Then try out the URL on your browser. http://thisdayinbangladesh.dev You should see your “index.html” file!

Important:
This tutorial will take you through out a nice series of posts on which a full laravel4 web application has been developed. That service is already LIVE HERE. So, stay tuned!

Update:
The next tutorial is ready Installing Laravel4 in Mac OSX with MAMP. So, you are another step close toward the full laravel4 application development series.

To Do List After Launching a New Linux/Unix Like Server for Development

Commands, tricks & cautions that will be used here have been tested only on a Ubuntu 12.04 VPS. Though, most of the commands should work in other Unix like system without any change.
In this lesson we will see how should a newly launched/opened server be configured for basic security & proper accessibility. Usually you get an IP address & a root password for logging in as root, as soon as you open a new cloud/vps server from rackspace/digitalocean or some others like these.

1. Connecting to the remote system through/using SSH:
SSH(Secure Shell) is a protocol used to securely loggin in to a remote system & also ssh is the tool used in Linux that connect to the remote server over the SSH protocol.

The terminal will show a message and will prompt

Type yes & press enter & then in next prompt enter your root password that was provided by that server provider while opening a VPS. So, now we are logged in to the remote system as root user.

2. Change your root user’s password:
You used the root password that was generated & provided by the server provider & the first thing is to change this password. Enter the following command on the terminal.

It will first ask the current root password & after entering the current password it will ask your desired new password twice for confirmation. Continue reading To Do List After Launching a New Linux/Unix Like Server for Development

Setup Auto Deployment with Git & Shell Script

Few days ago I found a nice post on the web about a trick for auto deploying sources/files to server from inside local development repository using shell script. I mean, you don’t need to log in into the server each time the code status is changed and pull the changes from a repository to make the server’s files updated. You can do all of these from inside the local repository by assigning several remotes to it & by using the Hook feature of git on the server end. I have just tried that out and made a screencast with some detail descriptions.

Following is a diagram of what I am going to show you detail on the video below it. Hope it might be helpful for some one who wants to watch a demo even before trying out few commands 🙂

Untitled drawing

Live Demo [watch in 720p at least]

Kohana with Twitter bootstrap: Auto Generator Shell Script

Kohana HMVC with Twitter Bootstrap Auto Generator

What it does?

  • It makes a ready to develop web app on Kohana MVC along with Twitter Bootstrap UI framework.
  • First it downloads kohana, twitter bootstrap, jquery etc.
  • Secondly it makes necessary changes on the kohana boostrap and allocates UI assets.
  • Then it creates two types of routes for accessing front end and backend of the developing app.
  • It also makes changes on the default controller class and creates a view for it.
  • Also you can create a set of MVC (model, view, controller) classes/files by using create command.
  • Finally you can open the app in browser using open command.

Installation

  1. I assuem you have downloaded the kohanastrap.sh  file on your home.
  2. Open up the terminal. Change its permission by chmod +x ~/kohanastrap.sh
  3. Make a symlink of it by sudo ln -s ~/kohanastrap.sh /usr/bin/kohanastrap
  4. Type kohanastrap  from inside any directory and talk with it.
  5. I assume, you will enter into yout htdocs OR www directory and type kohanastrap init  and then it will build up a ready to develop web app using twitter bootstrap as template.
  6. If you want to create a set of MVC files/classes such as a Controller, a Model and a View for managing users of your app, then type kohanastrap User  and Done! Check inside your classes, views directory.
  7. Finally run your web app using the command kohanastrap open  and it will open your browser with two additional tabs containing the URLs of front end and backend of your newly created app (If you are in Mac). Otherwise, Open the browser and go to http://localhost/kohana/ OR http://127.0.0.1/kohana/ if you are in other than Mac.

Demo

Download

You can fork/download it from github

Precautions

Make sure wget works in your system. Also make sure your php has cURL, mcrypt, GD enabled and Apache has mod_rewrite  enabled. Those are needed to kohana.

A jQuery Plugin Snippet for Sublime Text 2

Sublime_Text_Logo
You can simply (yes really simply) create a code snippet on Sublime Text 2 for faster code completion by clicking on the Tools -> New Snippet  menu of sublime and by editing the snippet template according to your choice.
You will have to edit/update line number 3 to the code block you want to have while calling the snippet by a shortcode. Uncomment line 6 & define a shortcode typing which you want to generate that code block.  Also uncomment line 8 and define whether you want that snippet to be workable only in a specific scope of scripting.

Finally save the file in /Users/USERNAME/Library/Application\ Support/Sublime\ Text\ 2/Packages/User  (Mac OSX) folder with a name along with .sublime-snippet extension.

Screen Shot 2013-08-29 at 4.26.04 PM

Here I have made a simple snippet which contains a template of a basic JQuery plugin. You can Download this snippet file and paste it inside the folder /Users/USERNAME/Library/Application\ Support/Sublime\ Text\ 2/Packages/User (Mac OSX)

Screen Shot 2013-08-29 at 4.12.36 PMThen you can start writing jquery on any type of file (As I did not define any scope) and the snippet keyword should appear.

Screen Shot 2013-08-29 at 4.14.14 PM

Press tab key by typing jqueryplugin OR enter/return key by selecting that suggestion and it will generate a basic template of a jquery plugin there for you.

Screen Shot 2013-08-29 at 4.14.22 PM

Most Popular Free Hosting & Deployment Environments

webhosting
My observation on some hosting/deployment environments & virtual cloud servers which can be used as cost free for development and testing period without any hassle.

1. Openshift
Deployment environment. Supports git version controlling. Have their own command line tool. 1GB storage for both DB & files with 512 MB RAM allocated per small gear. SSL support on your app URL. Custom domain support. No payment method needed.

2. Appfog
Deployment environment. Supports version controlling. Have their own command line tool. 100MB DB & 2GB RAM per account. You can host/deploy unlimited apps within this resource. Free for ever. SSL support on your app URL. Custom domain support. No payment method needed. A how to tutorial here.

3. Heroku
Deployment environment. Supports git version controlling. Have their own command line tool. 10K DB Rows & 512 MB RAM allocated per web dyno. You can host/deploy unlimited apps within this resource. Free for ever. SSL support on your app URL. Custom domain support. No payment method needed.

4. Amazon EC2 micro instance
A full featured virtual private server. Choose the operating system to be installed on it and you are done! Access & manage that VPS through your local machine’s terminal. Install packages, configure different types of environment, create users, deploy your app there. Actually use that remote machine as like you do in your own locac Unix/Windows server system. 8GB storage for whole system purpose with 613 MB RAM including 2 CPU per instance. One year free. Need payment method to be verified while sign up.

5. Amazon Beanstalk
Deployment environment. No need to configure any server from scratch. Just select your app type to be deployed & it will build up an environment to suit your app on background. Have their own command line tool for better managing your app from local machine. Supports version controlling. Uses the micro instance on behind. One year free. Need payment method to be verified while sign up. A how to tutorial here.

More on my mind is pagodabox, joyent etc.

Setup a custom domain for your appfog application

www
On a previous post we saw how to deploy a PHP application in appfog using appfog CLI. appfog gives you a domain for your newly created aaplication which is not so beautiful at all. Such as (http://YOUR-APP-NAME.aws.af.cm/) or something like that according to your choosen region/infrastructure while creating the app.

Today we will point a godaddy domain to a appfog application. For this you will have to first go to your app under your appfog account. Then select the Domain Names from left navigation. Here you can see the domain name already assigned to your application and few more blank fields for domain names to be added.

Also you can see the DNS instructions for custom domains” below that form. Here it will show what “A” record and CNAME record you should add on your own domain control panel.

Screen Shot 2013-02-14 at 7.24.46 PM

I have added www.nuhil.net as the second domain name. Then I added a “A” record and a “CNAME” record under my godaddy domain management panel using the DNS manager.

godaddyIf you wait few hours after changing the records in your domain end, then this will point the full domain for example http://www.nuhil.net to the appfog application but if you type the naked one like, http://nuhil.net then it will show a 404 not found appfog message. For the solution I did a forwarding under my godaddy account using the “forwarding domain tool” to forward the naked domain to full domain.

Screen Shot 2013-02-14 at 7.39.38 PM

This forwarding may cause a change on your “A” record you just created manually according to appfog’s suggestion. But no need to worry. The “CNAME” can take care of all the rest.