Cannot connect mysql database with PHP application

Hey, DevOps fellow.
I am trying to connect the database server loaded with mysql database on ubuntu server and the other php web application hosted on apache2 ubuntu server.
I have enabled the 3306 port using firewall-cmd.
Well, I was trying to stimulate the ecommerce application on my VM’s after following the 2-Tier web Application deployment. I have cloned the code from GitHub - kodekloudhub/learning-app-ecommerce: A sample e-commerce learning app.
But , I am not able to connect the application to the database.

Let me make sure I understand what you’re trying to do. You’re trying to adapt the repo (which uses a RedHat-style system) to work with two Ubuntu virtual systems. How did you create the virtuals? If it’s not by using vagrant (which would make sure that web and db can network with each other), how are you doing it?

While, I have installed Apache2 on FIrst Ubuntu VM created on Oracle Virtual Box named Web-server and I have the similiar other Ubuntu VM named DB-Server and I have installed MongoDB in it.
I downloaded the git repo on the Web-server, now when visit the website, the webiste works fine with the php. But, doesn’t fetch the products in the ecommerce website as it can’t connect with the database I guess.

What are the networking settings you have for your two systems? I believe the term Virtualbox using is “Host-Only” or “Bridged” networking, which will allow your hosts to see each other. Then you will use the IP of the db virtual to communicate from the web application and the MongoDB endpoint.

Yes, on both the VM, I have enabled two interfaces one with host only network and other with NAT.
They can ping each other from the host.

I am finally able to connect to the database.


I had to change the bind-address: 0.0.0.0. And also I installed the mysql-client on the webserver.
Can you help me understand what was it. I couldn’t understand.