CodeIgniter 4 PHP Spark Error Exception Fixed

Reading Time: 6 minutes
11,854 Views

Inside this article we will discuss about fixing error of PHP spark in codeigniter 4. It’s a codeigniter framework exception. So here we will discuss the step by step process to fix – CodeIgniter 4 php spark not working error.

When you go and type either of the command into terminal.

List All Available commands in CodeIgniter 4

$ php spark

Start Development server

$ php spark serve

We will get error, image shared about. So here we will see the complete solution to fix this.

Learn More –

Let’s get started.


Reasons of Spark Error Exception

Here, as per the views and research these are few points when codeigniter 4 spark stop woring.

  • System PHP version 8.x
  • Framework modules missing

Majority of the errors come when we have php version as the ongoing latest version i.e 8.x. (time of this blog content). CodeIgniter 4 we have installed via composer. Tried to run project into browser via php spark serve not working.

In some cases, also I faced that. Initially system upgraded to PHP 8.x, CodeIgniter 4 not working. Then installed another PHP version 7.4 and switched system to use 7.4 then again it’s not working.

It is known bug with v4.0.4 not yet compatible with PHP 8. But why it is coming ?

It’s because CodeIgniter 4 modules services, written as per the syntax and provided features of PHP 7.x. While updating to 8.x older syntax stop working.

So how to fix this?


Resolved: PHP Spark Error Exception

We will resolve this exception by taking two cases. You can use the option in which you are –

  • Your System has PHP version 8.x, PHP spark not working
  • Initially installed PHP 8.x switch back to 7.4, PHP spark not working.

System has PHP version 8.x

CodeIgniter 4.0.4 is not compatible yet to accept the new PHP version 8.x at this blog writing. So to run the project in PHP 8.x, we need to use the development version of CodeIgniter 4.

#Steps To Fix

Install CodeIgniter 4.

$ composer create-project codeigniter4/appstarter codeigniter-4

When you run $ php spark serve, error you will get

An uncaught Exception was encountered

Type: ErrorException
Message: Required parameter $from follows optional parameter $verbs
Filename: /var/www/html/codeigniter-4/trythis/vendor/codeigniter4/framework/system/Router/RouteCollection.php
Line Number: 1017

Still CodeIgniter 4.0.4 is not the stable release so far. So we can pull the development app started project for PHP 8.x.

$ php builds development && composer update

Next run,

$ php spark

Now, you can work as usual you do with codeigniter 4. This time the new development app starter project gives you the several available php spark commands.

Initially installed PHP 8.x switch back to 7.4 – Not Working

You have installed several PHP versions let’s say you have 7.3, 7.4, 8.x. If you are wondering i.e How to check php versions. For this ubuntu OS have several commands

$ sudo update-alternatives --list php

To check which version you are using. Create a file with name info.php (choose any name) at /var/www/html at your localhost root directory

Code inside info.php

<?php

phpinfo();

Open browser and see by http://localhost/info.php

If the currently used version is showing 7.4 and php spark not working. The error is because your current used php version may have some update missing.

So update-alternatives: using /usr/bin/php7.4 to provide /usr/bin/php (php) in manual mode

Execute this (For 7.4)

$ sudo update-alternatives --set php /usr/bin/php7.4

Execute this (For 7.3)

$ sudo update-alternatives --set php /usr/bin/php7.3

Next, back to project setup and open in terminal. Type

$ php spark serve

Now, you can see error has removed and now we can run our application.

We hope this article helped you to learn about i.e CodeIgniter 4 PHP Spark Error Exception Fixed Tutorial in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more