6

I need to run CodeIgniter project from any location without the need to replace it on the directory (www) of my WAMP server. So I want to use the CLI and Composer for this.

For Composer autoloading I follow these instructions from this link.

Here is my config file:

$config['composer_autoload'] = TRUE;

And my composer.json:

"config": {
"vendor-dir": "application/vendor"
},

After that I run composer update to create the vendor/ folder.

However when I tried to run the project using CLI like so:

php index.php MYController_1 Methode_1

Instead of opening and running the web application through web browser, the source code of this page is printed to the console.

What is the equivalent of Laravel's php artisan serve for CodeIgniter?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Hana90
  • 943
  • 5
  • 17
  • 37

3 Answers3

17

Laravel

php artisan serve is how Laravel starts a local development server:

After the project has been created, start Laravel's local development server using the Laravel's Artisan CLI serve command:

cd example-app

php artisan serve

CodeIgniter v3

CodeIgniter version 3 doesn't have an equivalent command to this, but you can use PHP's built-in webserver as Lázaro suggests:

php -S localhost:8000 index.php

CodeIgniter v4

If you are using CodeIgniter version 4 you can start its local development server with php spark serve:

Local Development Server

CodeIgniter 4 comes with a local development server, leveraging PHP’s built-in web server with CodeIgniter routing. You can use the serve script to launch it, with the following command line in the main directory:

php spark serve

This will launch the server and you can now view your application in your browser at http://localhost:8080.

Note

The built-in development server should only be used on local development machines. It should NEVER be used on a production server.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • Thank you Chris for this comprehensive answer, but when I run php serve in codeigniter directory I have this error "Could not open input file: serve" – Hana90 Apr 26 '18 at 18:00
  • 1
    @Hana90, it looks like this answer only applies to CodeIgniter version 4. I guess you're on version 3? In that case Lázaro's answer is probably best. – ChrisGPT was on strike Apr 26 '18 at 18:19
  • I download v4 and the same error I got when running this command in the project directory – Hana90 Apr 26 '18 at 18:21
  • 1
    @Hana90, ah, I've got it! The command is actually `php spark serve` for v4. I guess the documentation is wrong (the product is still in active development, after all). I've updated my answer. – ChrisGPT was on strike Apr 26 '18 at 18:36
4

PHP has a build in server that you can use. Just run

php -S localhost:8000 -t YOUR_PROJECT_FOLDER/

Codeigniter itself has nothing like a 'php artisan serve'

Lazaro Henrique
  • 527
  • 5
  • 7
0

php spark serve for CodeIgniter4.*.

Hasham Ali
  • 33
  • 1
  • 7