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!
SQLite should be installed on your PC — follow this Tutorialpoint link)
Text Editor (I use PHPStorm)
database.sqlite file in the database folder of your Laravel project.
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.
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
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
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
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
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.
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.
I hope this tutorial helped you benefit from my experience!
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.