SFTP Upload Laravel 5 - php

I’m trying to upload files to my staging server running Linux Ubuntu.
I tried follow everything in this post = https://laravelcollective.com/docs/5.1/ssh . I am on Laravel 5.1.
I configured my remote.php like this :
'connections' => [
'production' => [
'host' => '45.55.88.88',
'username' => 'root',
'password' => '',
'key' => '/Users/bheng/.ssh/id_rsa', //Try : public | private
'keytext' => '',
'keyphrase' => '******',
'agent' => '', //Try : empty | enabled | disabled,
'timeout' => 10,
],
],
I tried test it like this in my project :
SSH::run('date', function($line) {dd($line); });
I kept getting :
Unable to connect to remote server.
I tried it on my Mac OS Terminal
sftp root#45.55.88.88
It’s working fine, I got
sftp> ls
Desktop Documents Downloads Music Pictures Public Templates Videos dead.letter
What did I do wrong or forget ? What elses should I try ?
Do I need to do anything on my /etc/ssh/sshd_config ?
Can someone please help me out if you’re done this before ?

Try setting the connection in case it's not using the correct settings, and see if that helps:
SSH::into('production')->run('date', function($line) {dd($line); });
The only other things I would recommend are:
Verify that your key is accessible from your code
Correct passphrase is being used
Double-check any other connection settings

Related

Copy or create file on remote FTP

So, I have tried 4 different ways of doing this, none of them worked.
There's a 3rd party server that I can create and delete files on via Filezilla. This was for testing purposes however.
There's a script on my Laravel application that'll run once a day, create a few XML files and those need to automagically transfer to that same server.
When I create an ftp filesystem I get the error "ftp_rawlist(): php_connect_nonb() failed: Operation now in progress (115)" after a timeout.
When I try PHP's ftp_put or ftp_fput I get the error "ftp_put(): php_connect_nonb() failed: Operation now in progress (115)" (or ftp_fput, same error).
When I try PHP's fwrite with the ftp as a destination I get the error "failed to open stream: operation failed". This also fails in the browser.
I have made sure credentials are correct. I've copy/pasted them from the working Filezilla connection details.
Filesystem code:
'ftp' => [
'driver' => 'ftp',
'host' => env('FTP_HOST'),
'username' => env('FTP_USERNAME'),
'password' => env('FTP_PASSWORD'),
'root' => '/Production',
'ssl' => true,
'ignorePassiveAddress' => true,
],
I know about the server behind NAT problem, but it won't accept my changes to use original address in filesystems. I've cleared cache, and config and fed the hamsters, but nothing changes.
I'm honestly at the end of my knowledge right now. And asking the 3rd party to change their configuration/settings isn't an option. This server is one of many and they're all exactly the same, but different clients. They might help me by providing the logs on their end, but that's about it.
The only other that I see which could be a difference is that I'm running this code from command line (ie, as if it's run via cron). Not sure if that causes problems with connecting and creating files on a remote server. I'm not that experienced with writing Laravel commands.
Any help would be greatly appreciated.
Ok.
Ok. Inside the configuration file like this:
'ftp' => [
'driver' => 'ftp',
'host' => 'ftp.example.com',
'username' => 'your-username',
'password' => 'your-password',
'passive' => 'false',
'ignorePassiveAddress' => true,
'port' => 21,
]
add file 'test.pdf' inside the ftp
simply run
$contents = \Storage::disk('ftp')->exists('test.pdf');
dd( $contents );
and it works.

Laravel - how to upload file to another application on localhost?

I'm trying to create a file upload where admin would upload file from admin application to another application for regular users (they are on different domains).
I got it working with FTP filesystem but I would like to test it on localhost, before I fully deploy it.
I made a config entry in filesystem.php:
'ftp' => [
'driver' => 'ftp',
'host' => env('FTP_HOST'),
'username' => env('FTP_USERNAME'),
'password' => env('FTP_PASSWORD'),
'root' => '',
'port' => 21,
'timeout' => 30,
'ssl' => true,
]
And on my test function in admin_app I do this:
Storage::disk('ftp')->put('/public_app/storage/test3.png', $file);
I have to separate laravel applications: admin_app and public_app. How could I test the same thing on localhost? Another config entry point or do I need to download FTP for localhost?
What about using something like remote server that contain your assets?
For example use S3 and upload all your files there and access it from your second app or any other app.
Check this Article

Can't connect to database with laravel 5

I'm trying to connect to my mssql database with laravel 5 but it's not working. I've tried to connect with different mssql databases so it's not a firewall issue. Also my credentials are correct. I found on google that you need SQL Server Native Client 11.0 and I've already installed that.
This is my connection array in config/database.php:
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('nvt'),
'database' => env('nvt'),
'username' => env('nvt'),
'password' => env('nvt'),
'charset' => 'utf8',
'prefix' => '',
],
And I've set the default to "sqlsrv" :
'default' => env('sqlsrv','sqlsrv'),
But when I'm trying to create a table I receive the error:
PDOException in Connector.php line 50: could not find driver
What could be wrong???
EDIT:
I've installed pdo for sqlsrv from here:
http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx
And I added it to my php.ini file:
extension=\Installaties\php_pdo_sqlsrv_53_nts.dll
But stil I receive the error?
Try to remove the eve() method, i mean use the following method
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => 'nvt',
'database' => 'nvt',
'username' => 'nvt',
'password' => 'nvt',
'charset' => 'utf8',
'prefix' => '',
],
I ran into a similar issue. Try putting in the server info directly rather than using env. If it works, then you know Laravel is having an issue reading the .env file.
I encountered your problem the last time I tried my connection in sqlsrv. I am using xampp. Try putting yung php_pdo_sqlsrv_53_nts.dll in the ext folder, replace extension=\Installaties\php_pdo_sqlsrv_53_nts.dll with extension=php_pdo_sqlsrv_53_nts.dll and try installing odbc 11 on your computer. It worked for me but not sure why. (not an expert) if it worked good to help a fellow person and if not, sorry for the trouble. Thank you for the time reading.
You may try any of the following solutions
Check that you have entered the right connection parameters. Test by connecting to the DB with a client tool.
Make sure you have the right version of sqlsrv configured for your machine. Check the PHP logs to be sure your web server was able to load the extension correctly.
Set the port to null in your env file
As a tip, I won't advise anyone to set the connection parameters anywhere but in the .env (Setting it in config/database is a security risk).

Database not connecting with server on different host CakePHP version 2.0.0-dev

I am facing problem while connecting cake php version-2.0.0-dev application on server. When I connect with localhost database, it works fine on server, but if I try to connect it with the database of the different server which is being hosted by another host, it gives following error:
Fatal error: Call to a member function getAttribute() on a non-object in
/home/dev.ukssmain/public_html/stock_system_ukrs/cake/libs/model/datasources/dbo/dbo_mysql.php
on line 259**
My configuration in database.php file is like
public $default = array(
'driver' => 'mysql',
'connect' => 'mysql_connect',
'host' => 'test.com',
'port' => '3306',
'login' => 'test',
'password' => 'test',
'database' => 'test',
'prefix' => ''
);
Can anybody help me to get through this.
Firstly, you should update to 2.0.6 (latest stable 2.0.x), or 2.2.2 which is the latest stable. You can find them here.
2.0.0-dev is unstable and outdated, you should use a stable version instead. I don't know why you'd want to run a production site with a -dev version, you're asking for problems.
Database configuration info can be found here.

cakephp hosting "Cake is NOT able to connect to the database."

beginner level stuff-
-i recently hosted my cakephp project on 000webhost.com
-it shows the cake homepage
-but at the same time shows
Cake is NOT able to connect to the database.
Datasource class a2952772 could not be found.
-i have tried editing root/app/config/database.php number of times.
-i have created mysql database on 000webhost.com
i guess there is some problem with
$datasource in
public $default = array(
'datasource' => '????',
'persistent' => false,
'host' => 'mysql11.000webhost.com',
'login' => '*****',
'password' => '*****',
'database' => 'db1',
'prefix' => '',
//'encoding' => 'utf8',
);
if anybody has hosted and configured databases on 000webhost.com ,plz help...
You need to specify a valid datasource, such as 'Database/Mysql'. Also check the CakePHP database configuration section.

Categories