I'm trying to connect to a SFTP server and upload a file through php.
I've installed php lib (php_ssh2) but it's failing at this point:
<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$sftp = ssh2_sftp($connection);
?>
The last line is returning false and the following warning is shown on the log:
Warning: ssh2_sftp(): Unable to startup SFTP subsystem: Unable to request SFTP subsystem
I don't know if it has something to do with the error that I'm getting when I try to connect to the same server through commandline with sftp command:
sftp error subsystem request failed on channel 0
I've tried replacing the line Subsystem sftp /usr/lib/openssh/sftp-server of my sshd_config by internal-sftp as some people suggested, but it didn't work (I expected that as I think it's for connecting to a local sftp server)
I've tried reinstalling openssh-client and openssh-server (although I think the last one shouldn't be required, as the server is an external host).
I've tried to login to the SFTP with Filezilla and everything works smoothly.
Also, I've tried phpseclib, but it's giving an error on the login, even with the proper credentials.
So, I'm unable to upload a file to the sftp server neither by PHP nor by commandline.
Do you have a queue of what I'm missing here?
EDIT:
The phpseclib log is too long, I've pasted it here (please tell me how to attach it in case it's not allowed to put this kind of links):
http://pastebin.com/Kkw027nR
This is the FileZilla log http://pastebin.com/6u90646Q, I've noticed that maybe the problem is related with this two lines but I'm not sure:
2013-05-07 08:16:15 2704 3 Traza: Opened channel for session
2013-05-07 08:16:15 2704 3 Traza: Primary command failed; attempting fallback
Thank you,
Javier
It seems that there were a problem on the server's config that was causing the connections attempts to fail.
Anyway, both FileZilla and Putty (psftp) were able to connect successfully by some kind of fallback in case of failure.
I can't explain the details, but after sharing the logs with phpseclib's creator, he has been able to implement this fallback on his lib as well, so now I'm able to successfully connect to the sftp server using the latest version of phpseclib (https://github.com/phpseclib/phpseclib).
For more details about the problem, check this out: http://www.frostjedi.com/phpbb3/viewtopic.php?f=46&t=168285
Special thanks to TerraFrost for his patience and help to get the solution.
Related
I have implemented a phpGrid that works in my dev environment but just keeps saying:
Error: Could not connect to the database
in production
I am logging failed attempts at MySQL connections in the logs on and if I put in a dodgy username and password in the conf.php files username/password it does not show up in the log (I've tested the log is working by attempting to connect with bad credentials via a terminal.
The host is just "localhost" I am using PDO connections elsewhere within my code and the are all connecting using "localhost" so I see now reason why this would be a problem.
In the conf.php I've turned on:
define('DEBUG', true);
And on my grid I have:
$dg -> enable_debug(true);
But I just keep getting this stupid error that tells me nothing about what's really going on...
It happened to me as well. Finally I was able to figure out. The reason is mySQLi was not enabled on the server. I enabled it and it works now.
Sorry, i cannot add a commant and sorry for my english.
If you are using PHP 5.5 try:
error_reporting=E_ALL^E_DEPRECATED
at top of the page for the time being.
For the files on your production machine: proof if they are still in utf-8 encoding
everyone. I'm a student and very inexperience newbie with PHP . Before you mark this as irrelevant or duplicate or anything. Hear me out please, I need to connect to my school host to test out my codes, I have installed XAMPP, phpmyadmin 4.0.4.1 using notepad++ text editor, PHP5.4.19 and FTP WinSCP a program similar to filezilla
uploaded all the files to the server side public html and tried to run the file in browser
by using: my_school_link/my_username/
and I have this error
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on
line 3 and this is my connect.php file.
<?php
mysql_connect('host_name', 'user_name', 'password');
mysql_select_db('my_database_name');
?>
I cannot locate my /tmp/mysql.sock, * i have tmp folder in xampp folder but inside i cant find mysql.sock*
and I have tried the following
view nearly every post on this matter (i don't understand what is being said, thou i did try out some of the suggestions and answers)
have entered the correct hostname, username and password
run as admin
checked if mysql is running ( it is so is Apache)
MySQL socket specified in php.ini was never edited so it is in default mode
cant locate mysql config file, or my.cnf, or etc folder
What could the problem be? Please if anyone could help me, please tell me what's wrong.
Please provide a step-by-step guide. and file extensions if need to save files....
Is there any additional things i can add to help anyone understand my problem better?
if yes, please let me know...this is my last resort so Thank you so very much in advance for any help.
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on
line 3 and this is my connect.php file.
This error appear when your mysql server is not running. If you are on an shared hosting, it means that your provider has temporary stopped mysql server (some hacks needed to be solved, or doing updates etc.)
If you are on WAMP or local machine, you should check your /etc/my.cnf file it contains something like this:
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
Another reason may be that you are using the wrong host name while connect.
Don't use mysql_connect it is deprecated and instead you should use MySqli
all,
My log4php gets this error in a new server environment.
PHP Warning: log4php: [LoggerAppenderPDO:default]: Failed connecting to database. Closing appender. Error: could not find driver in ../log4php/LoggerAppender.php on line 283
I have the same settings for log4php (1. config.xml file 2.same log4php version) as my local development, which works perfectly. I tried simply log to a file in the new server, it works, which means the log4php lib has no problem. And I can even log to the database in the new server from my local script using local log4php lib, which means my server can recognize log4php logging.
I think this should related to the authentication to the database from the server itself. But have no idea what is the problem and how to solve it. Any idea?
Work around:
After some searches and tests(script using PDO not mysqli to connect to the database,reference here) , I confirm the problem is caused by lacking of pdo_mysql related driver, as akluth pointed out. I tried to re-install php5-mysql, but it failed, I tried to modify php.ini, got more errors. I think that is because the mysql-cluster settings maybe different from normal mysql. As the new server is a production server, we decide not to touch it and move the scripts to other server with normal mysql settings.
I am trying to query a remote LDAP server in a secure connection in a Windows php local test environment. I think I must have the access granted correctly because I can use an LDAP Browser application and that connects to the remote server fine. Also, if I do ' telnet remoteserverurl.com 636' then a blank screen shows up in command prompt, so I am at least connecting. But in my following .php code I get an error on bind: "PHP Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in line..."
The same code works in a Linux server. I think there is some kind of missing LDAP libraries in my local php environment for secure LDAP connection? Anyway, here is the code:
$ds=ldap_connect("ldaps://serveraddress.com", "636"); // remote server
//$ds=ldap_connect("ldap://localhost", 389); // works
//putenv('LDAPTLS_REQCERT=never');//doesn't help with secure ldap
//ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); //works for local LDAP server (Open LDAP)
$r=ldap_bind($ds, "cn=xxx,ou=proxy,o=xxx", "passwordxxxx");//throws error for remote
Any idea? Thanks!
Know this is older, but I recently ran into a similar issue when using wordpress 3.x & 4.x on windows 2008 & 2012 (IIS 7.x & 8.x, PHP 5.6).
I had written a plugin for ldap authentication for wordpress - as was trying to get LDAPS (ldap secure over port 636 working).
Couple things:
When using PHP LDAPS, the documentation states you simply prefix the LDAP server with ldaps://. So server1.domain.com for LDAPS should be ldaps://server1.domain.com/ ...note you don't need to pass the port at all for the connection method (per http://php.net/manual/en/function.ldap-connect.php). This is very similar to what the original question has in its submission.
The windows PHP libraries are hard-coded to look for an open ldap config file (ldap.conf) in C:\openldap\sysconf\ldap.conf.
Create the text file mentioned in #2 above - this is where you point to your certificate store. Once you create this file, you can put in TLS_REQCERT never … but this means no certs are verified and all are trusted automatically (essentially) - should only be for testing...never for production, as you defeat part of TLS/SSL security measures (i.e. certifying you are indeed talking to the host you believe you are connected to).
Instead of the insecure TLS_REQCERT never option that seems to be a popular (and perhaps misguided) suggestion on the interwebs...grab the common public cert authority list used by curl and similar - http://curl.haxx.se/ca/cacert.pem. This essentially is what firefox comes with for public certificate authority trusts (i.e. it's why you can install firefox and go to https://amazon.com without a cert warning, etc.).
Drop the cacert.pem file you downloaded (it's just a text file with a bunch of certificate hashes and descriptions) with your PHP install. For instance, say i dumped it with my php install in c:\php5\cacert.pem. Your location may differ, but put it somewhere it can be accessed and will be grouped with php stuff since it is related. Here's a couple shots of the contents of the cacert.pem file to give you an idea of what's inside.
Edit the C:\openldap\sysconf\ldap.conf and add a line for the command TLS_CACERT like pictured.
This should allow you to now trust public, valid certificates just like modern web browsers do, etc. Note that it won't fix internally-issued or self-signed certificate trust issues. But you can easily do that as well by adding your own cert hashs to the cacert.pem file.
To add another certificate as a trusted has in the cacert.pem file, simply get a copy of the certificate in question (you just need to export it to .cer in base64 format - don't need the private key and extension really doesn't matter - just needs to be a hash output). If you've exported it in the right format, you can open the certificate file and see the hash - it will be similar (but not identical) to the screenshot here of the Thawte Server CA example. Simply append the hash you exported to the cacert.pem file and it will be trusted. If you are looking to be clever, you can instead import the issuing certificate for your private-issued certificate - this would then trust any cert signed by the imported cert. If in doubt, you can always just import the presented certificate.
After making such changes, I found it best to restart the web server (iis manager -> web server node -> restart option) so everything using php was reset.
For extra credit, you can use the same cacert.pem file for the curl implementation by editing your php.ini file and putting the full path to the cacert.pem file in the line curl.cainfo =.
Again, I know this is an older post, but I wanted to share what I had learned while hooking up wordpress to eDirectory via LDAPS.
Check your PHP libaries
<?php phpinfo() ?>
Since you can connect using a LDAP client i expect your LDAP runs SSL
Did you copy your SSL Cert?
Copy the server certificates to sys:/php5/cert directory. This location is configurable in php.ini file.
Use "ldaps://" prefix for host name argument or a value of 636 for port number argument in ldap_connect call.
I got this working! #s.lenders' 'answer' (thanks for that) pointed out toward some Certificate issue and indeed it was a Certificate issue. The remove LDAP Server had its Certificate in expired state--I got a warning about that even when I connected using the desktop application (SoftTerra LDAP Browser). So imported the Certificate to my Windows Certificates--SoftTerra LDAP Browser application allowed me that option. And, voila!. SSL LDAP calls are working.
** Update: Not sure if the above Certificate thingy helped or not but here is something more concrete which helped me: It looks like the php LDAP libraries look for a certain conf files; hard-coded to: C\OpenLDAP\sysconf\ldap.conf ?! So I basically created new folders per this info and put an ldap.conf file with nothing but 'TLS_REQCERT never' and that helps! I have tested it..if I were to remove this file then my Secure LDAP queries don't work and fail in the 'bind' step. Note, I am comfortable with the 'never' in my conf because this will be only on my own workstation.
Also note I am on a Windows 7 running IIS 7+ **
Hope this helps someone.
I am running PHP (on Apache/Windows) and I am trying to connect to a LDAP server to authenticate users. PHP's LDAP plugin is just OpenLDAP.
While I've been successful in connecting to the LDAP server without SSL, I can't do it WITH SSL. I know I got everything right, except OpenLDAP won't connect to the server without the CA certificate. The connection fails and it gives me this error:
"error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed"
Now, I know I can suppress this behavior by setting TLS_REQCERT to "never" in the ldap.conf file. But the plugin on windows is just a dll file; and I have no idea on where to put the .conf file. Does anyone know?
Thanks in advance.
Apparently you need to place the ldap.conf file in the following directory:
C:\openldap\sysconf\
Since it's hardcoded into the DLL file. PHP.net Manual: LDAP Functions - Comment #47427