I recently had to migrate a laravel web app using mariadb on my computer to setup a test and development environment.
I will tell you the steps I went through and the difficulties that happened as well as the solutions I used to solve it.
making sure my fresh linux mint system is ready
so to be able to use laravel I started by searching on the web how to install it on my machine which is running linux mint 19.1 with XFCE.
first, let's do the habitual update/upgrade stuff:
sudo apt-get update
sudo apt-get upgrade
"Next step is to install PHP along with several extra packages that would prove useful if you are going to work with Laravel."
now we want to be able to use composer in our system. Composer being a dependency manager for php (see more here)
just as Mr Jossart said "The curl command downloads composer.phar package to your /tmp directory. But we would want composer to run globally hence we need to move it to /usr/local/bin/ directory under the name 'composer'. Now we can run composer from anywhere."
We now thank Mr Jossart for his help and follow up with another person. Him was gonna setup a new laravel system. But WE already have a repository with a laravel webapp on github. Hence we will not have to do everything from scratch. We will
- go on our repository
- clone our repository in our system using
git clone theRepoAddressto do so.
- we will cd in the directory of our freshly cloned repo.
installing MariaDB mysql
We now have to install MariaDB and mysql. To do so, I used this page. Which makes it pretty simple because you only have to use this command:
The MariaDB service will start automatically. You can verify it by typing:
sudo systemctl status mariadb
Now, here comes some fun. We want to have our own .env file so our laravel web app knows where to search for what. So we will create a mysql user and password as well as a database. To do so I used the help of this page.
we want to enter in the mysql repl as root :
sudo mysql -u root -p
now we want to create a new user. Be sure to replace MyUsername and MyPassword with your own chosen username and password :
CREATE USER 'MyUsername' IDENTIFIED BY 'MyPassword';
now we want to create the database (change DBname for the name you want for your database) :
CREATE DATABASE `DBname`;
now lets grant permissions :
GRANT USAGE ON *.* TO 'myuser'@localhost IDENTIFIED BY 'mypassword';
GRANT ALL privileges ON `theDatabaseYouCreated`.* TO 'theUserYouCreated'@localhost;
Apply changes made
To be effective the new assigned permissions you must finish with the following command:
now we get out of mysql with this command :
Setting the .env file of our laravel project
first of all be sure to be at the root of your laravel project directory.
good. Now there is always a file named .env.example copy it to .env like this in your terminal:
cp .env.example .env
now open it with you favorite text editor and enter the username, password and database name you chose in the last step in these three columns:
DB_DATABASE=putTheDBNameHere DB_USERNAME=putYourUsernameHere DB_PASSWORD=putYourPasswordHere
now be sure that you are in you repo file and do this command
now you should be good to do the following command which will migrate the laravel webapp for you :
php artisan migrate:fresh --seed
for me, it didnt work as it gave me this error :
Symfony\Component\Debug\Exception\FatalErrorException : Trait 'App\Providers\Illuminate\Support\Facades\Schema' not found
I fixed it by installing this package
sudo apt-get install php7.2-mysql
if your php version is different you can verify it with php --version and then install the concording php-mysql package.
I then faced this probleme:
Illuminate\Database\QueryException : SQLSTATE: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table
which is something with the charTypes. I fixed it by going in my AppServiceProvider.php file located in myLaravelProjectDir/app/Providers/
and added in the boot function
you can now migrade the Jobs to your local system individually using :
php artisan job:dispatch JOB1 JOB2 ...
then generate a key from artisan to be able to launch your test server with
php artisan key:generate
then you can launch the server with serve
php artisan serve
other resource I used:
blog post banner attribution : People vector created by pch.vector - www.freepik.com