33

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 = '';
3

17 Answers 17

46

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

7
  • 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, 2020 at 12:05
  • 9
    @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 Jan 18, 2020 at 17:58
  • @user9437856 what are you using Jan 16, 2021 at 9:27
  • 1
    @OluwatobiSamuelOmisakin Off course, that is the reason I give the possible solution I know you can use to solve this error Aug 12, 2021 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, 2021 at 16:46
18

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

0
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
1
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

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.

2
6

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.

0
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).

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

1
  • I'm using Mac too. A simple way and it works, thank you so much.
    – Mey Lin
    Jun 18, 2021 at 11:21
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.

1
  • I have downloaded ci4 manually, After follow these steps, got same issue
    – user8995024
    Feb 12, 2021 at 6: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
1
  • Your answer fits better in the StackOverflow format when you answer the whole question. You could cite other answers.
    – ominug
    May 26, 2020 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

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.

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.

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

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

0

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

0

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

When we installing CodeIgniter, that we are getting this message.

Step-1:

By Default, CodeIgniter app is running in "production" environment. we have to change it to development environment.

In Root folder change: env to .env

Search in .env file and Change # CI_ENVIRONMENT = production to CI_ENVIRONMENT = development

(please check # is removed)

Now Error will be visible in the browser.

Step-2:

Now, Error may show like these..

CodeIgniter\Exceptions\FrameworkException: The framework needs the following extension(s) installed and loaded: intl.

Open [xampp]
Click on [Apache Config]
Open File: /php/php.ini

Now, Search for ;extension=intl and remove the ;

extension=intl

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.