نصب و راه اندازی
نصب و راه اندازی
نیازمندی های سرور
چارچوب لاراول چند مورد نیاز سیستمی دارد. تمام این الزامات توسط ماشین مجازی Laravel Homestead برآورده می شود ، بنابراین به شدت توصیه می شود که از Homestead به عنوان محیط توسعه لاراول محلی خود استفاده کنید.
با این حال، اگر از Homestead استفاده نمی کنید، باید مطمئن شوید که سرور شما شرایط زیر را برآورده می کند:
- PHP >= 7.2.5
- پسوند BCMath PHP
- پسوند PHP Ctype
- پسوند فایل اطلاعات PHP
- پسوند JSON PHP
- پسوند PHP Mbstring
- پسوند OpenSSL PHP
- پسوند PDO PHP
- پسوند PHP Tokenizer
- پسوند XML PHP
نصب لاراول
لاراول از Composer برای مدیریت وابستگی های خود استفاده می کند. بنابراین، قبل از استفاده از لاراول، مطمئن شوید که Composer را روی دستگاه خود نصب کرده اید.
از طریق Laravel Installer
ابتدا نصب کننده لاراول را با استفاده از Composer دانلود کنید:
composer global require laravel/installer
مطمئن شوید که پوشه vendor bin در سراسر سیستم Composer را در خود قرار دهید
$PATH
تا فایل اجرایی لاراول توسط سیستم شما قرار گیرد.
این دایرکتوری بر اساس سیستم عامل شما در مکان های مختلف وجود دارد.
با این حال، برخی از مکان های رایج عبارتند از:
-
سیستم عامل مک:
$HOME/.composer/vendor/bin
-
پنجره ها:
%USERPROFILE%\AppData\Roaming\Composer\vendor\bin
-
توزیع های گنو / لینوکس:
$HOME/.config/composer/vendor/bin
یا$HOME/.composer/vendor/bin
همچنین می توانید مسیر نصب جهانی composer را با اجرا
composer global about
و جستجو از خط اول پیدا کنید.
Once installed, the laravel new
command will create a fresh Laravel installation in the directory you
specify. For instance, laravel new blog
will create a directory named blog
containing a
fresh Laravel installation with all of Laravel's dependencies already installed:
laravel new blog
Via Composer Create-Project
Alternatively, you may also install Laravel by issuing the Composer create-project
command in your
terminal:
composer create-project --prefer-dist laravel/laravel:^7.0 blog
Local Development Server
If you have PHP installed locally and you would like to use PHP's built-in development server to serve your
application, you may use the serve
Artisan command. This command will start a development server at
http://localhost:8000
:
php artisan serve
More robust local development options are available via Homestead and Valet.
Configuration
Public Directory
After installing Laravel, you should configure your web server's document / web root to be the public
directory. The index.php
in this directory serves as the front controller for all HTTP requests
entering your application.
Configuration Files
All of the configuration files for the Laravel framework are stored in the config
directory. Each option
is documented, so feel free to look through the files and get familiar with the options available to you.
Directory Permissions
After installing Laravel, you may need to configure some permissions. Directories within the storage
and
the bootstrap/cache
directories should be writable by your web server or Laravel will not run. If you
are using the Homestead virtual machine, these permissions should already be set.
Application Key
The next thing you should do after installing Laravel is set your application key to a random string. If you
installed Laravel via Composer or the Laravel installer, this key has already been set for you by the
php artisan key:generate
command.
Typically, this string should be 32 characters long. The key can be set in the .env
environment file. If
you have not copied the .env.example
file to a new file named .env
, you should do that
now. If the application key is not set, your user sessions and other encrypted data will not be
secure!
Additional Configuration
Laravel needs almost no other configuration out of the box. You are free to get started developing! However, you may
wish to review the config/app.php
file and its documentation. It contains several options such as
timezone
and locale
that you may wish to change according to your application.
You may also want to configure a few additional components of Laravel, such as:
Web Server Configuration
Directory Configuration
لاراول باید همیشه خارج از ریشه «دایرکتوری وب» پیکربندی شده برای وب سرور شما ارائه شود. شما نباید سعی کنید یک برنامه لاراول را از زیر شاخه ای از "دایرکتوری وب" ارائه دهید. تلاش برای انجام این کار میتواند فایلهای حساس موجود در برنامه شما را فاش کند.
URL های زیبا
آپاچی
لاراول شامل
public/.htaccess
فایلی است که برای ارائه URL ها بدون
index.php
کنترلر جلویی در مسیر استفاده می شود.
قبل از سرویس لاراول با آپاچی، حتما
mod_rewrite
ماژول را فعال کنید تا
.htaccess
فایل توسط سرور مورد احترام قرار گیرد.
اگر
.htaccess
فایلی که با لاراول ارسال می شود با نصب آپاچی شما کار نمی کند، این جایگزین
را امتحان کنید:
Options +FollowSymLinks -IndexesRewriteEngine On RewriteCond %{HTTP:Authorization} .RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^ index.php [L]
Nginx
اگر از Nginx استفاده می کنید، دستورالعمل زیر در پیکربندی سایت شما، تمام
درخواست ها را به
index.php
کنترلر جلو هدایت می کند:
location / { try_files $uri $uri/ /index.php?$query_string;}
هنگام استفاده از Homestead یا Valet ، URL های زیبا به طور خودکار پیکربندی می شوند.