Jump to content

Windows PHP connect into LINUX server


rocket1356

Recommended Posts

Hi,

 

I want to built a windows php website---> connect to the linux box--->read all settings value from the .ini files->display it into the php website->user can then change the values->save the .ini file base on the user modification close the file-->for back up reason of settings, also save the values into SQL database. I also need to reboot the linux box after apply changes to the .ini.

 

Anyone knows how to approach this problem? What do I need? Does php have a built in ssh?

 

Thanks

Link to comment
Share on other sites

cant you just use the windows server to connect to the linux server by finding the path of the .ini file

eg.

$lines = file('path to php.ini');
foreach ($lines as $num => $line) {
echo "Line-($num): $line<br />";
}

 

or just use the include function

Link to comment
Share on other sites

soz i just realised you wanted to let it be editable... just use the fopen function

<?php 
$file = 'path to php.ini' ; 
$content = file_get_contents($file); 
//edit some of this
echo "
<form action='file update.php'>
<textarea name='new_content'>$content</texarea><br />
<input type='submit' value='submit' />
</form>
";
?>

 

now you need to update the file contents to the textarea variable

 

<?php
$file = 'path to php.ini' ; 
fopen ($file);
fwrite($file, $_POST[new_content]);
fcolse($file);
?>

Link to comment
Share on other sites

So I connect to the LINUX box through what command? Can I use ssh2? Do I have to install ssh library or some sort?

 

Can I change their IP/Hostname by editing their config. files and then reboot?

 

Also, the .ini I am talking about is some file that controls the PLC(Input/Output relays).

 

Thanks.

Link to comment
Share on other sites

Can we start over?

 

Is this correct?

 

the customer has computer (SBC? EMBEDDED?) with Linux.  The Device has an INI on it that has to be edited from time to time to make it do what the user wants.  You need to let them edit the INI remotely.

 

Correct so far?

 

There are several solutions, but I'll wait for you to tell me if I got it right or if I'm totally lost on what you want.

Link to comment
Share on other sites

We have an in-house LINUX OS which our developer created. This LINUX is running on a 512mb flash. This LINUX will have serial card(with cables) controlling a motherboard full of relays(Infoo is not important, but just to let you know what it does). Because the serial card has settings, we created .ini files to configure the serial cards. When we ship out the LINUX box with our LINUX OS, we preconfigure the IP address that the customer gives to us.

 

OK, I hope it is cleared up to now. Now the customer has the LINUX box. They will boot up the machine. This machine will be online. They will now need to modify the .ini files to match the speed of communication they desired. Because they have multiple machines, it would be a hassle for them to modify each one after booting up.

 

So my idea is to create an installation script(PHP website), in a WINDOWS environment, that will interface with the LINUX box to change the settings in the .ini files.  This script will ask how many LINUX box they have. It will need to connect into each one(can you connect into more than 1 LINUX machine with the PHP script?), reads the current .ini info in the LINUX box, then display it into the PHP website. The user can then edit the fields in the PHP website. They can hit 'Apply' and this will apply the settings to the LINUX box. I will then need to reboot the LINUX machine(via the PHP website), to get the changes. Can I also change the IP address(via the PHP script)? The customer might change their mind about the IP address they gave to us(but I do not think that this is a priority yet).

 

Please let me know if this is not clear.

 

Thanks

 

 

Link to comment
Share on other sites

here is how I would do it:

 

First, I'd add an ftp server to the linux box(s).

 

1.  Pull the existing .ini from the linux box(s) as needed with php/ftp.

2.  Edit the .ini file with php/html

3.  Push the new .ini to the linux box with php/ftp

 

should work slick and clean

 

need more details?

 

Link to comment
Share on other sites

Sure I need more details. How big is the ftp server program. As the LINUX box can only handle a total of 512mb(flash drive). I think it has a ssh server/client program in there because I can manually use a SSH program to ssh into the LINUX box.

 

Is there another solution if the ftp server program cannot be installed in the LINUX machine?

 

Right now I am stuck on connecting to the LINUX machine.

 

Another problem is: Do the customer need to install apache server and php on their WINDOWS machine to get the php website to start up?

They are not hosting the website, they are just using the website to remotely connect into the LINUX machine.

 

Thanks.

Link to comment
Share on other sites

Do you need apache server to view a php website? I thought its for hosting only.

 

No you don't have to use apache but it's fairly easy to setup. IIS can also be configured to parse PHP scripts. You might want to look into one of the prebuilt configurations like WAMP or XAMPP. If your PHP server is going to be running on a windows based computer. If you have a developer that has already setup a mini Linux for these embedded systems they should be able to configure a Linux based server for you.

 

EDIT: You could also use the command line interface in windows.

Link to comment
Share on other sites

You can do this a ton of ways.  You basically need to be able to talk to a linux box from a windows box. 

 

ssh can do that, but ftp is VERY SMALL footprint.  I think FTP is still the way to go. You can run linux with LAMP & ftp, etc. with DSL Linux from a 256mb thumbdrive, so I think you should have no problem with FTP server.  It is the least work to do exactly what you want.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.