mongodb service in PHP - php

I'm trying to connect to mongodb in php.
There's no problem if mongodb is start in shell with mongod command.
new Mongo("mongodb://".$_host.":".$_port,true)
But when i start mongodb server as a service, i can connect with the mongo command, but i cant connect in php.
new Mongo("mongodb://".$_host.":".$_port,true)
Is there any other arguments?
I'm using the last version of mongodb and the last version of php.
Can someone help me?

What are your command line parameters for the MongoDB service? Is it possible that you've specified a different configuration than what you get by default when manually running mongod? What parameters did you use to install MongoDB as a service?

Thanks for your answer and comment, i fix it.
The problem was in the service command line , i use this command
"C:\mongodb\bin\mongod" --bind_ip 127.0.0.1 --logpath "C:\data\db\mongodb.log" --logappend --dbpath "C:\data\db" --port 27100 --install
instead of
"C:\mongodb\bin\mongod" --bind_ip myIPadress --logpath "C:\data\db\mongodb.log" --logappend --dbpath "C:\data\db" --port 27100 --install
In the php code new Mongo("mongodb://".$_host.":".$_port,true) , $host = myIPadress
That why it was working in command line and not in the php code, it must be the same IPadress, don't use localhost or something like that if you don't use a default new Mongo()

Related

PHP fails to access the docker socket via curl

My Code fails to reach the Docker Socket
$client = new GuzzleHttp\Client();
$test = $client->request('GET','http://v1.40/containers/json',[
'curl' => [CURLOPT_UNIX_SOCKET_PATH => '/var/run/docker.sock']
]);
I only get a generic cURL error 7 from that and I´ve checked that the socket is available and working inside the Container with the cURL command from the cmd. Its only when i try to connect via PHP it fails ominously and frankly im out of ideas.
So just in case someone stumbles upon this in the future and has the same or a similar problem.
Guzzle was not the problem in this case but phpfpm. I did not realize that the phpfpm workers in the official php docker image used the www-data user by default. The way I used is to change the user in the www.conf (default /usr/local/etc/php-fpm.d/www.conf in docker)
user = root
group = root
you will have to append the -R flag to the run command to allow running the workers as root.

Errors creating a new database with Doctrine orm symfony

i tried creating a new data base using the command:
$ bin/console doctrine:database:create
and I got the following errors:
In ExceptionConverter.php line 91: An exception occurred in the
driver: could not find driver
In Exception.php line 26: could not find driver
In Driver.php line 28: could not find driver
also i tried modifying the database url from:
# DATABASE_URL="mysql://db_user:db_password#127.0.0.1:3306/db_name?serverVersion=5.7"
to
# DATABASE_URL="mysql://root:#127.0.0.1:3306/SMF?serverVersion=5.7"
I'm using xampp server.
Make sure You have installed all drivers in that machine.
As far as I remember it is: php-pdo and php-pdo_mysql - depending on Your OS.
You need to have a mysql client to make such database.
Basically run this command in Your console:
symfony check:requirements
It will show You what package You are missing to run a Symfony app.
Don't forget to match your MySQL Server version with DNS:
DATABASE_URL="mysql://root:#127.0.0.1:3306/SMF?serverVersion=X.Y"
And lastly, Ouss Ma L'aire Bien mentions, uncomment the DATABASE_URL You want to use and comment out all others.
in your case you should delete the "#"
and if there are other lines staring with DATABASE_URL in your .env file just put "#" in the begining
in other cases, just try your windows cmd

Envoy and connecting via ssh with username with capitals

I recently installed laravel envoy task runner, when I try to run a task with command envoy run deploy I get the following error:
GabotronES#gabriel-ubuntu-1:/var/www/dtcburger.es$ envoy run deploy
Are you sure you want to run the [echo] task? [y/N]: y
[GabotronES:206.189.X.XX]: ssh: Could not resolve hostname gabotrones:206.189.X.XX: Name or service not known
[✗] This task did not complete successfully on one of your servers.
It says it can't resolve hostname gabotrones but my ubuntu user is GabotronES, in my Envoy.blade.php I have also user GabotronES in #servers directive, is this because envoy doesn't allow username with capitals to connect via ssh?
#servers(['web' => 'GabotronES:206.189.X.XX'])
*censored my IP just in case
I don't think the capitals are the issue.
Please try this syntax:
#servers(['web' => 'GabotronES#206.189.X.XX'])
You can also try to connect directly from the command line, to check if things work as expected.

How to know why OCI8 have different behaviour with php_fpm and php_cli?

I'm currently working on a PHP Symfony 3.4 project and I am connecting with OCI8 to an Oracle BDD.
Also, on the same environment I execute a .php file from command line and I connect to the Oracle bdd from it too.
I am using OID to connect to the database in my symfony app and my .php script.
Here's how I am connecting :
$conn = oci_connect('USERNAME', 'PASSW', 'OID_BDNAME');
Where OID_BDNAME is the database name in OID.
And it's working perfectly fine from the .php script but I can't get it to work within my symfony application, and here's the error :
ORA-12154: TNS:could not resolve the connect identifier specified
Both command line php and php fpm are using /etc/php.ini (I checked with phpinfo(); and $ php --ini)
Do you have an Idea why OCI8 have different behaviour with php_fpm and php_cli, and how to solve this ? Thanks

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