Saturday, October 25, 2014

Migrate From Apache to Nginx (Engin X) on Ubuntu VPS

I have low end of VPS, there are has minim of spesification hardware, googling and found recommended using Nginx for web server to reduce using of memory.

1. Stop service for Apache

sudo service apache2 stop

2. Installing Nginx PHP5-FPM

sudo apt-get install nginx php5-fpm

3. Configure PHP5-FPM

need to configuring PHP5 handler by Nginx
sudo nano /etc/php5/fpm/php.ini
find (CTRL + W) cgi.fix_pathinfo word and set like the below value:
cgi.fix_pathinfo=0
will modify another PHP configuration
sudo nano /etc/php5/fpm/pool.d/www.conf
find the "listen = ", We will modify this to use a socket for communication with the web server
listen = /var/run/php5-fpm.sock
Restart the PHP-FPM
sudo service php5-fpm restart

5. Set the Vhost of Nginx

sudo nano /etc/nginx/sites-available/myvhost.conf
add this lines to configure your site, for more example script you can find at /etc/nginx/sites-available/default
server {
    listen 80;

    root /var/www;
    index index.php index.html index.htm;
}
unlink the default configuration
sudo unlink /etc/nginx/sites-enabled/default 
Start the Nginx web server
sudo nano service nginx start

6. Remove Apache

to find all dependcies of Apache you filter like this:
dpkg --get-selections | grep apache
will display:
apache2      install
apache2-doc     install
apache2-mpm-prefork    install
apache2-threaded-dev    install
apache2-utils     install
apache2.2-bin     install
apache2.2-common    install
libapache2-mod-auth-mysql   install
libapache2-mod-passenger   install
remove
sudo apt-get remove apache2 apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common libapache2-mod-auth-mysql libapache2-mod-php5
for the clear remove dependencies run this command
sudo apt-get autoremove

Saturday, October 18, 2014

Friday, October 17, 2014

`autodetect': Could not find a JavaScript runtime on Ubuntu

When i starting the rails server, got the message " `autodetect': Could not find a JavaScript runtime "
googling and fix the issue with install a package:
sudo apt-get install nodejs

Thursday, October 16, 2014

Setup VPS for Ruby On Rails on Ubuntu 12.04 LTS

In this case, i'm using RVM for installing ROR

1. Update the Ubuntu

sudo apt-get update
sudo apt-get upgrade
after done, you need to restart the server for clean.
sudo shutdown -r now

2. Install MySQL

sudo apt-get install mysql-server mysql-client libapache2-mod-auth-mysql php5-mysql
Need, install the PHP for using phpmyadmin
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

3. Install dependencies

sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion libpq-dev

4. Install Curl

sudo apt-get install curl

5. Install RVM

\curl -L https://get.rvm.io | bash -s stable --ruby
source ~/.rvm/scripts/rvm
After installed RVM, close your terminal and login back to use the "rvm" command: RVM has some dependencies to need install, run this command.
rvm requirements
and if any install some recommended dependencies

6. Install Ruby

rvm list known
Will display like this:
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p547]
[ruby-]2.0.0-p481
[ruby-]2.0.0[-p576]
[ruby-]2.1.2
[ruby-]2.1[.3]
[ruby-]2.1-head
ruby-head
rvm install 2.1.2
rvm use 2.1.2 --default
check the version installed Ruby and Gem
ruby -v
gem -v

7. Install Rails

gem install rails

8. Install MySQL gem

Firstly, need install mysql dev
sudo apt-get install libmysqlclient-dev
gem install mysql2

9. Install ImageMagic

sudo apt-get install imagemagick

10. Install Javascript Runtime

sudo apt-get install nodejs

11. Install Phusion Passenger

gem install passenger
View script apache installation run this script:
passenger-install-apache2-module

Saturday, May 10, 2014

Crontab skip holiday date

Here's the step for skip holiday when using crontab:

1. Create the list of holidays on text file

touch /Users/arul/holidays_2014.txt
nano /Users/arul/holidays_2014.txt
2014-01-01
2014-01-14
2014-01-30
2014-03-31
2014-04-18

2. Create shell script on file

touch /Users/arul/runner.sh
nano /Users/arul/runner.sh
TODAY=$(date "+%Y-%m-%d")
if grep -q "$TODAY" /Users/arul/holiday.txt;
then
  /usr/bin/php /Users/arul/test.php
else
  echo "Not found the date"
  exit 0
fi

3. Set the Crontab task

crontab -e
Example the crontab will run every two hours start from Monday through Friday
0 */2 * * mon-fri sh /Users/arul/runner.sh

Tuesday, March 11, 2014

SVN cannot set LC_CTYPE locale on Centos

I got the error when checking "svn status"
svn: warning: cannot set LC_CTYPE locale
svn: warning: environment variable LC_CTYPE is UTF-8
svn: warning: please check that your locale name is correct
locale -a
export LC_ALL=C

Installing Subversion on Server Centos

Install the package
sudo yum install subversion mod_dav_svn
Create the directory svn
mkdir /var/www/svn
svnadmin create myrepo
chown -R apache.apache myrepo
Edit subversion configuration file
vi /etc/httpd/conf.d/subversion.conf
Add these line
LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so

< Location /svn >
   DAV svn
   SVNPath /var/www/svn
   AuthType Basic
   AuthName "Subversion repositories"
   AuthUserFile /etc/svn-auth-users
   Require valid-user
< /Location >
Adding new user
sudo htpasswd -cm /etc/svn-auth-users username
New password:
Re-type new password:
Adding password for user new_user
Restart your server
sudo service httpd restart
Finally, access your svn url:
http://ip-address/svn/myrepo