10

I recently hosted a laravel project (for a customer) on shared hosting, after failed attempts to get access to the server via ssh I contacted the host who informed me that ssh service was not available for my customers hosting plan, that means I have no access to terminal and can't use artisan. I know how to write a php script that will create sql tables but just before that I was wondering if theres a shortcut to this with laravel since the migrations(tables) are already defined. What I want is like to create a route project.com/run_migrations to do the job! Thanks in advance

1 Answer 1

32

You can easily create a small Artisan script within PHP like this:

Artisan::call('migrate');

This equals php artisan migrate. Use it anywhere you want to run your migrations.

If you are in production mode (if APP_ENV=production inside your .env file) then you would have to force the migration in case you want to allow to make changes. You can do it as follows:

Artisan::call('migrate', ["--force" => true ]);

This equals adding the --force flag a la php artisan migrate --force.

To answer your specific question though, create a route like this:

Route::get('/run-migrations', function () {
    return Artisan::call('migrate', ["--force" => true ]);
});

If you are interested in creating a web installer, you might be interested in this package:

https://github.com/Froiden/laravel-installer

Check out the code to see how he handles migrations and seeds etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.