Subscription Plans

Beginner’s Bundle

$
3.00
$
$
0
  • Access to all standard articles and news updates
  • Ad-supported experience
  • Weekly newsletter with top stories
  • Bookmark articles to read later

Infinity Plan

$
7.00
$
$
0
  • Everything in the Premium Plan
  • Priority customer support
  • Monthly live Q&A sessions with our editors
  • Unlimited access to archived articles
  • Invitations to exclusive virtual events and webinars

Elevate Subscription

$
5.00
$
0
  • Everything in the Basic Plan
  • Ad-free browsing for an uninterrupted experience
  • Early access to featured articles
  • Exclusive premium content and in-depth analysis
  • Access to member-only newsletters
Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

HOW TO INSTALL AND USE LARAVEL WITH SQLITE DATABASE ON YOUR WINDOWS PC

Date:

Share post:

In the web development world, several web application frameworks are required in the development of a website, that is, the backend aspect, some of which include – Angular, Django, React, Vue.js, Laravel, Expressjs, and many others. 

However, these web development frameworks require a tool to store, manage, and manipulate databases that are imputed into the website. These operations are not visible to end users but to the developers, which is why they are referred to as the backend/UX of the website. Examples of web development databases include MongoDB, Redis, Microsoft SQL Server, SQLite, etc. However, this article will focus on the installation of Laravel with SQLite. 

Laravel, which is the focus of this article, is a web application framework with expressive, elegant syntax. Laravel is also used to build robust, full-stack applications in PHP. It was developed by Taylor Otwell in 2011. SQLite is a lightweight, open-source, Relational Database Management System (RDBMS) that is used to store data in a single file on a hard drive. It also allows users to interact with a database by storing structured data like numbers or text in a file.

 One key reason why SQLite as a relational database management system is used alongside Laravel is its simplicity, fast configuration, and lack of server setup. SQLite offers developers a reliable solution for building efficient applications.

 

What, then, are the steps to installing PHP and Composer on your PC as they are prerequisites?

  1. Install PHP. You can use XAMPP, a free and open-source web server solution package. 
  2. Download the latest version of Composer from the Composer website. 
  3. Run the Composer installer: 
  4. Double-click the downloaded Composer-Setup.exe file 
  5. Follow the installation wizard 
  6. Choose the installation location and other preferences 
  7. Select Install 

Then verify the installation: 

  1. Open Command Prompt or PowerShell 
  2. Type composer -version 

The Composer version number should be printed on the console 

The latest version of Composer requires PHP 7.2.5 to run. 

Once this condition is met, Composer will need to manage dependencies. This is done by; 

  1. Package installation: Composer can install Laravel and its core components, as well as other packages and extensions. 
  2. Autoloading: Composer generates an autoloader for the project, which makes it easier to load classes. 
  3. Version control: Developers can specify version constraints for packages in the project’s composer.json file. 
  4. Package updates: Composers can easily update packages to their latest compatible versions. 
  5. Project configuration: Developers can use composer.json to define project-specific settings, such as the project name, description, authors, and licenses. 
  6. Script execution: Developers can define custom scripts in the composer.json file to automate tasks like migrations, cache clearing, and custom command executions. 

Once Composer downloads the dependencies’ files, it places them in the vendor directory in the project. The vendor directory is the standard location for all third-party code in a project.

To install Laravel using Composer, note that Composer Global requires “Laravel/installer”

composer create-project laravel/laravel (after running this command, a folder having the name Laravel will be created there)

Now go inside the Laravel folder and run the php artisan serve command.

 

Installing SQLite on Windows

Step 1: Download SQLite: Visit the official SQLite website and download the Windows binaries.

How to extract and place SQLite in a preferred directory:

First, open the SQLite database file with the sqlite3 command:

sqlite DATABASE_FILE.sqlite. Next, set the output so that command results are sent to a file instead of displayed:

.output schema.sql. Finally, output the schema by typing:

.schema. …

.output.

Step 2: Adding SQLite to the System Path

Explanation of setting up the environment variable to access SQLite from the command line;

  1. To set up the environment variable to access SQLite from the command line, you can add the SQLite directory to your system’s PATH environment variable:
  2. Unzip the downloaded SQLite file into a directory, such as C:\sqlite
  3. Right-click on the This PC or My Computer icon on your desktop
  4. Select Properties
  5. Click Advanced System Settings
  6. Click Environment Variables
  7. Under System Variables, find the Path variable and click Edit
  8. Add the C:\sqlite directory to the list of paths separated by a semicolon 

Checking if SQLite is installed properly by running sqlite3 in the command prompt.

 Setting Up Laravel Project

Step 1: Creating a New Laravel Project

Using Composer to create a new Laravel project:
bash
composer create-project –prefer-dist laravel/laravel sqlite-laravel-app

Step 2: Navigate to Project Directory

Open the project directory and ensure everything is set up.

Configuring Laravel to Use SQLite

Step 1: Setting up the .env File

Modify the .env file to configure the database connection:
bash.
DB_CONNECTION=sqlite

DB_DATABASE=/full/path/to/database/database.sqlite

Mention creating a database.sqlite file inside the database folder of your Laravel project.

Step 2: Creating the SQLite Database File

Use the command to create the SQLite database:
bash
touch database/database.sqlite

Explanation on how to check the connection in Laravel’s config/database.php.

Running Laravel Migrations

Step 1: Migrating Database Tables

Run the migration command to create default Laravel tables in SQLite:
bash
php artisan migrate

Step 2: Checking Tables in SQLite

Use an SQLite browser (like DB Browser for SQLite) to inspect tables and verify migration success.

Testing Laravel Application with SQLite

Step 1: Running Laravel Development Server

Start the Laravel server and access the application on the local host:
bash
Copy code
php artisan serve

Step 2: Testing CRUD Operations

Test database operations (like creating, reading, updating, and deleting) to ensure SQLite is working seamlessly with Laravel.

The summary of the process to install SQLite in Laravel includes;

  • Install PHP and Composer on Windows
  • Download SQLite
  • Adding SQLite to System Path
  • Setting Up Laravel Project
  • Configuring Laravel to Use SQLite
  • Running Laravel Migrations
  • Testing Laravel Application with SQLite

In conclusion, Integrating SQLite with Laravel offers developers a strong set of tools for building web applications. SQLite’s straightforward nature, paired with Laravel’s seamless compatibility, makes for an efficient development process. Whether for small projects or larger ones, this combination allows developers to take advantage of easy setup and the capabilities of Eloquent, maximizing the potential of this powerful pairing in web development. 

As reiterated in previous articles, the importance of community must be considered, especially in the tech space. Every expert programmer you admire started by learning to build simple programs. Here at Teners.net, we connect people who are interested in learning programming from scratch, ensuring that personalized tutorship is our priority. If you want to know more, reach out to us and other enthusiastic programmers who are learning in our academy at Teners.net.

 

 

 

 

Source link

spot_img

Related articles

File Hashes Analysis with Power BI from Data Stored in DShield SIEM

I previously used Power BI to analyze DShield sensor data and this time I wanted to show...

Raspberry Pi Pico powers $75 PicoCalc portable programming handheld

Building a Raspberry Pi project from scratch is always a satisfying experience and one of the best ways...

AI Ethics in Event Management

The rapid adoption of artificial intelligence in event management has created new opportunities and challenges for event professionals...