We're live-coding on Twitch! Join us!
DEVELOPING LOCALLY USING SQLITE WITH LARAVEL ON UBUNTU

DEVELOPING LOCALLY USING SQLITE WITH LARAVEL ON UBUNTU

I have had a lot of issues with my MYSQL configuration on my Ubuntu OS recently. I have gone through all the questions that are related to the problems on StackOverflow but it didn’t yield any result. I also asked questions too. I had to keep switching between Ubuntu and Windows to work on any of my PHP projects and it has been tiring and stressful. So, I decided to explore another database system with PHP for the first time and I saw that Laravel supported SQL Server, MYSQL, SQL SERVER and Postgres. Sqlite came to my mind first because I have used it for Android development. As I started to configure my Laravel project to work with Sqlite, I found out that setting up Sqlite to work with Laravel is not as easy as that. So, I have decided to write this short tutorial. Trust it helps you!

Requirements

Table of Contents

  • PHP 7+
  • Text Editor (I use PHPStorm)

Steps

Step 1

create a database.sqlite file in your database folder of your Laravel project.

Step 2

Open your database.php file in the config folder of your project and make sure what you see in the image below is the same in your project.

Step 3

Go to your .env file *and and change your *DB_CONNECTION *to sqlite. Another thing you have to do is change *DB_DATABASE to the path of your database.sqlite on your local computer.

Note: You don’t need to change the value of DB_USERNAME and DB_PASSWORD

Step 4

You should install the driver that allows you to use PHP with Sqlite. If you are using PHP 7, run this code in your terminal:

sudo apt-get install php7.0-sqlite3

For PHP 5 versions, you run this code in your terminal

Step 5

Stop your Apache server with this command in your terminal

sudo service apache2 stop

Then, restart the server with this command

sudo service apache2 restart

Step 6

You can run your migrations now but first run this command in your terminal

php artisan migrate:install — env=local

before you migrate your tables to the database with this command

php artisan migrate — env=local

Step 7

Launch your Laravel project from your terminal with this command

php artisan serve — host=”127.0.0.1" — port=3000 –env=”development”

Then, you can view your project from this URL http:// 127.0.0.1:3000 or any domain specified by you.

Final Step

To test if your configuration works, run this command to set up Laravel Authentication scaffoldings

php artisan make:auth

then go to http:// 127.0.0.1:3000/registeron your browser and try to register. You should have everything set up.

Note: To check your database, using inbuilt PHPStorm database feature will save you a lot of stress. This means that you can access objects in your Sqlite database like you using PHPMYADMIN for Mysql

Conclusion I believe this tutorial was helpful. I just decided to share my experience. I hope it helps solve your problem.

If you like my post, show me love by recommending my post. Follow me on Twitter @goodnesskayode and Medium @goodnesskay

Enjoy PUSHING codes!!!

Like this article? Follow @goodnesskayode on Twitter

Host websites with a $100 credit