Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of "php artisan serve" for a CodeIgniter project?

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?

like image 246
Hana90 Avatar asked Apr 25 '18 20:04

Hana90


2 Answers

Laravel

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

Serving Laravel

Typically, you may use a web server such as Apache or Nginx to serve your Laravel applications. If you are on PHP 5.4+ and would like to use PHP's built-in development server, you may use the serve Artisan command:

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. The documentation gets the command name wrong, but is otherwise helpful, so I've included it here with the fixed command:

Local Development Server

PHP provides a built-in web server that is can be used locally when developing an application without the need to setup a dedicated web server like MAMP, XAMPP, etc. If you have PHP installed on your development machine, you can use the serve script to launch PHP’s built-in server and have it all setup to work with your CodeIgniter application. To launch the server type the following from the 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.

like image 155
Chris Avatar answered Nov 14 '22 21:11

Chris


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'

like image 39
Lazaro Henrique Avatar answered Nov 14 '22 23:11

Lazaro Henrique