Tag Archives: PHP

HTTPS in RHEL and PHP in less than 5 minutes !

Enabling HTTPS will give your application an added layer of security. The SSL layer will encrypt all communication that happens between the customer’s browser and your application. In this article, I am not describing things in detail about each security option. This is good enough to get started in most of the cases.

Login to Redhat Linux as user root and run the below commands to install apache ( with ssl support ) and PHP version 5.

#yum install httpd mod_ssl openssl php5
#service httpd restart

You should be able access your server via HTTPS now using the browser like https://yourservername.domain/application/login.php . You are now using a self signed certificate for the server. Your browsers might warn you about this , but it is safe to accept it and continue.

If your server was using HTTP only and you recently upgraded it to HTTPS, Here’s a quick and dirty method in PHP to detect if your users are still using HTTP and redirect them to HTTPS. All you need to do is include this code in the start of your php file.

< ?php
$loginURL="https://yourserver/application/login.php" ;
if($_SERVER['HTTPS']){
echo <<<REDIRECT
Redirecting to ... $loginURL 
<script>
window.location($loginURL);
</script>
REDIRECT;
}
?>

As you see, a little time spent can go great lengths towards securing your website and applications. Feel free to comment. 🙂