unable to access magento classes via command line interface/vagrant box - magento

i installed Magento via a vagrant box. it works fine.
However, i need to test code via CLI .i accordingly created a page at the root of the site with following code:
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
$customer = Mage::getModel('customer/customer')->load(79);
print_r($customer->getData());
i then tried to access this page via command line interface on windows (cygwin) with following commands
php magento/test.php
i get the following errors;
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [20 02] No connection could be made because the target machine actively refused it.
' in C:\DevFolder\magentoKlierik\magento\lib\Zend\Db\Adapter\Pdo\Abstract.php:12 9
however when i make the same call via the URL i get access. i.e
why is there a difference when using command line and how do i give permission on the command line

You have to run the code inside the vagrant box, so in this case you need to run in your host system:
vagrant ssh -c 'php /vagrant/httpdocs/test.php'
For more information you can refer to the documentation.
Moreover I suggest you not to use custom scripts but use the system that is provided by magento for creating cli scripts.
You can find a good tutorial on inchoo (which I did not write) that provides you with some examples.

Related

cannot run commands in tinkerwell over ssh connection (laravel)

Tinker works just fine when I am ssh'd into my box, but I cannot get it to work in tinkerwell.
I'm trying to connect to my local vagrant box with tinkerwell. It is a vagrant box running in windows: ubuntu 20, laravel 5.7, php7.3.33. Tinkerwell 2.25 in Windows 10. I can connect over ssh, but it errors out whenever I run any command:
In Shell.php line 79:
Argument 1 passed to _PhpScoperc223a629f245\Psy\Shell::add() must be
an ins tance of
_PhpScoperc223a629f245\Symfony\Component\Console\Command\Command, instance of Psy\Command\ParseCommand given, called in
phar:///tmp/vagrant_t
inker.phar/vendor/symfony/console/Application.php on line 316
I get the same error whenever I try to run any command. On google I found a thread where someone had the same issue, except they were not connecting over ssh, they were on a mac, and the thread had no resolution in it (https://github.com/beyondcode/tinkerwell-community/issues/215).
I have checked that the correct version of php is in my $PATH, so the default path of php for the php executable that tinkerwell picks seems correct. I have also tried specifying /usr/bin/php but it doesn't change anything.

How to fix VS Code error with Remote-SSH: "the terminal process failed to launch: A native exception occurred during launch (forkpty(3) failed.)."?

I've installed and used the Remote-SSH extension in VS Code to access a Linux staging environment and work remotely.
The setup and connection works for one user, however is not allowing me to connect as a different user (on the same server).
Immediately after connecting, an error pops up saying the terminal process failed to launch: A native exception occurred during launch (forkpty(3) failed.). and the terminal would fail to open. If I attempt to manually open the terminal, it will fail with the same error.
Here is an example of how my Remote-SSH config file looks:
Host configfile1
HostName host.website.com
User username1
IdentifyFile "[key file path]"
Host configfile2
HostName host.website.com
User username2
IdentifyFile "[key file path]"
I could connect just fine and open remote terminal with configfile1, however would run into the aforementioned error when attempting to connect with configfile2.
I have tried various solutions mentioned in this GitHub issues thread, but to no avail: https://github.com/microsoft/vscode-remote-release/issues/4233
Does anybody have a solution for this?
I don't know the underlying causes for this, but this error pops up when using jailed shell settings.
Try changing the user's SSH shell settings to normal shell, and you may be able to connect without an issue.
This may not be ideal for all scenarios or security considerations, however, but it will allow Remote-SSH to connect and spawn the terminal.

Can start ChromeDriver within CLI tool but won't allow connections

I'm using Laravel homestead and I'm writing a little artisan command line tool that I need to browse my site with javascript execution.
I run dusk test regularly with no difficulty, so I thought I would use Laravel's tools for this script.
I started out by running this early in my script:
\Laravel\Dusk\TestCase::startChromeDriver();
This started the driver fine running on port 9515 running as user vagrant (default homestead user)
But when I tried to access it (also from within the script) I would get an error:
Failed to connect to localhost port 9515: Connection refused
If I instead started it manually on the command line:
$ ./vendor/laravel/dusk/bin/chromedriver-linux --port=9515
The driver started fine again running on port 9515 as user vagrant, but this time my tool runs fine.
But I really want to be able to start the ChromeDriver from within the tool. So I also tried:
$process = new \Symfony\Component\Process\Process('./vendor/laravel/dusk/bin/chromedriver-linux --port=9515');
$process->start();
Connection was refused again.
Any idea why this works when I start it from the command line but not within my artisan command?
I can't explain why this makes a difference but it has. If I launch the driver with the full path:
/home/vagrant/Code/mysite/vendor/laravel/dusk/bin/chromedriver-linux --port=8888
all works fine now.

Composer-Rest-Server not connecting

I am testing a a business network I created, I ran the Composer-rest-server and all worked fine, then shut the server as suggested in the developers guide , then I proceeded use the yo hyperledger composer to create the skeleton of the angular app, however, now the angular app is showing in the local browser, however, the composer-rest- server is not.
Expected Behavior:
I should start the composer-rest- server in localhost:3000 and the angular app as well
Actual Behavior:
I get this message;
scovering types from business network definition ...
Connection fails: Error: Error trying to ping. Error: Error trying to query chaincode. Error: Connect Failed
It will be retried for the next request.
Exception: Error: Error trying to ping. Error: Error trying to query chaincode. Error: Connect Failed
Error: Error trying to ping. Error: Error trying to query chaincode. Error: Connect Failed
at _checkRuntimeVersions.then.catch (/home/node/.nvm/versions/node/v6.11.2/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:696:34)
Your Environment
composer-cli#0.11.3
generator-hyperledger-composer#0.11.3
composer-rest-server#0.11.3
Docker version 17.06.0-ce, build 02c1d87
docker-compose version 1.13.0, build 1719ceb
The Problem
If you kill your fabric instance using ./stopFabric that you started using the ./startFabric command then all the containers that were apart of the business network were killed as well and therefore you need to reinstall the .bna and start the network again. (the development flow provided is purposely volatile for rapid development)
The Solution
1.) Type docker ps to see all of your running containers. You should see none if you are getting that error because your peer is not responding to pings
2.) Open a separate terminal and navigate to where you have fabric-dev-servers in the terminal and run ./fabricStart. This will start all the containers like your network Certificate Authority, the peer, the orderer, etc.
3.) Return to your project in another terminal. Do Step 1 & 2 found at the developer tutorial (you likely won't need to do step 3 since you likely already imported the network administrator identity going through the tutorial)
4.) Run composer network ping --card admin#tutorial-network. The ping should go through.
5.) Run docker ps. You should see 4 containers running
6.) Run composer-rest-server and follow the steps from the tutorial.
7.) Run cd tutorial-network-app to switch to where your angular application is (or wherever you generated it with the yo command)
8.) Navigate to http://localhost:3000 and everything should work.
Any other questions or problems just reply here and I can help.
The expected behaviour is that the REST server is already running (the the generator uses Loopback to spin up a REST server already (that's why you shut down the previous REST server)). Its described here https://hyperledger.github.io/composer/unstable/tutorials/developer-guide.html under 'Generate your Skeleton Web Application'.
After you created the application - following completion of the yo hyperledger-composer questions (and after providing the answers) you run your application using npm start from within the generated application directory. Your app is accessible at http://localhost:4200.

«Can't create domain» error on installing Vesta admin panel

I trying to install VestaCP on CentOS 6. And i always get this error:
Error: no avaiable IP address
Error: can't create domain
I install Vesta on clean OS and installation have no special configuration that can cause this errors.
What should I do?
Open vst-install-rhel.sh (for example, with «nano») and delete this block:
# Adding default domain
$VESTA/bin/v-add-domain admin $servername
check_result $? “can’t create $servername domain”
Than run vst-install-rhel.sh:
bash vst-install-rhel.sh
See also:
Vesta Forum, Russian Admin Blog

Resources