How to install SSL Certificates with Apache 2 on Ubuntu 12.04

Please note that commercial SSL certificates require a unique IP address each for SSL-enabled site, although multiple non-SSL sites may also share that IP address.

Step – 1 Create a Certificate Signing Request

A CSR is an encrypted body of text. Your CSR will contain encoded information specific to your company and domain name; this information is known as a Distinguished Name or DN.
In the DN for most servers are the following fields: Country, State (or Province), Locality (or City), Organization, Organizational Unit, and Common Name. Please note:
1. The Country is a two-digit code — for the United States, it’s ‘US’. For countries outside of the United States,
2. State and Locality are full names, i.e. ‘California’, ‘Los Angeles’.
3. The Organization Name is your Full Legal Company or Personal Name, as legally registered in your locality.
4. The Organizational Unit is whichever branch of your company is ordering the certificate such as accounting, marketing, etc.
5. The Common Name is the Fully Qualified Domain Name (FQDN) for which you are requesting the ssl certificate.
If you are generating a CSR for a Wildcard Certificate your common name must start with *. (for example: *.digicert.com). The wildcard character (*) will be able to assume any name that does not have a “dot” character in it.
To remain secure, certificates must use keys which are at least 2048 bits in length. If your server platform can’t generate a CSR with a 2048-bit key

mkdir /etc/apache2/ssl
 cd /etc/apache2/ssl
 openssl req -new -newkey rsa:2048 -nodes -keyout yourdomain.key -out yourdomain.csr

Replace yourdomain with the domain name you’re securing. For example, if your domain name is viralsolani.co, you would type viralsolani.co.key and viralsolani.co.csr.

• This begins the process of generating two files: the Private-Key file for the decryption of your SSL Certificate, and a certificate signing request (CSR) file (used to apply for your SSL Certificate) with apache openssl.

• Open the CSR file with a text editor and copy and paste it (including the BEGIN and END tags) into the form from where you purchase your SSL certificate.

• Save (backup) the generated .key file as it will be required later for Certificate installation

Execute the following command to protect the key:
chmod 400 /etc/apache2/ssl/www.yourdomain.com.key

Execute the following command to protect the signed certificate:

chmod 400 /etc/apache2/ssl/www.mydomain.com.crt

Step – 2 Get the Certificate Authority Root Certificate
In My case it is Go Daddy. So you need to go from wherever you purchase your SSL certificate and you need to submit the below generated CSR. And you can then download the certificate.
You will get two files. I’ve upload that two files in same folder where I’ve put my CSR and Private key that i.e /etc/apache2/ssl/
Step – 3 Configure Apache to use the Signed SSL Certificate.

This configuration vary depend upon OS and version of that OS. So I’ve installed Ubuntu 12.04 and to configure the certificate you need to do below steps.
You need to configuration in Apache virtual hosting file.
So now you need to go: /etc/apache2/sites-available/default-ssl

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin viral.solani@gmail.com

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

SSLCertificateFile    /etc/apache2/ssl/yourdomain.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/yourdomain.com.key
SSLCertificateChainFile /etc/apache2/ssl/gd_bundle.crt

</VirtualHost>
</IfModule>

Basically you need to locate yourdomain.com.crt , yourdomain.com.key and gd_bundle.crt.
Now last thing you need to do is restart you apache with the following command

 /etc/init.d/apache2 restart

You should now be able to visit your site with SSL enabled. Congratulations, you’ve installed a commercial SSL certificate!

2012 in review

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here’s an excerpt:

4,329 films were submitted to the 2012 Cannes Film Festival. This blog had 14,000 views in 2012. If each view were a film, this blog would power 3 Film Festivals

Click here to see the complete report.

Understanding Abstract Classes in PHP

Abstract classes are an often misunderstood feature of PHP object-oriented programming (OOP) and the source of confusion when considered versus an Interface. The obvious reason for using an Interface is that a child class can implement multiple interfaces but extend only a single abstract class. However, if multiple inheritance is not required then people often go with abstract classes just because they provide the option of later adding base functionality within the abstract class. This is not entirely unreasonable but the reasons for creating abstract classes should be more than that.
Why Use Abstract Classes?

An Abstract class provides concrete base functions as well as abstract functions that must be implemented by concrete child classes—binding them into a contract so to speak, if they wish to make use of the base functionality.

This is a subtle but important point and this is where abstract classes really shine. They can call abstract functions from within base concrete functions. Jumping straight to an example is the clearest way to explain this.

abstract class Animal {
  function greeting() {
    $sound = $this->sound();      // exists in child class by contract
    return strtoupper($sound);
  }
  abstract function sound();      // this is the contract
}

class Dog extends Animal {
  function sound() {              // concrete implementation is mandatory
    return "Woof!";
  }
}

$dog = new Dog();
echo $dog->greeting();            // WOOF!

This opens up a whole lot of interesting possibilities. For example, you can write a drive() function that calls $this->start(); $this->accelerate(); in an abstract class. Then create a motorcycle class that defines its own start() and accelerate() functions that may be different from those in the car class. In turn, the motorcycle and car can both be driven by just calling drive() without having to implement it locally.
Characteristics of Abstract Classes

Make a note of these characteristics to lock down your understanding of abstract classes:

  • Single inheritance. Child classes can extend only one class at a time.
  • Abstract classes cannot be instantiated — no new Animal();
  • Abstract classes can define class variables of type const only.
  • Abstract class A can be extended by another abstract class B. Abstract class B can implement none or any of the abstract functions in A.
  • In the previous case, a child class C which extends abstract class B must implement all abstract functions in B as well as the abstract functions in A which have not already been implemented in B.
  • The signature of the concrete functions and abstract functions must be the same. However, if an abstract function is defined as abstract function speak($greeting); then it is okay to implement it as function speak($greeting, $shout = FALSE) but not function speak($greeting, $shout).
  • The visibility of functions in the child classes must be the same or less restrictive than the parent class. Thus, a protected abstract function can be implemented as either protected or public but not private.
  • Declaring functions as static abstract throws a strict warning in PHP 5.2 or earlier, however, as of PHP 5.3 this is allowed.

Superb way of adding PHP variables to Javascript/Jquery in Zend Framework

Rupesh Patel Web Developer

If you are using any MVC framework(these days I think most of us uses MVC) in php, then you might needed to assign variables from php to javascript, Some times you might have to add tens of parameters to javascript. And this thing leads to dirty code like below in any of your view files..

and the main problem with this solution is you have to do it explicitly for each of variables. And What if you want to add an array to javascript ?

I have done some thing interesting to cop this in Zend Framework , Similar can be done in any of MVC systems if views and control code is differentiated.

1) Create a view file at application/views/index/include_js_vars.phtml  and paste following code in this file.

2) now most probably you are including java scripts in your layout file application/layouts/scripts/layout.phtml
so render our include_js_vars view before [ echo…

View original post 124 more words

Nice Story……

2Motivate

There was a king who was a great admirer of art. He encouraged artists from all over his country and gave them valuable gifts.

One day an artist came and said to the king, “Oh King! Give me a blank wall in your palace and let me paint a picture on it. It will be more beautiful than anything you have ever seen before. I promise you shall not be disappointed.” Now, the king happened to be constructing a big hall at the rear end of the palace. So he said, “All right you may work on one of the walls in the new hall.”

So the artist was given the job and he was very pleased indeed. Just then, another young man said, “Oh King! Please allow me to work on the opposite wall. I too am an artist.”

The king said, “What would you like to make?”

The…

View original post 448 more words

PHP SDK & Graph API base Facebook Connect Tutorial

Hello Friends

In My current application I’ve used facebook Graph API to fetched data from facebook with the help of  PHP SDK. I’ve explored so many tutorials on web but I found some links are very helpful and easy to understand Here I’m sharing those links. By surfing through these links you can get to know these below things

1 . How you can create your application in Facebook and How you can use APP ID and APP Secret? 

2. How you can connect to Facebook from your Application?

3. How you can fetch data with the help of Facebook Graph API and PHP-SDK?

4. How you can Design your Facebook Application?

So here are some useful links.

  1. http://www.londatiga.net/it/how-to-create-facebook-application-with-php-for-beginner/
  2. http://thinkdiff.net/facebook/php-sdk-3-0-graph-api-base-facebook-connect-tutorial/
  3. http://net.tutsplus.com/tutorials/php/wrangling-with-the-facebook-graph-api/
  4. http://www.joeyrivera.com/2010/facebook-graph-api-app-easy-w-php-sdk/
  5. http://net.tutsplus.com/tutorials/javascript-ajax/design-and-code-an-integrated-facebook-app/

To Create a New Application in Facebook.

https://developers.facebook.com/apps

Graph API

https://developers.facebook.com/docs/reference/api/

PHP SDK refrence

https://developers.facebook.com/docs/reference/php/

FB Tool for Graph API Explorer

http://developers.facebook.com/tools/explorer

Hope it helps.


profile for Viral Solani at Stack Overflow, Q&A for professional and enthusiast programmers

How to Install Apache, PHP, MySQL and PHPMyAdmin in Ubuntu 11.04

If you are a PHP based web developer, you need all the software running and configured properly. Here I am talking about installing them One by One in your Ubuntu Desktop. We are installing all the applications from terminal.

How to Open Terminal:
So, to fire up the terminal follow any of these steps:

  1. If you are running Unity Desktop, click on the Ubuntu Logo at top left corner and type Terminal in the search application bar. Then click on the terminal icon.
  2. If you are running GNome Desktop, click on Applications->Accessories->Terminal
  3. For shortcut, you can also press Ctrl+Alt+T at once, to open the terminal.

How to install Apache:

1. Make sure you have the internet connection. To install apache execute the following command in the terminal:

1
sudo apt-get install apache2

It takes some time to download and install apache. After the setup completes, type http://localhost/ in your browser window to make sure apache is installed and running properly. If you see the page with It Works!, the setup of apache2 completes successfully.

How to Install PHP:

1. To install PHP 5, type following commands in the terminal one by one:

1
2
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5

The first line installs PHP5 in the computer. The second one provides the PHP5 module for the Apache 2 webserver. If second one is not installed, then Apache cannot parse PHP codes in a web page.

2. After installing PHP5 and PHP module for apache, restart the apache with following code:

1
sudo /etc/init.d/apache2 restart

3. While restarting the apache server, if you see a warning as “Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName”, then you can fix this by creating a file with the Server name. To do this type the following command in the terminal:

1
sudo gedit /etc/apache2/conf.d/fqdn

When the text editor opens, type “ServerName localhost” inside the file and click Save. Then close it. Now restart again with the above code and you will see that the warning message has gone.

4. Now, we have successfully installed php and apache web server. However, still we don’t know if PHP is successfully installed. To check this, create a file inside /var/www/ folder named test.php as:

1
sudo gedit /var/www/test.php

and write following code in it

1
<?php   phpinfo();  ?>

Save the file and type this in browser: http://localhost/test.php

If you see the various information about PHP and installed modules there, then we can confirm that Apache is parsing PHP codes. Hence the installation is successful up to this point.

How to Install MySQL:

1. To install MySQL Server in ubuntu, type following code in terminal window:

1
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

This will install latest mysql server and other necessary PHP modules for recognizing mysql functions from PHP code. While installing MySQL server, you may require to enter the password for MySQL root user.

How to Install PHPMyAdmin:

1. To Install PHPMyAdmin, type the following codes in the terminal:

1
sudo apt-get install phpmyadmin

While installing PHPMyAdmin, you may require to select the web server. In such case, tick the Apache2 Server and proceed with the installation. You may also require to input MySQL root user password during installation.

Once the installation completes, type this in your browser window to confirm the successful installation of PHPMyAdmin: http://localhost/phpmyadmin/index.php.

Now, you are finished. Your environment is setup and you can enjoy using all these applications. Next, you can install other applications that may be necessary such as Eclipse, GIMP etc.

The Right Way to Get a File Extension in PHP

I made a recent search on retrieving file extensions in PHP.

I found out that a lot have been re-inventing the wheel. They have been creating code for functionality that PHP already has. This is one example of re-inventing the wheel

function get_file_extension($file_name)
{
return substr(strrchr($file_name,’.’),1);
}

Another example was this:

function file_extension($filename)
{
return end(explode(“.”, $filename));
}

PHP already has a function that does the same thing and more.

Welcome, pathinfo.

$file_path = pathinfo(‘/www/htdocs/your_image.jpg’);
echo “$file_path [‘dirname’]\n”;
echo “$file_path [‘basename’]\n”;
echo “$file_path [‘extension’]\n”;
echo “$file_path [‘filename’]\n”; // only in PHP 5.2+


// Output
/www/htdocs
your_image.jpg
jpg
your_image

A much easier way to use the constants:
[PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME]

PATHINFO_DIRNAME – the directory
PATHINFO_BASENAME – the file name
PATHINFO_EXTENSION – the extension
PATHINFO_FILENAME – the filename without the extension

echo pathinfo(‘/www/htdocs/your_image.jpg’, PATHINFO_EXTENSION);

// Output

jpg