Points to KNOW to develop projects with LARAVEL
What Version of Composer
we have to install
Laravel support Latest
Composer version which support PHP 8.2
So First update PHP in
your System
What We use the Thread
Safe and Non Thread Safe versions ?
The choice between Thread
Safe and Non Thread Safe versions of PHP depends on the server setup
you plan to use:
1.
Thread Safe (TS):
o Use
this version if you are using a web server that runs in a multi-threaded
environment, like Apache on Windows with the default setup.
o Thread
Safe PHP ensures that all operations are executed safely in a multi-threaded
environment by locking the process threads to prevent issues with concurrent
executions.
2.
Non Thread Safe (NTS):
o This
version is typically used if you are running PHP in a FastCGI
environment or any other setup where the web server uses separate processes for
handling requests instead of threads.
o Non
Thread Safe PHP has better performance in these cases, as it doesn’t require
thread safety checks.
Which to Install:
- If
you're using Apache with mod_php on Windows: Go with
the Thread Safe version.
- If
you're using IIS with FastCGI or any other server
setup that doesn't rely on threads: Choose the Non Thread Safe
version.
If you're unsure and just
developing locally, the Thread Safe version is typically safer to start
with.
No, you don't need to reinstall Composer after upgrading to PHP 8.2. Composer will automatically work with the newly installed PHP version as long as PHP 8.2 is correctly set in your system's PATH environment.
After installing PHP 8.2,
you can verify that Composer is using the correct PHP version by running the
following command in the terminal:
composer -vvv about
1. Ensure PHP 8.2 is Set
in PATH
Make sure PHP 8.2 is set
as the default version in your system's environment variables:
- Go
to Control Panel > System > Advanced system settings >
Environment Variables.
- Under
System variables, find the Path variable and ensure the path to PHP
8.2 (e.g., C:\path\to\php8.2\) is set above the path for PHP 8.0 or remove
the PHP 8.0 path.
- You
can verify the PHP version by running:
php
-v
Ensure
it shows PHP 8.2.
2. Recheck Composer
Version with PHP 8.2
Once PHP 8.2 is in your
PATH, check if Composer is using it:
composer
-vvv about
It
should now display PHP 8.2.
3. Global composer.json
Not Required
The message about the
global composer.json indicates that Composer couldn't find a global
configuration file. This file is optional and not required unless you use
global Composer packages.
To proceed with Laravel
or any other project:
- Navigate
to your project directory and run:
composer
init
This
will create a composer.json file in the project directory.
Now, you should be able
to use Composer with PHP 8.2 and resolve any Laravel dependencies.
1: Enable the OpenSSL
Extension
1. Enable the OpenSSL
Extension in PHP
1.
Locate the PHP installation folder
for PHP 8.2. It might be in a directory like C:\php\ or wherever you've
installed it.
2.
Open the php.ini file located in your PHP
installation folder. If there are multiple php.ini files, make sure you're
editing the one associated with PHP 8.2. You can locate the correct one by
running:
php
--ini
Which
php.ini development or production , We have to choose?
The difference between
php.ini-development and php.ini-production is related to the configuration
settings optimized for different environments:
1.
php.ini-development:
o This
configuration is designed for development environments.
o It
enables detailed error reporting and logging, which is helpful when you're
actively developing a project and debugging issues.
o Security
settings are generally more relaxed to make it easier to test features.
2.
php.ini-production:
o This
configuration is optimized for production environments where performance and
security are critical.
o Error
reporting is reduced to avoid showing sensitive information, and certain
features are disabled to ensure the application is more secure.
o It
also focuses on performance optimization.
Which One to Use?
- For
local development or testing, it’s better to use
php.ini-development, as it provides more detailed error messages and
warnings that can help with debugging.
- For
production environments, you should use
php.ini-production, as it enhances security and performance.
How to Choose:
1.
Rename
the file you want to use:
o If
you're in a development environment, copy or rename php.ini-development to
php.ini.
o If
you're preparing for production, rename php.ini-production to php.ini.
If you're setting up PHP
for development purposes (e.g., for working on a Laravel project), and
you want to use the php.ini-development file, here are the essential steps and
changes you may need to make:
1. Copy or Rename
php.ini-development
First, navigate to your
PHP installation directory and locate the php.ini-development file.
- Rename
it to php.ini.
2. Key Changes to Make in
php.ini
a) Enable the openssl
Extension
Uncomment the line to
enable the openssl extension. Find this line:
;extension=openssl
And change it to:
extension=openssl
b) Enable Other Required
Extensions (if needed)
Depending on your project
requirements, you might need to enable additional extensions like pdo,
mbstring, etc. For Laravel, these are commonly required:
- Find
and uncomment the following lines:
extension=pdo_mysql
extension=mysqli
extension=mbstring
c) Display Errors
(Optional for Development)
In development mode, you
often want to see errors directly in the browser or terminal. Ensure the
following settings are configured:
- Find
and set display_errors to On:
display_errors = On
- Ensure
error_reporting is set to a high level to catch all errors:
error_reporting = E_ALL
d) Configure
max_execution_time and memory_limit
For development purposes,
you may want to relax these limits to avoid issues during testing:
- Increase
the script execution time if needed:
max_execution_time = 300
- Increase
the memory limit:
memory_limit = 512M
e) Date.timezone
Set the correct timezone
to avoid warnings:
- Find
the date.timezone line and set it according to your location. For example,
if you're in India:
date.timezone =
Asia/Kolkata
3. Save and Apply Changes
Once you’ve made these
changes, save the php.ini file and restart your terminal or server (e.g.,
Apache or Nginx) to apply the settings.
4. Verify PHP and OpenSSL
You can verify that
everything is working by running the following commands:
- Check
the PHP version:
php -v
- Check
that OpenSSL and other extensions are enabled:
php -m | grep openssl
php -m | grep pdo_mysql
These steps should get
your PHP environment ready for development with Laravel or any other PHP
project.
1.
Ensure that the openssl extension
is enabled in your php.ini file by uncommenting:
extension=openssl
2.
Restart your system or terminal, and then
verify OpenSSL is enabled by running:
php
-m | grep openssl
If
OpenSSL is listed, you're good to go!
2. Ensure the
libeay32.dll and ssleay32.dll Files are Present
These files should be
present in your PHP installation folder (or in the ext folder). If they’re
missing, you may need to copy them from the PHP installation package or
download them.
- libcrypto-3-x64.dll:
This is the updated version of libeay32.dll.
- libssl-3-x64.dll:
This replaces ssleay32.dll.
These libraries are part
of the OpenSSL 3.0 version, which PHP 8.2 is compatible with.
Steps:
3.
If you have libcrypto-3-x64.dll and
libssl-3-x64.dll in your PHP installation, place them in your PHP
directory (or C:\Windows\System32\ if needed).
3. Restart your System
(Optional)
After making changes to
the php.ini file, it’s often a good idea to restart your system to ensure all
changes are applied, though sometimes just restarting the terminal or your web
server (e.g., Apache or Nginx) is enough.
4. Verify the Extension
is Enabled
Run the following command
to check if the OpenSSL extension is enabled:
php -m | grep openssl
If OpenSSL is listed, the
extension is enabled.
5. Retry Composer
Once OpenSSL is enabled,
you can retry running Composer commands.
1. Check if the .dll
Files Are Present
Go to your PHP
installation directory, typically C:\php\ext, and check if the following files
are present:
- php_mysqli.dll
- php_mbstring.dll
- php_openssl.dll
- php_pdo_mysql.dll
If these files are
missing, PHP cannot load the extensions.
2. Download Missing .dll
Files
If the necessary files
are missing, you'll need to re-download PHP or get the required files.
a) Re-download PHP:
- Visit
the official PHP download page for Windows: https://windows.php.net/download/
- Download
the correct version of PHP (make sure it's the Thread Safe version
for your setup).
- Extract
the contents and check the ext folder for the missing .dll files.
- Copy
the necessary .dll files (listed above) to your current PHP installation’s
ext directory.
b) Ensure Correct PHP
Version:
Make sure you're
downloading the correct version of PHP for your operating system and setup
(either Thread Safe or Non Thread Safe), and for your bit architecture (x64 for
64-bit systems).
3. Edit php.ini
After ensuring the
necessary .dll files are present, make sure these lines are uncommented in your
php.ini file:
extension=mysqli
extension=mbstring
extension=openssl
extension=pdo_mysql
If they are commented
with a ; at the beginning, remove the semicolon.
4. Ensure PHP is Pointing
to the Correct php.ini File
Run the following command
to verify which php.ini file PHP is using:
php --ini
Ensure that the correct
php.ini file is listed. If PHP is using the wrong php.ini file, you can specify
the correct one using the PHPRC environment variable, or ensure the php.ini
file is correctly located in the PHP directory.
5. Restart the Terminal
or Web Server
After making these
changes, restart your terminal or web server (like Apache or Nginx) to apply
the updated configurations.
6. Verify the Changes
Run the following command
to ensure the extensions are now loaded properly:
php -m | grep -E
'mysqli|mbstring|openssl|pdo_mysql'
1. Check extension_dir in
php.ini
Make sure PHP is looking
in the correct folder for extensions.
1.
Open your php.ini file.
2.
Look for the extension_dir directive, and
ensure it points to the correct folder where the .dll files are located (your
ext directory). It should look like this:
extension_dir =
"C:/php/ext"
If the path is incorrect,
PHP won't be able to load the extensions, even if the .dll files are present.You
change it according your path of PHP.
2. Check for System
Environment Variables
Sometimes, Windows needs
to be aware of where PHP and its extensions are installed.
1.
Open Environment Variables (you can
search for it in the Start Menu).
2.
Under System variables, find Path.
3.
Make sure that your PHP installation
directory (e.g., C:\php\) is added to the Path variable.
If PHP isn’t in the
system path, Windows might not be able to locate the necessary libraries.
3. Check for VC++
Redistributable
Make sure that the Visual
C++ Redistributable for Visual Studio 2019 (for PHP 8.2, built with VC16)
is installed. Without it, PHP may fail to load certain extensions.
1.
Download it from here:
https://aka.ms/vs/16/release/vc_redist.x64.exe.
2.
Install the package, then restart your
computer.
4. Check for Conflicting
PHP Versions
Sometimes, having
multiple versions of PHP installed can cause issues.
1.
Check the current PHP version:
php -v
2.
Make sure you’re using the correct version
of PHP by setting the path in the Path environment variable. The version should
be PHP 8.2.x.
5. Verify that the
Correct php.ini is Used
You might have multiple
php.ini files, and PHP could be loading the wrong one.
1.
Run this command:
php --ini
2.
This will show the path to the php.ini
file being used. Ensure it points to the one you’ve modified (where you've
enabled mysqli, mbstring, openssl, and pdo_mysql).
6. Restart the Web
Server/Terminal
Once you've made changes,
restart your terminal or web server (like Apache, Nginx, or PHP's built-in
server) for the changes to take effect.
7. Check the Extensions
Again
Run the following command
to check if the extensions are loading:
php -m | grep -E
'mysqli|mbstring|openssl|pdo_mysql'
If all is set correctly,
you shouldn't see the error anymore. Let me know if any issues persist!
extension_dir =
"C:/php/ext"
6. Restart Your System
Sometimes changes are not
picked up immediately. Restart your computer to ensure all changes are applied.
7. Check PHP Info
To get more details on
what PHP is loading:
1.
Create a file named info.php in your web
root with the following content:
<?php phpinfo(); ?>
2.
Access this file via your web server
(e.g., http://localhost/info.php).
Look for the loaded
configuration file and verify that the extension_dir and enabled extensions are
correctly listed.
8. Update or Reinstall
PHP
If the problem persists:
1.
Download a fresh copy of PHP 8.2 from PHP’s official site.
2.
Replace your existing PHP files with the
newly downloaded ones, ensuring to include the correct .dll files.
1. Enable the fileinfo
Extension in php.ini
1.
Open your php.ini file:
o Located
at C:\php-8.2\php.ini.
2.
Find and enable the fileinfo
extension:
o Locate
the following line:
;extension=fileinfo
o Remove
the semicolon (;) to uncomment the line:
extension=fileinfo
3.
Save the php.ini file.
2. Verify the fileinfo
Extension is Loaded
1.
Restart your web server (e.g.,
Apache, Nginx) or command line interface to apply the changes:
o If
you are using PHP’s built-in server, restart it as well.
2.
Check if fileinfo is loaded:
o Run
the following command in your terminal:
php -m | grep fileinfo
o If
the extension is correctly enabled, you should see fileinfo in the output.
3. Check PHP Configuration
1.
Verify which php.ini file is being
used:
o Run:
php --ini
o Make
sure it points to C:\php-8.2\php.ini or the correct configuration file.
2.
Ensure there are no errors or
additional issues in the php.ini file that might be causing
the fileinfo extension not to load.
4. Re-run Composer
Command
After ensuring that the
fileinfo extension is enabled, try running the Composer command again:
composer install
5. Optional: Use
--ignore-platform-req
If you are still facing
issues and need a temporary workaround, you can use Composer with the
--ignore-platform-req=ext-fileinfo flag. However, this is not recommended as a
long-term solution because it bypasses important checks for necessary
extensions:
composer install
--ignore-platform-req=ext-fileinfo
Summary
By enabling the fileinfo
extension and verifying that it’s loaded correctly, you should be able to
resolve the dependency issues and proceed with installing Laravel and its
packages.
1. Check PHP Modules List
1.
Run the following command in Command
Prompt:php -m
This command lists all
enabled PHP modules. Look through the output for fileinfo.
1. Enable the SQLite
Extension in php.ini
1.
Open your php.ini file:
o Located
at C:\php-8.2\php.ini.
2.
Find and enable the SQLite extension:
o Look
for the following lines:
;extension=sqlite3
;extension=pdo_sqlite
o Remove
the semicolons (;) to uncomment them:
extension=sqlite3
extension=pdo_sqlite
3.
Save the php.ini file.
4.
Restart your web server or PHP CLI
to apply the changes.
2. Verify the SQLite
Extension is Enabled
1.
Check if sqlite3 and pdo_sqlite are
listed:
o Run
the following command in Command Prompt:
php -m
o Look
for sqlite3 and pdo_sqlite in the list of enabled modules.
3. Check Your .env
Configuration
1.
Ensure your .env file
(found in the root of your Laravel project) has the correct database
configuration for SQLite:
DB_CONNECTION=sqlite
DB_DATABASE=/path_to_your_database/database.sqlite
Ensure DB_DATABASE points
to the correct path of your SQLite database file. If the file doesn’t exist,
create it manually.
4. Verify Database File
Path
1.
Make sure the path specified in
DB_DATABASE exists and is writable:
o For
example, if you have DB_DATABASE=/path_to_your_database/database.sqlite, make
sure /path_to_your_database/ directory exists and database.sqlite file is
present.
2.
If using relative paths, ensure
the file path is relative to the Laravel project’s root directory.
5. Check PHP Installation
Ensure that your PHP
installation is complete and includes SQLite support. Sometimes, reinstalling
PHP or using a package manager that includes all necessary extensions might
resolve the issue.
Summary
By enabling the SQLite
extensions in php.ini and verifying your database configuration, you should be
able to resolve the error and get Laravel working with SQLite.
Example Commands
1.
Copy a File:
copy
C:\path\to\source_file.txt C:\path\to\destination_file.txt
2.
Copy a Directory:
xcopy
C:\path\to\source_directory C:\path\to\destination_directory /s /e
.env Configuration
DB_CONNECTION=mysql # Specifies the database driver to use
(MySQL in this case)
DB_HOST=127.0.0.1 # The host where your MySQL database
server is located
DB_PORT=3306 # The port used by MySQL (default
is 3306)
DB_DATABASE=product_db # The name of the MySQL database you are
connecting to
DB_USERNAME=root # The username for connecting to the
MySQL database
DB_PASSWORD=your_mysql_password # The password for the MySQL user
Steps to Follow
1.
Create the Database:
Make sure you have created a database named product_db in MySQL. You can do
this using a MySQL client or command line:
CREATE DATABASE
product_db;
2.
Update .env File:
o Ensure
your .env file has the above configuration.
o Replace
your_mysql_password with the actual password for your MySQL root user (or
another user with appropriate permissions).
3.
Verify MySQL Configuration:
o Make
sure MySQL is running on 127.0.0.1 (localhost) and is listening on port 3306.
o Ensure
that the root user or specified user has the necessary privileges to access
product_db.
4.
Run Migrations
(if needed):
o After
configuring your .env file, you can run Laravel migrations to set up your
database schema:
php artisan migrate
5.
Check Database Connection:
o Ensure
that your application can connect to the database by accessing routes or
features that interact with the database.
Laravel setup:
.env File Breakdown
1.
App Settings:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:kUyWBJj4RghuqQu7bSsp/bBLNdcpxsEkdLFyp5XfLG8=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost
o APP_NAME:
Name of your application.
o APP_ENV:
Application environment (local, production, etc.).
o APP_KEY:
Encryption key for Laravel.
o APP_DEBUG:
Enables debug mode.
o APP_TIMEZONE:
Timezone setting.
o APP_URL:
URL of your application.
2.
Localization:
APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US
o APP_LOCALE:
Default locale for your application.
o APP_FALLBACK_LOCALE:
Fallback locale if the default locale is unavailable.
o APP_FAKER_LOCALE:
Locale for Faker library.
3.
Maintenance and Logging:
APP_MAINTENANCE_DRIVER=file
BCRYPT_ROUNDS=12
LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
o APP_MAINTENANCE_DRIVER:
How Laravel handles maintenance mode.
o BCRYPT_ROUNDS:
Number of rounds for bcrypt hashing.
o LOG_CHANNEL:
Default logging channel.
o LOG_LEVEL:
Logging level.
4.
Database Configuration:
DB_CONNECTION=sqlite
o DB_CONNECTION:
Specifies that SQLite is being used as the database connection.
For SQLite, you also need
to specify the path to the SQLite database file in your configuration:
DB_DATABASE=/path_to_your_database/database.sqlite
Make sure you create this
file (database.sqlite) and provide the correct path.
5.
Session and Cache Settings:
SESSION_DRIVER=database
CACHE_STORE=database
o SESSION_DRIVER:
Specifies how sessions are stored.
o CACHE_STORE:
Specifies how cache is stored.
6.
Other Services:
MAIL_MAILER=log
REDIS_CLIENT=phpredis
o MAIL_MAILER:
Mail driver.
o REDIS_CLIENT:
Redis client configuration.
.env File for MySQL
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:kUyWBJj4RghuqQu7bSsp/bBLNdcpxsEkdLFyp5XfLG8=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost
APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US
APP_MAINTENANCE_DRIVER=file
#
APP_MAINTENANCE_STORE=database
BCRYPT_ROUNDS=12
LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=product_db # Ensure this database exists
DB_USERNAME=root # Your MySQL username
DB_PASSWORD=your_mysql_password # Your MySQL password
SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null
BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database
CACHE_STORE=database
CACHE_PREFIX=
MEMCACHED_HOST=127.0.0.1
REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=log
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}"
Steps to Follow
1.
Create the Database:
o Ensure
you have created a MySQL database named product_db. You can do this using a
MySQL client or command line:
CREATE DATABASE
product_db;
2.
Update .env File:
o Replace
your_mysql_password with your actual MySQL password.
3.
Check MySQL Configuration:
o Make
sure MySQL is running on 127.0.0.1 (localhost) and is listening on port 3306.
o Verify
that the root user (or any other specified user) has access to the product_db
database.
4.
Run Migrations:
o After
configuring your .env file, run Laravel migrations to set up your database
schema:
php
artisan migrate
5.
Verify Connection:
o Test
your application to ensure it can connect to the MySQL database.
The .env content:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:kUyWBJj4RghuqQu7bSsp/bBLNdcpxsEkdLFyp5XfLG8=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US
#
APP_MAINTENANCE_STORE=database
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=product_db # Ensure this database exists
DB_USERNAME=root # Your MySQL username
DB_PASSWORD=your_mysql_password # Your MySQL password
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database
CACHE_PREFIX=
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
Steps After Updating .env
1.
Run Migrations:
php artisan migrate
2.
Clear Config Cache:
php artisan config:cache
3.
Test Your Application:
o Verify
that your Laravel application is connecting to the MySQL database and that
everything is functioning correctly.
Steps to Configure
Laravel with XAMPP
1.
Install XAMPP:
o Ensure
XAMPP is installed and running on your machine. XAMPP includes Apache, MySQL,
and PHP, which is perfect for local development.
2.
Create a Database:
o Open
phpMyAdmin from the XAMPP control panel by going to
`http://localhost/phpmyadmin