Welcome Guest, Not a member yet? Register   Sign In
Error on LAMP server
#1

I uploaded my windows app to a LAMP server. I am getting the following error. 

A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known
Filename: mysqli/mysqli_driver.php
Line Number: 201
Backtrace:
File: /opt/bitnami/apache2/htdocs/sub_crud/application/core/MY_Loader.php
Line: 277
Function: database
File: /opt/bitnami/apache2/htdocs/sub_crud/application/controllers/Users.php
Line: 15
Function: __construct
File: /opt/bitnami/apache2/htdocs/sub_crud/index.php
Line: 316
Function: require_once

A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known
Filename: mysqli/mysqli_driver.php
Line Number: 201
Backtrace:
File: /opt/bitnami/apache2/htdocs/sub_crud/application/core/MY_Loader.php
Line: 277
Function: database
File: /opt/bitnami/apache2/htdocs/sub_crud/application/controllers/Users.php
Line: 15
Function: __construct
File: /opt/bitnami/apache2/htdocs/sub_crud/index.php
Line: 316
Function: require_once

A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: controllers/Users.php
Line Number: 15



I looked up line 15 of Users.php
class Users extends CI_Controller {

   function __construct() {
       parent::__construct();    <<<<<<this line is 15 
       $this->load->library('form_validation');
       $this->load->library('session');
       $this->load->model('user');
       $this->_init();

   }


Any idea what this is? The code runs fine under Windows.  
proof that an old dog can learn new tricks
Reply
#2

It's database connection issue, check your DB credentials, these would be different on Linux which is usually in different network.
Reply
#3

Thanks. Is the username and the password to access Mysql from the application the same username and password I use to access phpmyadmin from my computer? When I use the same username and password the connection seems to timeout.
proof that an old dog can learn new tricks
Reply
#4

Depends on your set up, but highly unlikely it'll match.

When you work on Windows, you are running your own DB server that handles all the queries. Think you were running it on AWS? They have their own dedicated DB, which can be quite pricey, or are you running database server on your Bitnami instance?
Reply
#5

(This post was last modified: 09-04-2018, 01:29 PM by richb201.)

I am actually doing both. I use the mysql to keep weekly data and then summarize the data weekly and upload the summaries to the AWS' Dynamodb, for safe keeping. This is what I am using for the mysql: The dots are not real!

$db['default'] = array(
   'dsn' => '',
   'hostname' => '34.229.225.201',
   'username' => 'root',
   'password' => '.........',
   'database' => 'substantiator',
   'dbdriver' => 'mysqli',


PS I managed to get a little further by changing username to root@localhost. Now I get:
Severity: Warning
Message: mysqli::real_connect(): (HY000/2002): Connection timed out
Filename: mysqli/mysqli_driver.php
Line Number: 201

How do I debug this? On my local phpStorm, I would just put a breakpoint on line 201 or I would look at the php error log file. Is there something analagous in LAMP?
proof that an old dog can learn new tricks
Reply
#6

So MySQL is running on your EC2 instance?

I don't use it like that myself, we're on that fancy RDS for database, but feels like database hostname should be 'localhost' or 127.0.0.1, because effectively PHP script is not "leaving" EC2 instance to connect to DB.
Reply
#7

(This post was last modified: 09-04-2018, 02:12 PM by richb201.)

I decided that I needed to keep the data to run my application separate from the users data, so I split the data into two places. Anyway, your suggestion seemed to work! Now it seems that I don't have the proper permissions to write out to the cache file.

An uncaught Exception was encountered
Type: Exception

Message: Session: Configured save path '/opt/bitnami/apache2/htdocs/sub_crud/application/cache' is not writable by the PHP process.

Filename: /opt/bitnami/apache2/htdocs/sub_crud/system/libraries/Session/drivers/Session_files_driver.php
proof that an old dog can learn new tricks
Reply
#8

I tried changing the permissions of the cache directory by using chmod 0770 cache, but this didn't seem to work (I went to the application directory first). Do you know how to display the permissions of a directory?
proof that an old dog can learn new tricks
Reply
#9

The cache directory's permissions are:

drwxrwxr-x 2 bitnami bitnami 4096 Sep 4 18:56 cache

Thus it is read/write. Perhaps it is only RW for user bitnami, while I am user root? Should I make the last section "rwx" which would make site writeable for everyone? Or is that a security hole?
proof that an old dog can learn new tricks
Reply
#10

It depends - it's the Apache user that you want to give write access to, so you could change the owner of that directory to 'apache' or you could give folder 0777 rights.

It's best practice so move application out of public_html folder, same goes for all writable asset folders.

Code:
/application <-- all your CI stuff
/cache <-- session files
/system <-- CI system folder
/public_html
    /index.php <-- this is where your domain points to
    /css <-- domain css files
Reply




Theme © iAndrew 2016 - Forum software by © MyBB