Sunday, 8 November 2015

How to Install Laravel 4 with an Apache Web Server on Ubuntu 14.04

Laravel is a open source PHP framework for web developers. It aims to provide an easy, elegant way for developers to get a fully functional web application running quickly.
Here we will dissuss how setup laravel step by step from scratch.
Preparing the server / environment
sudo apt-get update
sudo apt-get upgrade
Preparation of installing PHP 5
Installing Apache, PHP and MySQL
sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install mysql-server
sudo apt-get install php5-mysql
The installation process is self-explaining. You can prove the installed versions of PHP and Apache with:
php -v
apache2 -v
Installing necessary PHP extensions
sudo apt-get install unzip
sudo apt-get install curl
sudo apt-get install openssl
sudo apt-get install php5-mcrypt
Install Composer (systemwide)
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
Activate mod_rewrite
sudo a2enmod rewrite
sudo service apache2 restart
Install Laravel 4
cd /var/www/laraveldev
wget https://github.com/laravel/laravel/archive/master.zip
unzip master.zip && cd laravel-master/ && mv * ../ && cd ..
rm -r laravel-master && rm master.zip

Make the storage folder writeable and restart the server:

sudo chmod -R 777 app/storage
sudo service apache2 restart
First run of Laravel 4
Now edit app/routes.php and add a new route:
Route::get(‘/mytest’, function() {
    return “Oh yeah, this really works !”;
});

Now you navigate to your the browser.
http://your-domain-or-ip/mytest

Drupal caching using cache_get and cache_set

Drupal functions cache_get and cache_set are basically used for static caching temporarly and permanently in the cache table of the drupal database.
Using cache_set function is fairly simple below is a syntax of how you can implement this.
cache_set(key, value, 'cache', CACHE_TEMPORARY); or cache_set(key, value, 'cache', CACHE_PERMANENT); 
cache_set takes four parameters first the key parameter, this parameter is unique for the system and is used to differentiate between other records in the table also this key is used to retrive data from the database the second parameter is the value that is the data to be stored in the key.
Now the third parameter is the table name that is table to store the data in and the fourth parameter is the cache type that is temporary or permanent, if temporary it will flush the cache when the cron runs and if permanent cache type is selected the cache will never expire.
cache_get function is used to retrive the data from the cache table based on the key in the table. Below is the syntax of how you can implement this.
cache_get(key);
The cache_get function when invoked by a key returns an object which contains the cache id as cid the value as the data variable and the expire that is the time it will expire. If expire is set to zero the cache will never expire. Below is a full syntax of how this is implemented.
  $tempdata =  cache_get('cachekey');
  if(isset($tempdata->data)) {
    return $tempdata->data;
  } else {
    $value = "Test Cache Value";
    cache_set('cachekey', $value, 'cache', CACHE_TEMPORARY);
    return $value;
  }