30

Whoops! We seem to have hit a snag. Please try again later.

Codeigniter 4 shows an error when I run the CI4 application, How I resolve?

Changes:

public $baseURL = 'http://ci.local';


public $baseURL = 'http://localhost:8080';
public $indexPage = '';
Kampai
  • 22,848
  • 21
  • 95
  • 95
Nasir Uddeen
  • 339
  • 1
  • 3
  • 5

16 Answers16

43

This work for me try it Go to app directory then to boot directory you will see production.php file.

That is: app => Config => Boot => production.php

Change the ini_set('display_errors', '0') to ini_set('display_errors', '1').

Warning: When in production change back to initial ini_set('display_errors', '0')

Or

you can rename your file env in your project directory to .env after that open it and edit. Search for # CI_ENVIRONMENT = production remove # and change production to development

Warning: When in production change back to initial CI_ENVIRONMENT = development to CI_ENVIRONMENT = production

For those experiencing intl error go to where your php installation directory edit the php.ini file remove semi-colon ";" from ;extension=intl to extension=intl. save the file and restart your server. I think this will solve that error. This particular editing of my php.ini was on php >= 7.3 so I haven't check other version of php lesser than these versions which Codeigniter 4 does not support

Chibueze Agwu
  • 910
  • 5
  • 12
  • 1
    Setting ```CI_ENVIRONMENT = development``` in ```env``` strangely did not change anything. But changing ```production.php``` as you described did the job. However, I am wondering, why did changing the ```env``` file not help? – Gerke Jan 18 '20 at 12:05
  • 8
    @Gerke Did you change file `env` to `.env` that is adding dot in front of the file name. I hope this will do the job for you – Chibueze Agwu Jan 18 '20 at 17:58
  • @user9437856 what are you using – Chibueze Agwu Jan 16 '21 at 09:27
  • Perfect answer! – Kay Angevare May 03 '21 at 17:38
  • Changing environment to "development" did the magic because Codeigniter 4* already set that `display_errors` to `'1'` by default. – Oluwatobi Samuel Omisakin Aug 11 '21 at 14:15
  • 1
    @OluwatobiSamuelOmisakin Off course, that is the reason I give the possible solution I know you can use to solve this error – Chibueze Agwu Aug 12 '21 at 15:57
  • 1
    Since this is Codeigniter 4, rather I'd suggest only the CI_ENVIRONMENT modification in the .env from "production" to "development". In my case no exception thrown but just an info to enable CURL in the php.ini. Anyway good reminder, forgot to set it. – Robert Aug 20 '21 at 16:46
17

After installing CodeIgniter 4 when you run the app then you will get an error like this

enter image description here

To know the error go to the app/Config/Boot/production.php and set display_errors to 1 as below

ini_set('display_errors', '1');

Now, you will see the actual error below

enter image description here

Nothing to worry about it. The app needs permission. Assign the permission like as below

sudo chmod -R 777 project_name

Umang Soni
  • 521
  • 5
  • 9
14

Assume that your root folder of your CI4 project is rootproject. Edit rootproject/.env file. On line 17 change from:

#  CI_ENVIRONMENT = production

to:

CI_ENVIRONMENT = development

Save it.

Refresh your browser that pointing to your CI4 project. It should give you many error messages.

If there is something written as CacheException, than your cache folders are not writable. Make it writable;

Ubuntu:

chown -Rv www-data rootproject/writable

CentOS:

chown -Rv apache rootproject/writable

Easy way:

chmod 777 -Rv rootproject/writable
rexluther
  • 141
  • 1
  • 2
7

In your CI4 project root, create a file named .env. It should be in the same directory as system, app e.t.c

Then, add this CI_ENVIRONMENT = development

mLawrenci
  • 79
  • 1
  • 1
7

The problem is most likely due to missing extensions. Check server requirements here.. Check your php.ini file and make sure intl and mbstring are enabled.

Imran
  • 103
  • 1
  • 7
  • Here's a solution for enable **intl** answered by @burhan-ul-haqq-zahir [https://stackoverflow.com/a/66100302/6681157](https://stackoverflow.com/a/66100302/6681157) – Diana Quinteros Jul 20 '21 at 22:27
  • Yes, also stated on this website: https://www.studentstutorial.com/codeigniter/install_4.php?expand_article=1 – IVIike Aug 02 '23 at 12:41
5

When you change # CI_ENVIRONMENT = production to CI_ENVIRONMENT = development don't forget of rename the env file to .env else it will not work.

Josimar
  • 80
  • 1
  • 6
5

Try This

  1. Open [xampp]/php/php.ini

    Search for ;extension=intl and remove the ;

  2. Save the php.ini file and restart Apache(server).

Merrin K
  • 1,602
  • 1
  • 16
  • 27
4

I had the same problem, I have a simple solution for Mac. - in the project folder, go to 'writable' - select all the folders contained and click on 'get information' - go share and permissions - in 'everyone' select 'read and write' That's it! refresh the page

Santiago D
  • 56
  • 3
3
  1. In Root folder change: env to .env

  2. Change # CI_ENVIRONMENT = production to CI_ENVIRONMENT = development (ensure it is uncommented)

  3. Your error may be related to the knit.php file.
    Go to System/Third Party and change: knit.php to Knit.php (Capital)

  4. Reload.

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Rokhayakebe
  • 119
  • 1
  • 3
  • I have downloaded ci4 manually, After follow these steps, got same issue –  Feb 12 '21 at 06:18
3

For those using XAMPP in MacOS:

You don't need to change the ownership of the writable directory. You only need to change permission to entire directory:

chmod -R 777 writable
  • Your answer fits better in the StackOverflow format when you answer the whole question. You could cite other answers. – ominug May 26 '20 at 18:11
2

You're running in the production environment and need to change it to a Development or Testing environment to see the error messages within the browser.

There are a few ways to do this, but adding:

SetEnv CI_ENVIRONMENT development

To the Apache httpd.config file is what worked for me.

_t

shotsy247
  • 153
  • 1
  • 9
2

I got the answer for this query; just follow these steps:

  1. From the command line, at your project root just hit this php spark serve

  2. Then hit this on your browser http://localhost:8080/

Enjoy your Latest CI.

Das_Geek
  • 2,775
  • 7
  • 20
  • 26
1

Not sure what the desired answer is, but:

  1. If you are asking to see what is the actual error is - either change your environment to testing/development (as suggested so far) or you can check your logs - writable/logs/log-.php
  2. If you wish to solve the error, we will need more information, like have you setup virtual hosts, have you change .htaccess file in public folder, etc. Otherwise we will be most likely betting (I bet it's virtual hosts).

In any case, a copy of the displayed error (after changing evnironment) or log file will be useful.

Tsefo
  • 409
  • 4
  • 15
1

In Codeigniter 4 source code have a folder named writable, just update it's access permission. Sometimes it'll help to get rid of Whoops. Also can check the video for Ubuntu / Linux

Anupam M
  • 11
  • 6
0

You can check logs file on writable/logs find error information, If your logs information like :

CRITICAL - 2020-04-19 17:44:55 --> Invalid file: template/header.php
#0 F:\xampp\htdocs\ppdb\vendor\codeigniter4\framework\system\View\View.php(224): CodeIgniter\Exceptions\FrameworkException::forInvalidFile('template/header...')

And go fix your error, in my case i am wrong typed name on controller file

colidyre
  • 4,170
  • 12
  • 37
  • 53
0

env file is coming with env without . than you just need to rename it with .env and change your production environment to development.

Ritika
  • 19
  • 2