How run migrate commands by controller? - php

I want create an installation controller for my web app and for config db need run migration commands from controller.
For example when user visit
localhost/backend/webapp/index.php?install/step1
by action step1 run migrate up and down command and do installation.

Thanks from #soju and #meysam you can use both solutions.
Use exec:
Perhaps combining stackoverflow.com/a/35864018/1592247 and exec
function of php could helps (#meysam)
Use extensions:
How can I call a console command in web application in Yii 2.0 (#soju)
Both way may help you.
be aware using exec may cause some security issues and disable in some servers.

Related

What is the difference between artisan and composer from the point view of a laravel project?

I didn't know composer before laravel and i encountered them at the same time. So, I can't distinguish the commands of them, but memorize them.
What is the difference between php artisan and composer.phar and also the commands they run?
Can anyone help me on this issue? Thanks..
Composer is a package manager for php and artisan is a command line tool using php
Composer
- download libraries
Artisan
- run scripted commands like you would in bash
The reason to use artisan instead of direct php commands is that you have to implement certain functions so you get an universal feel to the commands. It will help with a lot of things like handling arguments. You could see it as a nice helper for writing great php command line tools.
Once your command is generated, you should fill out the name and
description properties of the class, which will be used when
displaying your command on the list screen.
The fire method will be called when your command is executed. You may
place any command logic in this method.
https://laravel.com/docs/5.0/commands
There is a basic difference in these two commands that they belongs to two different packages.
Composer: composer is a dependency management tool for php. It auto manages dependencies of your project according to your requirements and thus makes your project more distributable.
You don't have to package all the dependencies inside your application. And, if your dependencies are variable it is hard to manage them all within your application. So, composer does it for you.
So, your composer command operates this package. And, it can be used for any project whether it is laravel or other php application.
Artisan: This is the command line utility of Laravel. It comes integrated with your laravel installation.
You can perform operations on your laravel project using its commands. As it is a tool built over php. So, you need to execute its command over php-CLI. That is why you use the php before it.
And, you need to use artisan before it because this is the script name which operates the commands of this tool. If you see your laravel project directory it has a file named artisan inside the root folder. It is the file which bootstraps the laravel's command line code. Or, you can say it is like index.php of directory.
Hope I was helpful.

Whats the point of running Laravel with the command 'php artisan serve'?

I dont seem to understand why we need to run a Laravel app with php artisan serve vs just running it with Apache or nginx. I know that under development, we use artisan to fire up the site and after deployment to a server, you use the webserver to load up the site.
Whats the use of running the app in artisan in the first place?
The serve command is just a shortcut for the PHP Built-in Webserver, something PHP has out of the box, so the point of using it is to start testing your application as fast as you could, you just need to install PHP, Composer and your application is up (if you don't need anything else, of course). But if you already have Nginx installed, there is no point at all, just use it.
It's not wise to use the Builtin Webserver in production.
One advantage of using php artisan serve over a typical webserver during development is you can use Psysh as a debugger (Laravel Tinker) to set a breakpoint.
For example, at the line of code I want to break at I type:
eval(\Psy\sh());
Then I hit the page that will run that section of code and when it gets to that line it will break into a Psy Shell repl (in the commandline window where I started php artisan serve). Then I can inspect variables, etc. at that point of execution. It's very useful for debugging. As far as I know, you can't do this running Apache/Nginx. It has to be with artisan serve (or running automated tests).
More info here:
https://tighten.co/blog/supercharge-your-laravel-tinker-workflow
http://psysh.org/
Purpose: The purpose of using Php artisan serve (PHP builtin server) is just for testing and easy starting your project it should not be used in real website deployment.
Asset Not working: Always put your index file in public it's the beauty and security of Laravel framework and your assets will always working. if you are bore to use your custom URL like C:/wamp/www/pym/server.php then use Virtual host locally but don't but don't put your index outside the Public folder.
if you really want to use index at your Root directory then you should customize your all asset() and url() helper functions and should put your exact url Example asset('/login') should be changed to asset('localhost/yourprojectroot/login').
php artisan serve --host your_server_ip --port 8000
copy that http://your_server_ip:8000 and run it into the browser
Aside from the best answer here.
You can see the logs directly where you execute the php artisan serve, so useful in debugging.
Well, was looking for the same answer but couldn't find any that is satisfying so , if your also unsatisfied just like me try running the link returned when you run
php artisan serve
it returns
Laravel development server started: <http://127.0.0.1:8000>
copy that /http://127.0.0.1:8000 and run it into the browser , guess what it returns );the page that u first got when you installed laravel for the first time or i guess it will return the page in the routes folder which was set as /home directory or file(default home page).
In brief:
php artisan serve
starts the serve,forexample its like when your going to drive a car and you start the engine before driving whereby you can start the engine and drive at the same time ,its not neccessary to do so but depends.So to me that's php artisan serve CLI.

Run Console Command in PHP script Symfony 2

i have this console command :
php app/console jms-job-queue:run
I want to run this command when i click a button on my website.
So i don't niet a command prompt to do this.
Is this possible in symfony 2 ?
A good idea would be to created a helper class to do this for you, because the commands will look different foreach dev and prod environment. You can add also methods to check if there are any processes running, or to kill one.
Not sure, but I guess you need full path to your command:
[%kernel.root_dir%] / console jms-job-queue:run
Your could try creating a service that defines the behavior you want, then have both your console command and your controller action call that service. This promotes code reuse and allows you to call that function anywhere you want.
You can also look at this question that had been answered before:
How can I run symfony 2 run command from controller
Maybe it will be enough to use plain php exec function.
You can define the command as a service like this and use it in your controller.

Laravel 4: Any way to run PHP Artisan command in PHP code?

I'm fairly new on Laravel's technology regarding real-time application. I'm trying to make a notification system and from what I Google, using some kind of socket server is the best way.
So I'm trying to use this: https://github.com/BrainBoxLabs/brain-socket
But I have no idea how to run it on live server later, since I don't own the server itself I can't run commands like: php artisan brainsocket:start in terminal, so I need to figure out how to run that command by using php code?
Or if my method is wrong, how to use that brain-socket in live server?
You can do this with
Artisan::call('brainsocket:start', $args);
where $args is an array of arguments.
See the Laravel docs.

YII framework, is SSH required to run protected/yiic.php migrate

We have a company doing several websites for us using the YII framework. The developers tell us that in order to run protected/yiic.php migrate that they must have SSH access to our server.
We are reluctant to provide SSH as there are many clients on our server. Is SSH really required as they say or can this migration script run via other means via the web browser?
You can write php-script, that will execute migrates, use CConsoleCommand for base, but it is not simple issue.
The fastest way run the migration only SSH, but approach proposed by Alex also nice.

Categories