Table of Contents
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
Start Development server
php spark serve
We will get error, image shared about. So here we will see the complete solution to fix this.
Note*: This article is written when CodeIgniter development version is 4.0.3 or 4.0.4. May be later on it will be updated.
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
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
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.
Find More on CodeIgniter 4 here
- CodeIgniter 4 Cookie Helper Tutorial
- CodeIgniter 4 CRUD Application Tutorial
- CodeIgniter 4 CRUD REST APIs Tutorial
- CodeIgniter 4 CSRF Token in AJAX Request
- Database Query in CodeIgniter 4 Tutorial
- CodeIgniter 4 Ajax Form Data Submit
- CodeIgniter 4 Form Validation Tutorial
- CodeIgniter 4 Image Upload with Form Tutorial
- Multi language in CodeIgniter 4 Tutorial
- Stripe Payment Gateway Integration in CodeIgniter 4
- CodeIgniter 4 CSRF Token Tutorial
- CodeIgniter 4 Basics Tutorial
- CodeIgniter 4 Spark CLI Commands Tutorial
- Migration in CodeIgniter 4 Tutorial
- Seeders in CodeIgniter 4 Tutorial
Hi, I am Sanjay the founder of ONLINE WEB TUTOR. I welcome you all guys here to join us. Here you can find the web development blog articles. You can add more skills in web development courses here.
I am a Web Developer, Motivator, Author & Blogger. Total experience of 7+ years in web development. I also used to take online classes including tech seminars over web development courses. We also handle our premium clients and delivered up to 50+ projects.