Friday, July 25, 2014

Deploy PHP Application Using Capistrano 2.15

Deployment With Capistrano:

We can also deploy php app using ruby gem capistrano. For this we have to install it first on our system.

gem install capistrano -v 2.15.5
gem install railsless-deploy

After that on any place we have to initialized it. For this use:

capify .


It will create following two files

config/deploy.rb
Capfile

Add in the Capfile

require 'railsless-deploy'
load 'config/deploy'
Now edit the deploy.rb

  1. set :application, "App name"
  2. set :repository, "https://username:password@yourrepository.org/project-repository.git"
  3. set :user, 'shh_username'
  4. set :scm, :git
  5. set :normalize_asset_timestamps, false
  6. set :deploy_to, "/full/path/to/your project"
  7.  
  8. set :deploy_via, :copy
  9. set :use_sudo, false
  10. set :copy_exclude, [".git", ".DS_Store", ".gitignore", ".gitmodules", "Capfile", "config/deploy.rb"]
  11.  
  12. server "server name", :app
  13. namespace :myapp do task :restart_webserver do #Show Start of Task print "Restarting webserver..." # Restart Web Server run "#{sudo} service apache2 restart" end end after "deploy","myapp:restart_webserver"

We can also use deply_via:remote_cache.

Now setup deploy and then execute it.



cap deploy:set
cap deploy

It will create three folders on root
project_root/releases
project_root/shared
project_root/current
 

Friday, July 18, 2014

Moving Magento Website to another server

For Moving Magento Website:

Procedure for moving website:

1. Install Apache, MySql, PHP to new server

2.Take all the back up of code and database from previous server and put it on new server.

3. Now go to the table core_config_data and update coulmn where path web/unsecure/base_url and web/secure/base_url and value to your new website end with '/'.

4. Now edit app/etc/local.xml edit file according to your database configuration.

Its done.

Points Should Be Remind:

 There should be .htaccess file on the root and it should be same as the previous server file.

Problems Occurs:

Mostly there are some problems occurs due to server migration.

Main problem is "404 Error Page Not Found"

For this there are two solution.

1. Configuration of .htaccess file should be correct.

2. /etc/apache2/sites-enabled/000-defualt.conf file configuration should be correct and also there should be following thing:

<Directory /var/www/html>
     AllowOverride All
    Order Allow,Deny
    Allow from all
    Require all granted
</Directory>


Friday, July 4, 2014

Codeigniter Code Tricks

Codeigniter Code Tricks:


1) There is an optional second parameter in $this->uri->segment()

We can find second parameter in a url by this code

$robot = $this->uri->segment(3); 


There is an optional second parameter that permits you to set your own default value if the segment is missing.

$robot = $this->uri->segment(3, 'calculon');  


2) Any library can have a configuration file

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');



$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp1.mailserver.ca';
$config['smtp_user'] = 'username';
$config['smtp_pass'] = 'password';
$config['smtp_port'] = '25';


3) View’s can be returned as data with a third parameter

$page = $this->load->view('view', $data, TRUE);$pdf = build_pdf($page);
// OR
$this->load->helper('download');$view_data = $this->load->view('xml_template', $data, TRUE);
force_download($data['page_title'].'.xml', $view_data); 

Friday, June 27, 2014

Adopt PHP Library in Codeigniter

Adopt PHP Library:

1. Create a test folder in it:

/application/libraries/test_folder/

2. Create a Test_lib.php in the libraries root with the content:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once 'facebook/facebook.php';

class Facebook_lib extends Facebook{
}



3. In controller:

$this->load->library('facebook_lib',$config); 

$this->facebook_lib->clearAllPersistentData();




Friday, June 13, 2014

Getting Git on Server

Getting Git on Server:

In order to initially set up any Git server, you have to export an existing repository into a new bare repository.

git clone path_of_my_project.git
Initialized empty Git repository in /opt/path_of_project.git

The output for this command is a little confusing. Because clone is basically a git init and then a git fetch, you see some output from the git init part, which creates an empty directory. The actual object transfer gives no output, but it does happen. You should now have a copy of the Git directory data in your my_project.git directory.

This is roughly equivalent to something like

cp -Rf my_project/.git my_project.git

Putting Bare Repository on server:

Let’s say you’ve set up a server called git.example.com that you have
SSH access to, and you want to store all your Git repositories under the /opt/git directory.
You can set up your new repository by copying your bare repository over:

scp -r my_project.git user@git.example.com:/opt/git

we can clone repository by this

git clone user@git.example.com:/opt/git/my_project.git

Friday, June 6, 2014

Git Daemon

Git Daemon:

Git daemon allows users to share the own repository to colleagues quickly. Git instaweb allows users to provide web view to the repository.

Git protocol is relatively easy to set up. Basically, you need to run this command in a daemonized manner:

git daemon --reuseaddr --base-path=/opt/git/ /opt/git/

--reuseaddr allows the server to restart without waiting for old connections to time out, the --base-path option allows people to clone projects without specifying the entire path, and the path at the end tells the Git daemon where to look for repositories to export. If you’re running a firewall, you also need to punch a hole in it at port 9418 on the box you’re setting this up on.

/etc/event.d/local-git-daemon

script:

start on startup
stop on shutdown
exec /usr/bin/git daemon \
      --user=git --group=git \
      --reuseaddr \
      --base-path=/opt/git/ \
      /opt/git/
respawn

Friday, May 30, 2014

Set up of Gitosis

Gitosis:

Gitosis is basically a set of scripts that help you manage the authorized_key file as well as implement some simple access controls.

Installing:

Gitosis requires some Python tools, so first you have to install the Python setuptools package, which Ubuntu provides as python-setuptools

sudo apt-get install python-setuptools

Next, you clone and install Gitosis from the project’s main site:

git clone git@path_of_project.git

cd gitosis
sudo python setup.py install

That installs a couple of executables that Gitosis will use. Next, Gitosis wants to put its repositories under /home/git , which is fine. But you have already set up your repositories in /opt/git , so instead of reconfiguring everything, you create a symlink:

ln -s /opt/git /home/git/repositories

Gitosis is going to manage your keys for you, so you need to remove the current file,
re-add the keys later, and let Gitosis control the authorised_keys file automatically. For now,
move the authorised_keys file out of the way:

mv /home/git/.ssh/authorized_keys /home/git/.ssh/ak.bk

You need to turn your shell back on for the “git” user, if you changed it to the git-shell command. People still won’t be able to log in, but Gitosis will control that for you. So, change
this line in your /etc/password file

git:x:1000:1000::/home/git:/usr/bin/git-shell

back to

git:x:1000:1000::/home/git:/bin/sh

Now initialised it with gitosis init where we want to initalised.

Now this is set up