Laravel: TTY mode is not supported on Windows platform - php

I'm trying to use the "php artisan db" command and I'm getting this error. How can I fix it? I've already seen some similar problems, but none of them helped me.
PS C:\Users\Alisson\Documents\Programming stuff\study\first-laravel-crud> php artisan db
Symfony\Component\Process\Exception\RuntimeException
TTY mode is not supported on Windows platform.
at C:\Users\Alisson\Documents\Programming stuff\study\first-laravel-crud\vendor\symfony\process\Process.php:1059
1055▕ */
1056▕ public function setTty(bool $tty)
1057▕ {
1058▕ if ('\\' === \DIRECTORY_SEPARATOR && $tty) {
➜ 1059▕ throw new RuntimeException('TTY mode is not supported on Windows platform.');
1060▕ }
1061▕
1062▕ if ($tty && !self::isTtySupported()) {
1063▕ throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.');
1 C:\Users\Alisson\Documents\Programming stuff\study\first-laravel-crud\vendor\laravel\framework\src\Illuminate\Database\Console\DbCommand.php:41
Symfony\Component\Process\Process::setTty()
2 C:\Users\Alisson\Documents\Programming stuff\study\first-laravel-crud\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36
Illuminate\Database\Console\DbCommand::handle()

The real answer is to use Linux for development, which is (I assume) fairly easily done using Windows' built-in facilities.
But, all php artisan db does is call the MySQL command line, which you can do yourself. Check your .env file to get values for the host, username, and password. Then fill them into this command:
mysql -h host -u username -ppassword
Note the missing space after -p is intentional.

Related

Php script gives different result in browser than terminal

I have a simple php script using to test bind to MS active directory, in order to use it for login to an php application. When it runs on browser, responds error: "Can't contact LDAP server", but in terminal works fine.
OS centos 7
php 5.6.40
$ldad = ldap_connect('ldap://{LDAP}.{DOMAIN.COM}','389')
or die('Cannot connect');
ldap_set_option($ldap,LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($ldap,LDAP_OPT_REFERRALS,0);
if($bind=ldap_bind($ldap,'{USERNAME}#{DOMAIN.COM}','{PASSWORD}')) {
echo "\n\nSuccess Binding!\n\n";
ldap_unbind($ldap);
}
else {
echo ldap_error($ldap);
}
Any suggestions?
Solution found and has to be shared:
SElinux was enabled. I found better to run
semanage boolean -l
to find out if it was on or off, httpd_can_connect_ldap was off so I alter to on using
setsebool -P httpd_can_connect_ldap on
I hope I helped someone with familiar problem.

PHP or Python on windows send command to remote Linux stack

I am developing a web application to send G-Code to the 3dprinter. This 3dprinter has a Linux stack. I could make it in Ubuntu application on Win by using the following command
ssh root#ip
password
python3 /usr/share/griffin/command_util.py
sendgcode G28
after typing python3 /usr/share/griffin/command_util.py,
it will retun(Cmd) type command here
I tried to use ssh2 in PHP, connection and authentication parts work. Besides,list,cd \usr\share\griffin && list also return the same result as what I get in windows cmd. But in the following code, after running the py file in linux stack, it only returns (Cmd). Nothing happened with sendgcode G28.
<?php
set_include_path('C:/xampp/htdocs/phpseclib1.0.15');
include('Net/SSH2.php');
$ssh = new Net_SSH2('ip');
if (!$ssh->login('root', 'password')) {
exit('Login Failed');
}
echo $ssh->exec('python3 /usr/share/griffin/command_util.py && sendgcode G28');
?>
The following code in Python wouldn't receive any retun value
#
import paramiko
# realize transport
trans = paramiko.Transport(('ip', 22))
# connection
trans.connect(username='root', password='ultimaker')
# Specify the transport of the sshclient object as the above trans
ssh = paramiko.SSHClient()
ssh._transport = trans
# execute command
stdin, stdout, stderr = ssh.exec_command('python3 /usr/share/griffin/command_util.py \n sendgcode G28')
print(stdout.read().decode())
# close connection
trans.close()
The Linux stack shows that sendgcode command is undocumented. I don't understand why I could use it in Windows cmd but not in PHP or Python. Any help would be super appreciated!
Just delete '&&' in PHP or '\n' in Python, then it would work

Unable to exchange encryption keys

I'm facing a hard problem at the moment and I didn't find anything online that can help me.
I want to connect from my server to another one through SSH in order to send instructions (the second server manage Wi-Fi authorizations).
As much as I can say, I think the problem occurred because we updated one server. (I'm not really sure if the problem has appeared because of it).
I'm from a Windows Server and I want to call a Linux one.
Here is the script :
function executeCommand($command) {
$infoConnection = getInfoConnection();
$out = '';
//The Warning occurs here, impossible to go further
$connection = ssh2_connect($infoConnection["hostname"], 22);
if ($connection === false) {
$error = error_get_last();
throw new Exception("
Error Type : ".$error["type"]."<br/>
Message : ".$error["message"]."<br/>
File : ".$error["file"]."<br/>
Line : ".$error["line"]."<br/>");
}
ssh2_auth_password($connection, $infoConnection["username"], $infoConnection["password"]);
$stdio_stream = ssh2_shell($connection);
sleep(2);
fwrite($stdio_stream,$infoConnection["username"]."\n");
sleep(1);
fwrite($stdio_stream,$infoConnection["password"]."\n");
sleep(1);
fwrite($stdio_stream, $command."\n");
sleep(1);
while($buffer = fgets($stdio_stream)) {
$out .= $buffer;
}
fwrite($stdio_stream, 'exit');
unset($connection);
return $out;
}
Here is the warning :
Warning: ssh2_connect() [function.ssh2-connect]: Error starting up SSH connection(-5): Unable to exchange encryption keys in ../aff_wifi.php on line 203
The line 203 is this one :
$connection = ssh2_connect($infoConnection["hostname"], 22);
When I "catch" the warning, I have this :
Error type : 2 Message : ssh2_connect() [function.ssh2-connect]:
Unable to connect to ipAdress
File: ..\aff_wifi.php
Line: 203
Do you have any idea why this occurs?
When I try to connect from my server to the other with PuTTY, everything works fine
Have a good day!
I had this problem when trying to access a focal ubuntu server from a little old xenial through ssh2_connect. The solution was to update libssh2-1. Even with php showing the old version, it worked normally.
In the xenial, I added the focal repository, then installed the latest version of libssh2-1, restarted PHP to apply and removed focal repository.
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse"
sudo apt-get update
sudo apt -y install libssh2-1
sudo add-apt-repository -r "deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse"
sudo apt-get update
Warning: ssh2_connect() [function.ssh2-connect]: Error starting up SSH connection(-5): Unable to exchange encryption keys in ../aff_wifi.php on line 203
libssh2 0.x only supports Diffie-Hellman SHA1 based key exchange. OpenSSH has disabled DH SHA1 by default. That leaves libssh2 0.x high and dry.
Option 1: Update libssh2
libssh2 1.7 and up supports DH SHA256 and ECDH key exchange. These will work with the latest OpenSSH. 1.x releases require PHP 7.
Option 2: use phpseclib
If you're stuck on PHP 5 then libssh2 isn't usable. The highest version available for PHP5 is libssh2 0.13 which still only supports the SHA1 key exchanges. An alternate library that worked for me was phpseclib. That supports diffie-hellman-group-exchange-sha256 and I was able to connect to updated OpenSSH servers.
If you have access to the SSH server, and the SSH server is running on a Linux system, the /var/log/messages and /var/log/secure logs on the Linux system might contain events that could be helpful in identifying why "Unable to exchange encryption keys" is being returned. For example, the /var/log/secure log could have something like this.
Jan 29 07:02:46 docker1 sshd[3245780]: Unable to negotiate with 192.168.0.15 port 55736: no matching host key type found. Their offer: ssh-rsa,ssh-dss [preauth]
Notice in this example that the /var/log/secure log captures "no matching host key type found" as the underlying issue. By default, the PHP ssh2_connection functions offers the following host key types.
ssh-rsa
ssh-dss
If the SSH server does not accept ssh-rsa or ssh-dss as host key types, then the /var/log/secure log will capture something like "no matching host key type found" and PHP should log "Unable to exchange encryption keys". In this scenario, the SSH server would need to be updated to accept the ssh-rsa or ssh-dss host key types.
For example, if the SSH server is OpenSSH, this could mean appending ssh-rsa and ssh-dss to the HostKeyAlgorithms line in the /etc/crypto-policies/back-ends/opensshserver.config on the OpenSSH Linux System.

Can't connect to SQL Anywhere 12 with PHP and ODBC on Ubuntu

I'm trying to get a PHP 5.3.10 installation on Ubuntu 12.04 to connect to a a remote SQL Anywhere 12 (Sybase?) server using ODBC (unixODBC). However, PHP's execution halts at odbc_connect().
PHP code:
$odbc = odbc_connect('DSN=TP189902;', 'username', 'password');
if ($odbc)
{
echo 'Connected';
}
else
{
echo 'Failed: '.odbc_error($odbc);
}
So regardless of whether or not it connects, it should be outputting one of the echos, but it doesn't. If I try using PHP's PDO library instead, I get the same result.
My unixODBC setup looks like the following. And this might be where my mistake is, because I've never setup ODBC on linux before and am not very familiar with it.
odbcinst.ini
[SQL Anywhere 12]
Description = SQL Anywhere 12
Driver = /opt/sqlanywhere12/lib64/libdbodbc12.so
Setup = /opt/sqlanywhere12/lib64/libdbodbc12.so
odbc.ini
[TP189902]
Description = TP189902
Uid = username
Pwd = password
Driver = SQL Anywhere 12
ServerName = 189902
CommLinks = tcpip(Host=1.2.3.4)
DatabaseName = DB189902
I've also tried a ton of alternatives, such as using the driver's path for the Driver value, using Host=1.2.3.4 instead of CommLinks, etc.
Also the command isql -v TP189902 username password doesn't output anything unless I give it a fake DSN so that it outputs and error.
I've also verified that libdbodbc12.so is the same architecture as isql and that it has all of it's dependencies.
On top of this, I have very similar setup on a Windows 7 machine running WAMP, that connects just fine (with both the ODBC and PDO library). I used the same DSN details on it.
Edit: I've also tried this to skip the DSN, but it gives the same result. It also works on the Windows box.
$odbc = odbc_connect('Driver={SQL Anywhere 12};Server=189902;CommLinks=tcpip(Host=1.2.3.4);', 'username', 'password');
I don't use PHP these days but here are some things I've spotted:
I would totally ignore php until you get isql working.
I'm assuming it is a typo that you say your system ini file is "odbcinstr.ini" - it should be "odbcinst.ini".
How do you know you are looking at the right odbc ini files - run odbcinst -j to check the locations unixODBC is using.
I know where that "[ODBC Data Sources]" section comes from (iodbc) but it not at all necessary for unixODBC - just delete the first 2 lines of your odbc.ini file.
your isql line is probably missing a username and password - it should be "isql -v TP189902 username password". I cannot for the life of me see why it would output nothing at all.
Ultimately the issue was getting the LD_LIBRARY_PATH set to /opt/sqlanywhere12/lib64 for Apache.
Setting it in /etc/environment got isql -v TP189902 and php connect.php working when called from any shell user, but not Apache.
To get Apache to see it, I had to edit /etc/init.d/apache2 and change
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
to
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/sqlanywhere12/lib64".
And then restart the Apache service.
Various other methods I found online to do this did not work.
One caveat is that with the path set, unixODBC still won't read my system DSN file for some reason. So to get Apache to access the DSN, I had to make a user DSN file (.odbc.ini) in /var/www, as that's the Apache user's (www-data) home folder.

Can't connect to MongoDB through PHP

I just wanted to take a look at Mongo-DB. But i just don't get it running. I've installed it with PECL and my phpinfo() tells me that the extension is loaded, but when i try to get a connection with
$mongo = new Mongo();
I get this:
Fatal error: Uncaught exception 'MongoConnectionException' with
message ': Transport endpoint is not connected'
Anybody have the same Problem? ... Or any Idea on this?
Please don't take this the wrong way, but have you actually got the server running? Only it looks like your error relates to a failure to connect and you've made no mention of the server or where it is located (localhost on the default port for example)
any server start method, such as "/etc/init.d/mongodb start" or "service start mongodb" will fail, if a stale lock file still exists. In Ubuntu/Debian this is /var/lib/mongodb/mongod.lock. Look for this and delte it, if it exists and seems to be an old one.
check out whether server is running or not..
/etc/init.d/mongodb start
then go to
root#kannan-desktop:~# mongo
MongoDB shell version: 1.6.3
connecting to: test
>
Don't forget to change the IP in your mongod.conf if it's a new installation.
custom string looks like that
mongodb://username:password#host:port/database
First Change the Default db path by following command
$ sudo mkdir -p /data/db/
$ sudo chown id -u /data/db
and then the final command is..
$ mongod --journal
Do not close terminal until you are working with mongoDB
It works for me...
just write mongod in your terminal and will work well

Categories