How to set database, server, username and password in Laravel 5.1?

12,225

Solution 1

It is possible to do it in 2 ways in Laravel:

1) Go to <projectname>/config/database.php and search for 'connections' =>

2) Set it in .env file on the root.

Solution 2

  1. go to .env file in the root of your project (must enable show hidden file)
  2. if you are using mySql database find these three line or if not exist add this three line into .env file
    • DB_DATABASE=your_database_name
    • DB_USERNAME=your_database_username
    • DB_PASSWORD=your_database_password

for example :

  • DB_DATABASE=college
  • DB_USERNAME=root
  • DB_PASSWORD=password

after doing these work, run this command again "php artisan serve"

Solution 3

You can write your own AdminPanel where you get all config values from the .env file, put them in a form and write them back to the file. Make sure to delete the AdminPanel after the configuration because it's a big security issue.

Share:
12,225
scott
Author by

scott

Updated on July 24, 2022

Comments

  • scott
    scott almost 2 years

    I am trying to set the database name, server name, username and password in Laravel via an html form (similar to the way that this can be done in WordPress). Is there any way to do this with Laravel?