Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to open my website login page with https only, I check that SSL is enable on server here is basic information of server return by phpinfo();

    PHP Version 5.2.14
Configure Command   '--with-openssl'  '--enable-zip' 
Registered Stream Socket Transports     tcp, udp, unix, udg, ssl, sslv3, sslv2, tls 
                               curl
cURL support    enabled
cURL Information    libcurl/7.10.6 OpenSSL/0.9.7a ipv6 zlib/1.2.3
                              openssl
OpenSSL support     enabled
OpenSSL Version     OpenSSL 0.9.7a Feb 19 2003

my basic code on header.php is

if($_SERVER['SERVER_PORT'] != 443) {
   header("HTTP/1.1 301 Moved Permanently");
   header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
   exit();
}

but it always give below error:
The connection has timed out
The server at www.mywebsite.com is taking too long to respond.

although same code works perfectly at localhost...where phpinfo() returns

PHP version 5.3.1
    openssl
OpenSSL support     enabled
OpenSSL Library Version     OpenSSL 0.9.8l 5 Nov 2009
OpenSSL Header Version  OpenSSL 0.9.8l 5 Nov 2009

I have 2 Questions

  1. Do I need to update my SSL?? or how do I run website on https on server???
  2. How to open only 2 pages in https and rest of all in http

Thanks

share|improve this question

migrated from stackoverflow.com Feb 7 '11 at 8:37

This question came from our site for professional and enthusiast programmers.

2  
Whether your site is served over SSL or not has nothing to do with whether PHP has the openssl module. It's a web server (Apache/IIS) level protocol and gets configured there. Search the web or serverfault.com –  Dan Grossman Feb 7 '11 at 7:04
    
so how do i make my web to open directly in https??? –  diEcho Feb 7 '11 at 7:08
    
In Apache, you configure mod_ssl, tell the server to listen on port 443, create a virtual host entry for port 443 and this hostname, specify the locations of a private key and signed SSL certificate file (which you bought from an SSL certificate provider), restart the web server... –  Dan Grossman Feb 7 '11 at 7:12
    
@Dan in which file have to write , will u plz xplain it on Answer section –  diEcho Feb 7 '11 at 7:18
    
This is not on-topic for StackOverflow, it's server configuration not programming, and you can find a million tutorials on the web. –  Dan Grossman Feb 7 '11 at 7:19

2 Answers 2

up vote 1 down vote accepted

Create openssl certificate first , take help from this blog

then make necessary changes in below files

here I am also including how to set https for virtual host

/opt/lampp/etc/extra/httpd-vhosts.conf

<VirtualHost *:80>
   ServerAdmin localhost.admin
   DocumentRoot "/opt/lampp/htdocs/"
   ServerName localhost
   ErrorLog "logs/php_error_log"
   CustomLog "logs/access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@ice.cold.com
    DocumentRoot "/opt/lampp/htdocs/wish"
    ServerName ice.cold.com
    ServerAlias www.ice.cold.com
    <Directory /opt/lampp/htdocs/wish>
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog "logs/ice.cold-error_log"
    CustomLog "logs/ice.cold-access_log" common
</VirtualHost>

/opt/lampp/etc/extra/httpd-ssl.conf

<VirtualHost _default_:443>
    DocumentRoot "/opt/lampp/htdocs"
    ServerName localhost:443
    ServerAdmin localhost.admin
    SSLEngine on
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    SSLCertificateFile "/opt/lampp/etc/ssl.crt/server.crt"
    SSLCertificateKeyFile "/opt/lampp/etc/ssl.key/server.key"
</VirtualHost>

<VirtualHost ice.cold.com:443>
#   General setup for the virtual host
    ServerAdmin webmaster@ice.cold.com
    DocumentRoot "/opt/lampp/htdocs/wish"
    ServerName ice.cold.com
    ServerAlias www.ice.cold.com
    <Directory /opt/lampp/htdocs/wish>
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog "logs/ice.cold-error_log"
    CustomLog "logs/ice.cold-access_log" common

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "/opt/lampp/etc/ssl.crt/server.crt"
SSLCertificateKeyFile "/opt/lampp/etc/ssl.key/server.key"

Reference

share|improve this answer

A site which times out remotely, but which works when accessed via localhost, usually means that a firewall is misconfigured. Check that port 443 is open from the outside world.

share|improve this answer
    
var_dump($_SERVER['SERVER_PORT'] == 443) returns false, how do i enable?? –  diEcho Feb 8 '11 at 4:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.