Friday, November 22, 2013

EC2 Ubuntu Apache PHP MySQL Setup


  1. In order to connect to the instance we need to assign an IP address. In the left menu in the EC2 Management Console select Elastic IPs under Network & Security. Allocate a new address and assign it to your instance. Elastic IPs are free as long as they are assigned to an instance, so remeber not to leave any unallocated IP addresses as you will get charged by the hour. Remember the assigned IP.
  2. On your local machine use the pem key to SSH into your instance. On OS X change the permission of the key to 600 and use following command in terminal:
    ssh -i yourkeyname.pem ubuntu@yourelasticip
    and boom you are in.
  3. Update the Ubuntu package manager and the installed packages:
    sudo apt-get update
    sudo apt-get dist-upgrade
  4. Install Apache:
    sudo apt-get install apache2
  5. Enable .htaccess files by editing the /etc/apache2/sites-available/default file, fx with vi or nano. Look for the /var/www directory and make sure it contains AllowOverride All.     <Directory /var/www/>
                    Options Indexes FollowSymLinks MultiViews
                    AllowOverride All
                    Order allow,deny
                    allow from all
    </Directory>
  6. Enable the rewrite module in Apache:
    sudo a2enmod rewrite
  7. Install PHP5:
    sudo apt-get install libapache2-mod-php5
  8. Restart Apache:
    sudo /etc/init.d/apache2 restart
  9. Ensure that Apache is running by typing the instance IP in your browser.
  10. Allow the Ubuntu user to work with the /var/www folder:
    sudo adduser ubuntu www-data
    sudo chown -R www-data:www-data /var/www
    sudo chmod -R g+rw /var/www
    Logout and login again to pick up the new user group. Test by creating a directory and deleting it again in www without having to sudo. This will make your life easier since permissions will get messed up less once you start adding frameworks and tools to your web service.
  11. Test PHP by cd into /var/www folder and typing sudo vi phptest.php. Hit i key to enter insert mode and just write a simple php script with a phpinfo() call.
    Hit ESC to exit insert mode and type :wq to save and quit the vi editor. Go to instanceIP/phptest.php in your browser and you should see the phpinfo displayed.
  12. Install MySQL:
    sudo apt-get install mysql-server
    sudo apt-get install php5-mysql
    Insert root password for the database and remember it.
  13. To test MySQL let’s install PHPMyAdmin:
    sudo apt-get install phpmyadmin
Next I think you need to install git.I don't prefer to use FTP client.
  1. sudo apt-get install git

Wednesday, August 28, 2013

How to run Composer autoload and CodeIgniter autoload simultaneously

Did you tried to install composer and then you existing CodeIgniter Autoload stop working!!! It happened because __autoload is the old, deprecated way of doing autoloading and you can have only one.

How to run it?
You should register your autoloader using spl_autoload_register.
How you will do it in your code..Here is an example below...

function MY_CI_Autoload($class)
{
 if(strpos($class, 'CI_') !== 0)
 {
  @include_once( APPPATH . 'core/'. $class . EXT );
 }
}

spl_autoload_register('MY_CI_Autoload');

This way your autoloader and composer's will coexist happily.

Saturday, August 17, 2013

My MAMP MySql is not turning on!!!!!!!

I have updated my MAMP version to 2.0 and after that my mysql stop working.
This command worked for me and after running the following in my command line it start working again.. :)
     ps aux | grep mysql 
     lsof -i 
     killall -9 mysqld
if needed
    sudo killall -9 mysqld

Using composer with MAMP’s version of PHP

One tool I have been playing with recently is Composer which is a dependency manager, think Ruby Gems but for PHP. Which is a great little tool and I’m really happy to see the community getting behind it and moving forward. After just trying to install composer I ran into a little problem which I thought was worth sharing.
After running curl -s https://getcomposer.org/installer | php, I get the following error:

Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:

The detect_unicode setting must be disabled.
Add the following to the end of your `php.ini`:
    detect_unicode = Off


Which looks pretty simple to fix but MAMP should have this setting disabled. So I ranwhich php and I’m told I’m running /usr/bin/php which is the version of PHP that comes preinstalled with OS X. So we just need to swap this over to the PHP that is installed with MAMP, which is located at

 /Applications/MAMP/bin/php/php5.3.6/bin 

To do this I edit my .bash_profile or .profile if you are using a different shell and add the MAMP version of PHP to the PATH variable.

export PATH=/Applications/MAMP/bin/php/php5.3.6/bin:$PATH

It’s important to append the existing $PATH at the end otherwise the version of PHP in /usr/bin/php will be found and loaded first instead. Save the .bash_profile and reload your profile by typing

 source ~/.bash_profile

and run which php, and if you’ve done everything right should say /Applications/MAMP/bin/php/php5.3.6/bin/php.

Saturday, June 8, 2013

How to list all CRON Jobs for all user

To have a improved output formatting you can run the following command in you terminal.

for user in $(cut -f1 -d: /etc/passwd)
do echo $user && crontab -u $user -l
echo " "
done

Wednesday, May 22, 2013

Easy way to delete all objects from S3 bucket

I had to delete a bucket from S3 server But the problem is, a bucket can only be deleted if it is empty. Delete objects using User Interface on Amazon S3 management console is a tough job and very time consuming. Take a look at the following screenshot.


If a bucket hold more then 10000 objects then how you will do it?

If you are familier with Amazon SDK PHP2 go with the following code to accomplish this task easily..
require 'vendor/autoload.php';

use Aws\S3\S3Client;
use Aws\S3\Model\ClearBucket;

$s3 = S3Client::factory(array(
    'key' => 'write_your_key_here',
    'secret' => 'write_your_secret_key_here'
));

$bucket = 'your_bucket_name';

$clear = new ClearBucket($s3, $bucket);
$clear->clear();

// Delete the bucket
$result = $s3->deleteBucket(array('Bucket' => $bucket));

// Wait until the bucket is not accessible
$result1 = $s3->waitUntilBucketNotExists(array('Bucket' => $bucket));

Another way to do this..
$bucket = 'your_bucket_name';

$iterator = $s3->getIterator('ListObjects', array(
    'Bucket' => $bucket
));

$s3->registerStreamWrapper();

foreach ($iterator as $object) {
    unlink('s3://'.$bucket.'/'.$object['Key']);
}

Monday, May 13, 2013

How to use JW Player on FancyBox

How I got JW Player working inside FancyBox


    jQuery(".position1").fancybox({
        'content':'
Big Opportunity, Health, Convenience , Trading up – Leah Weckert
', maxWidth:800, maxHeight:600, fitToView:false, width:'70%', height:'70%', autoSize:true, closeClick:false, openEffect:'none', closeEffect:'none', afterShow:function () { jwplayer('mediaspace').setup({ 'flashplayer':'/coles-brand/js/jwplayer/jwplayer.flash.swf', 'file':"http://www.blipunited.com/lb/video.mp4", 'image':'http://img.youtube.com/vi/LtGoBZ4D4_E/0.jpg', 'provider':'youtube', 'height':400, 'width':700, 'controlbar.position':'bottom' }); } });