Developing Locally Using SQLite with Laravel on Ubuntu

Published Jun 13, 2017
Developing Locally Using SQLite with Laravel on Ubuntu

I was having a lot of issues with my MySQL configuration on my Ubuntu OS, even after going through all the related questions on Stack Overflow and asking my own. I had to keep switching between Ubuntu and Windows to work on any of my PHP projects, and it was 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 PostgreSQL.

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. I hope it helps you!

Requirements

Steps

Step 1

Create a database.sqlite file in the 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/register on your browser and try to register. You should have everything set up.

Note: When checking your database, using the inbuilt PHPStorm database feature will save you a lot of stress. This means that you can access objects in your SQLite database the same way you would use phpMyAdmin for MySQL.

Conclusion

I hope this tutorial helped you benefit from my experience!

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

Enjoy PUSHING codes!!!


This post was originally published by the author here. This version has been edited for clarity and may appear different from the original post.

Discover and read more posts from Goodness Toluwanimi Kayode
get started
Enjoy this post?

Leave a like and comment for Goodness

2
1