Install
Server Requirements
Laravel has some system requirements. Of course, all these requirements can be met by the Laravel Homestead virtual machine, so it is highly recommended that you use Homestead as your development environment.
Of course, if you are not using Homestead, please make sure your server meets the following requirements:
- PHP >= 7.1.3
- OpenSSL PHP Extension
- PDO PHP extension
- Mbstring PHP extension
- Tokenizer PHP extension
- XML PHP extension
- Ctype PHP extension
- JSON PHP expansion
- BCMath PHP expansion
composer global require laravel/installerMake sure to place composer's system-wide vendor bin directory in Your system environment variable
$PATH so that the system can find the Laravel executable file. This directory exists in different locations depending on your operating system; some common configurations include:
- macOS:
- $HOME/.composer/vendor/bin
- $HOME/.config/composer/vendor/bin
- %USERPROFILE%\AppData\Roaming\Composer\vendor\ bin
laravel new command will create a new Laravel project in the directory you specify. For example,
laravel new blog will create a directory named
blog with all Laravel dependencies installed:
laravel new blogCreate a project through ComposerAlternatively, you can run the
create-project command in the terminal to install Laravel:
composer create-project --prefer-dist laravel/laravel blogLocal Development EnvironmentIf you have PHP installed locally and you want to use PHP's built-in server to serve your application, you can use the Artisan command
serve. This command will start the development server on
http://localhost:8000:
php artisan serveOf course, it is best to choose Homestead and Valet. ConfigurationPublic pathAfter installing Laravel, You should configure your web service's documentation directory to point to the
public path. The
index.php file in this path serves as the front-end controller for all HTTP requests entering the application.
Configuration files
All configuration files of the Laravel framework are stored in the config
directory. Each option is documented, making it easy to look through the file and familiarize yourself with the options that may be useful to you.
Directory Permissions
After installing Laravel, you may need to configure some permissions. The storage
and bootstrap/cache
directories should be writable under your web service, otherwise Laravel will not run. If you are using a Homestead virtual machine, these permissions should already be set.
Application Key
The next step after installing Laravel is to set your application key to a random string. If you installed it through composer
or the Laravel installer, this key has already been set for you through the php artisan key:generate
command.
Normally, this string should be 32 characters long. This key will be set in the environment variable file .env
. If you have not renamed the .env.example
file to the .env
file, you will need to rename the .env.example
file to . env
file. If the application key has not been set, your user sessions and other encrypted data will not be secure!
Other configuration
Laravel almost does not need any other configuration besides the above. You can start developing however you want! However, you may want to look again at the config/app.php
file and its comments. It contains some options that you may want to change depending on your application, such as: timezone
and locale
.
You may also want to configure some other components of Laravel, such as:
- Cache
- Database
- Session Control
public/.htaccess file usually used in the resource path Hide the front controller of
index.php. Before serving Laravel with Apache, make sure the
mod_write module is enabled so that the
.htaccess file can be parsed by the server.
.htaccess file that comes with Laravel does not work, try the following alternative:
Options +FollowSymLinks -Indexes RewriteEngine On RewriteCond %{HTTP:Authorization} .RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L]
Nginx
If you use Nginx, add the following configuration to your site configuration, all requests will be directed to the index.php
front-end controller.
location / { try_files $uri $uri/ /index.php?$query_string;}
When you use Homestead or Valet, elegant links will be automatically configured.