?
Solved

Use HTTPS instead of HTTP in apache

Posted on 2014-11-24
10
Medium Priority
?
288 Views
Last Modified: 2014-11-29
Hi,

I have created a webpage using PHP to telnet into the router. But instead of the regular http access I want to access the same webpage using https. I have installed the wampserver software.

How can I achieve that?
0
Comment
Question by:Vipin Kumar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 11

Expert Comment

by:Radek Baranowski
ID: 40462853
If I understand you right, you have a piece of php code which connects to a telnet port on some remote server, right ?

Now, the secure version of telnet is ssh - secure shell. Therefore you might use ssh2 function to open ssh connection to remote server, example is given here:

http://php.net/manual/en/function.ssh2-connect.php

there are many ssh2 functions in default PHP, the full list is here:

http://php.net/manual/en/book.ssh2.php

If you would like to authenticate with username and password, you are most likely to use this one:

http://php.net/manual/en/function.ssh2-auth-password.php  <- check out the example from this page:

<?php
$connection = ssh2_connect('shell.example.com', 22);

if (ssh2_auth_password($connection, 'username', 'secret')) {
  echo "Authentication Successful!\n";
} else {
  die('Authentication Failed...');
}
?>

Open in new window


cheers, hope this helps
0
 
LVL 29

Expert Comment

by:Jan Springer
ID: 40462886
if you want https, for that site or that page (whichever you prefer), use mod_rewrite to write any http header into https within your httpd.conf.
0
 
LVL 30

Assisted Solution

by:Kerem ERSOY
Kerem ERSOY earned 2000 total points
ID: 40463388
Hi,

As far as I understand you want to redirect your PHP page to HTTPS if it was requested with HTTP. If you add this code snippet in the beginning of your code it would redirect the page to HTTP is launcehed with HTTP:

<?php
if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == ""){
    $redirect = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    header("Location: $redirect");
}
?>

Open in new window


If you want to redirect all your web server to https you can add this directive to your document root in httpd.conf:

Redirect permanent / https://www.mydomain.com/

Open in new window



Cheers,
K.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 1

Author Comment

by:Vipin Kumar
ID: 40463613
@ Jan Springer

How do i implement mod_rewrite to use https instead of http?
0
 
LVL 1

Author Comment

by:Vipin Kumar
ID: 40463617
@ Kerem ERSOY

I tried using Redirect permanent / https://www.mydomain.com/ but I was not successful. How do I use this for my web application? What you have provided is for a domain. I have an web application which will be running over the intranet
0
 
LVL 1

Author Comment

by:Vipin Kumar
ID: 40463620
@ Radek Baranowski

I have to ssh into a cisco router not a windows server. How do I pass on my commands to the router using ssh and then capture the output and display the same on web?
0
 
LVL 1

Accepted Solution

by:
Vipin Kumar earned 0 total points
ID: 40463633
@ Kerem ERSOY

I tried using the below code to redirect my webpage, but the webpage it is redirecting to https but the page is not opening what m I missing or is there any configuration that I need to in Apache to open a HTTPS page

<?php
if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == ""){
    $redirect = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    header("Location: $redirect");
}
?>

Open in new window

0
 
LVL 1

Assisted Solution

by:Vipin Kumar
Vipin Kumar earned 0 total points
ID: 40463925
Below link contains the steps to configure the WAMP Server to accept SSL connection.

Step 1 - to configure wamp server to accept SSL connection

Then the next step specified by Kerem ERSOY needs to be implemented to redirect http to https. If one page needs to be redirected then implement the code on that page's beginning if all pages are to be redirected then it should be there on all the pages
0
 
LVL 11

Expert Comment

by:Radek Baranowski
ID: 40463972
http://php.net/manual/en/function.ssh2-exec.php

returns the stream of result data if command was successful
0
 
LVL 1

Author Closing Comment

by:Vipin Kumar
ID: 40471388
As no where it is mentioned that WAMP server also needs to be configured to accept SSL connection
0

Featured Post

Bringing Advanced Authentication to the SMB Market

WatchGuard announces the acquisition of advanced authentication provider, Datablink, with one mission – to bring secure authentication to SMB, mid-market, and distributed enterprises with a cloud-based solution, ideal for resale via their established channel & MSSP community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question