Build Local Dev Environment Easily!!!

Setup a local development environment with Vagrant + Virtual box. install below items httpd(webserver), mysql, php, ruby, python, rails, nodejs In this case, need to install some libs and I used Mac OS X.

Install VirtualBox

Download VirtualBox

https://www.virtualbox.org/wiki/Downloads

Install Vagrant

Download Vagrant

https://www.vagrantup.com/downloads.html

Install CentOS

Step0. Make directory

You can make a directory where you want. In this case, we make under Document.

% cd Documents/
% mkdir LocalDev
% cd LocalDev

Step1. Add box

Vagrantbox.es http://www.vagrantbox.es/ You can choose what you want to use, but in this case we use Cent OS.

Format

% vagrant box add {box name} {box url or path(If you have a box already)}
% vagrant box add localdev https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box

Step2. Init box

Format

% vagrant init {box name}
% vagrant init lovaldev

Step3. Start Cent OS

% vagrant up

Step4. Edit Vagrantfile

% vi Vagrantfile

Before

# config.vm.network “private_network”, ip: “192.168.33.10”

You just remove # and if you want to change your local machine’s ip, you can do it like below.

After

config.vm.network “private_network”, ip: “192.168.33.50”

If you had done those step, your local machine would have started already. But you can’t access the ip with your browser because you didn’t install webserver.

Step5. Try to login your local machine(ssh)

% vagrant ssh

If you success ssh, you can see that.

password:vagrant (default setting) You generally don’t need input.
[vagrant@vagrant-centos65 ~]$

You should update your CentOS before install something that you need to install.

% sudo yum -y update

Install httpd

Step1.

% sudo yum -y install httpd

Step2. Start webserver

% sudo service httpd start

Step3. Set chkconfig on

You should change your chkconfig because when you start your machine, you can access your web server.

% sudo chkconfig httpd on

Step4. Check the result of setting

% chkconfig --list

You can see something like this.

httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Step5. Put a sample html

% cd /var/www/html
% sudo vi index.html

index.html

<h1>It works!</h1>

Finally, you can go your ip(in this case 192.168.33.50) with browser. You see like this.

Install PHP

There are two ways. If you need to php5.3, you can use yum command like shell % sudo yum -y install php

However, if you need php5.4, you should do below steps.

Step1. Download epel & remi

epel(https://dl.fedoraproject.org/pub/epel/6/x86_64/)

% wget https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

remi(http://rpms.famillecollet.com/)

% wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Step2. Install epel & remi

% sudo rpm -U epel-release-6-8.noarch.rpm
% sudo rpm -U remi-release-6.rpm

Step3. Change your setting

% sudo vi /etc/yum.repos.d/epel.repo

Before [epel]

name=Extra Packages for Enterprise Linux >6 — $basearch
#baseurl=http://download.fedoraproject.o>rg/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

After [epel]

name=Extra Packages for Enterprise Linux >6 — $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

Step4. Confirmation of php version that you can install

% yum info --enablerepo=remi php

Step5. Install php and so on

% sudo yum --enablerepo=remi install php php-dev php-mysql php-mbstring php-gd

Step6. Check php version

% php -v
PHP 5.4.36 (cli) (built: Dec 19 2014 06:28:27)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

Install mysql

Step1.

% sudo yum install -y --enablerepo=remi mysql-server

Step2. Do setting about mysql

At least you should put on a password.

% /usr/bin/mysql_secure_installation

Step3. Login mysql

% mysql -u root -p

You have to type below to logout after you can login.

exit;

Install python

Step1. Download python2.7

First you have to download python2.7 because if you type yum install command, you can only install python2.6. CentOS 6

% wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tar.xz
% tar Jxvf Python-2.7.9.tar.xz

Step2. Install python

% cd cd Python-2.7.9
% ./configure --enable-shared --with-threads
% make
% sudo make install
% sudo cp libpython2.7.so libpython2.7.so.1.0 /usr/lib
% sudo /sbin/ldconfig
% source ~/.bash_profile

Step3. Check python version

% python --version
Python 2.7.9

Step4.

Install ruby with rbenv

Step1. Install some libs

% sudo yum -y install libyaml libyaml-devel zlib zlib-devel readline readline-devel openssl openssl-devel libxml2 libxml2-devel libxslt libxslt-devel

Step2. Install rbenv

you just follow this page(https://github.com/sstephenson/rbenv)

% sudo yum -y install git
% git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
% echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
% echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
% rbenv -v
rbenv 0.4.0-129-g7e0e85b

Step3. Check a list that you can install which ruby.

% rbenv install -l
Available versions:
1.8.6-p383
1.8.6-p420
1.8.7-p249
1.8.7-p302
1.8.7-p334
1.8.7-p352
1.8.7-p357
1.8.7-p358
1.8.7-p370
1.8.7-p371
1.8.7-p374
1.8.7-p375
1.9.1-p378
1.9.1-p430
1.9.2-p0
1.9.2-p180
1.9.2-p290
1.9.2-p318
1.9.2-p320
1.9.2-p326
1.9.2-p330
1.9.3-dev
1.9.3-preview1
1.9.3-rc1
1.9.3-p0
1.9.3-p125
1.9.3-p194
1.9.3-p286
1.9.3-p327
1.9.3-p362
1.9.3-p374
1.9.3-p385
1.9.3-p392
1.9.3-p429
1.9.3-p448
1.9.3-p484
1.9.3-p545
1.9.3-p547
1.9.3-p550
1.9.3-p551
2.0.0-dev
2.0.0-preview1
2.0.0-preview2
2.0.0-rc1
2.0.0-rc2
2.0.0-p0
2.0.0-p195
2.0.0-p247
2.0.0-p353
2.0.0-p451
2.0.0-p481
2.0.0-p576
2.0.0-p594
2.0.0-p598
2.1.0-dev
2.1.0-preview1
2.1.0-preview2
2.1.0-rc1
2.1.0
2.1.1
2.1.2
2.1.3
2.1.4
2.1.5
2.2.0-dev
2.2.0-preview1
2.2.0-preview2
2.2.0-rc1
2.2.0
2.3.0-dev
jruby-1.5.6
jruby-1.6.3
jruby-1.6.4
jruby-1.6.5
jruby-1.6.5.1
jruby-1.6.6
jruby-1.6.7
jruby-1.6.7.2
jruby-1.6.8
jruby-1.7.0-preview1
jruby-1.7.0-preview2
jruby-1.7.0-rc1
jruby-1.7.0-rc2
jruby-1.7.0
jruby-1.7.1
jruby-1.7.2
jruby-1.7.3
jruby-1.7.4
jruby-1.7.5
jruby-1.7.6
jruby-1.7.7
jruby-1.7.8
jruby-1.7.9
jruby-1.7.10
jruby-1.7.11
jruby-1.7.12
jruby-1.7.13
jruby-1.7.14
jruby-1.7.15
jruby-1.7.16
jruby-1.7.16.1
jruby-1.7.16.2
jruby-1.7.17
jruby-1.7.18
jruby-9.0.0.0-dev
jruby-9.0.0.0+graal-dev
jruby-9000-dev
jruby-9000+graal-dev
maglev-1.0.0
maglev-1.1.0-dev
maglev-2.0.0-dev
mruby-dev
mruby-1.0.0
rbx-1.2.4
rbx-2.0.0-dev
rbx-2.0.0-rc1
rbx-2.0.0
rbx-2.1.0
rbx-2.1.1
rbx-2.2.0
rbx-2.2.1
rbx-2.2.2
rbx-2.2.3
rbx-2.2.4
rbx-2.2.5
rbx-2.2.6
rbx-2.2.7
rbx-2.2.9
rbx-2.2.10
rbx-2.3.0
rbx-2.4.0
rbx-2.4.1
ree-1.8.6-2009.06
ree-1.8.7-2009.09
ree-1.8.7-2009.10
ree-1.8.7-2010.01
ree-1.8.7-2010.02
ree-1.8.7-2011.03
ree-1.8.7-2011.12
ree-1.8.7-2012.01
ree-1.8.7-2012.02
topaz-dev

Step4. Install ruby

you choose the version from the list.

% rbenv install 2.0.0-p247
% rbenv rehash
% rbenv global 2.0.0-p247

Step5. Check ruby version

% rbenv versions
system
1.9.3-p551
* 2.2.0 (set by /home/vagrant/.rbenv/version)
% ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]

Install Rails 4.2.0

Step1.Update gem

% gem update --system

Step2. Install rails without documents

% gem install rails --no-ri --no-rdoc

Step3. Check rails’ version

% rails -v

Install nodejs

Step1. install build tools

% sudo yum -y groupinstall 'Development Tools'

Step2. register rpm

% rpm -ivh http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

Step3. install node.js

% sudo yum -y install nodejs npm --enablerepo=epel

Step4. check version

% node -v
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.