CodeIgniter Forums
CodeIgniter initial configuration - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: CodeIgniter initial configuration (/thread-76349.html)



CodeIgniter initial configuration - imabot - 05-05-2020

Hi, I'm from CI3 and I try to migrate on CI4.

I'm following this tutorial : https://codeigniter.com/user_guide/tutorial/index.html

Initial configuration is not clear. I do not understand what I should do to get a proper configuration of CodeIgniter. Here are some of my interrogations :

I read the CI_ENVIRONMENT variable can be set in the .htaccess file and in the .env file. Where should I put the configuration ?
I read the baseURL variable can be set in /Config/app.php, and in the .env file. Where should I configure baseURL ?
I read the database configuration can be set in the /Config/database.php and in the .env file. Where should I configure the DB ?

I try to configure  the DB in /Config/database.php and in the .env file, but I can't get ride of this error : 
Quote:You have not selected a database type to connect to.
You have not selected a database type to connect to.
I can't figure out how to properly configure CI4 for development on a local apache server and for production on a remote apache serveur. 

I read the doc dozen of times, but I still don't understand the configuration philosophy of CI4. Any light is welcome.


RE: CodeIgniter initial configuration - Marcolino92 - 05-05-2020

You have to set the data for the connection to the database on app / Config / database.php


RE: CodeIgniter initial configuration - jreklund - 05-05-2020

It's recommended to set in .env, so you can have a different .env file on your severs.

Please note you need to rename/copy your env into .env - There need to be a . (dot).
Code:
CI_ENVIRONMENT = development
app.baseURL = 'http://skribbl.example.com/'
app.indexPage = ''
database.default.hostname = localhost
database.default.database = skribbl
database.default.username = root
database.default.password =
database.default.DBDriver = MySQLi



RE: CodeIgniter initial configuration - imabot - 05-05-2020

Quote:jreklund It's recommended to set in .env, so you can have a different .env file on your severs.

Ha, OK, that was not clear for me after reading the documentation.

Quote:Please note you need to rename/copy your env into .env - There need to be a . (dot).
Code:
CI_ENVIRONMENT = development
app.baseURL = 'http://skribbl.example.com/'
app.indexPage = ''
database.default.hostname = localhost
database.default.database = skribbl
database.default.username = root
database.default.password =
database.default.DBDriver = MySQLi

So the database configuration in the /Config/Database.php is not used, right ?

Hum it's not working I still have the following error :

Code:
InvalidArgumentException

You have not selected a database type to connect to.
 
When I look at the arguments of  CodeIgniter\Database\Database->load ( arguments ), this is the arguments set in /Config/Database, not the parameters set in .env.


RE: CodeIgniter initial configuration - jreklund - 05-05-2020

Can you post your .env file here?

.env overrides your settings in /app/Config/(all files)


RE: CodeIgniter initial configuration - imabot - 05-05-2020

(05-05-2020, 12:10 PM)jreklund Wrote: Can you post your .env file here?

.env overrides your settings in /app/Config/(all files)

OK, .env overrides settings !!! Everything is clear now. 

By the way, it works, I reverted the file /Config/Database.php. (As it was not working, I try many options, and I probably changed something that prevent connecting to MySQL). Let's try PDO now !

Thank you for your help.


RE: CodeIgniter initial configuration - jreklund - 05-05-2020

PDO are not ported yet, so you can't use that driver.
https://codeigniter.com/user_guide/intro/requirements.html


RE: CodeIgniter initial configuration - imabot - 05-05-2020

(05-05-2020, 12:27 PM)jreklund Wrote: PDO are not ported yet, so you can't use that driver.
https://codeigniter.com/user_guide/intro/requirements.html

This is probably why it was not working! Do you know configuration settings for PDO is explained in the documentation : https://codeigniter.com/user_guide/database/configuration.html#database-configuration

Quote:Some database drivers (such as PDO, PostgreSQL, Oracle, ODBC) might require a full DSN string to be provided. If that is the case, you should use the ‘DSN’ configuration setting, as if you’re using the driver’s underlying native PHP extension, like this:

Code:
// PDO
$default['DSN'] = 'pgsql:host=localhost;port=5432;dbname=database_name';



RE: CodeIgniter initial configuration - jreklund - 05-05-2020

Okay, that's wrong at this time. CI4 user guide are based on CI3, so must have been missed.