In this article, we will guide you through the process of Laravel installation using composer and configuration of the web server. Install Laravel using Composer with the help of the following steps.
Prerequisites
The Laravel framework requires some prerequisites for the system. All these requirements you will get from Laravel Homestead virtual machine and we would highly recommend you to use Homestead as a local Laravel development environment.
In case, you are not using Homestead, makes sure that your server meets the following requirements.
BCMath PHP Extension
PHP >= 7.2.5
Ctype PHP Extension
JSON PHP Extension
OpenSSL PHP Extension
Fileinfo PHP extension
PDO PHP Extension
XML PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
Step 1: Install Laravel
With the help of Composer, you can install Laravel which also helps you manage dependencies. Therefore, before using Laravel, make sure that you have Composer in your system beforehand.
Through Laravel Installer
First, you need to install a Laravel installer with the help of Composer.
Ensure that you place the system-wide vendor bin directory of Composer in your $PATH so that your system can locate the Laravel executable. Now, this directory locates in various locations depending on your operating system; however, some of the common locations include:
Windows: %USERPROFILE%\AppData\Roaming\Composer\vendor\bin
macOS: $HOME/.composer/vendor/bin
GNU / Linux Distributions: $HOME/.config/composer/vendor/bin or $HOME/.composer/vendor/bin
You can also find the global installation path of the composer when you run composer global about and look up from the first line.
In your recommended directory, laravel new command will build a new Laravel installation after the completion of the installation.
Using the command laravel new blog, for example, will produce a directory called blog containing a brand-new Laravel installation with all of Laravel's dependencies already set up:
Use Composer Create-Project
The alternative method to install Laravel is by using Composer create-project command in your terminal.
Local Development Server
In case you have already installed PHP in your system locally and want to use PHP’s built-in development server to server for your app, the best thing is to use the serve Artisan command. Now, this command helps in starting a development server at http://localhost:8000:
Step 2: Configuration
After Laravel installation, the next step is to configure the web root or document of your web server to be the public directory. The role of index.php file in this directory presents as a front controller for every HTTP request entering your app.
Configuration files
All kinds of Laravel configuration files are stored in the directory named config. Each kind of option is documented and therefore you can look through the files and know all the options given to you.
Directory Permission
You also need to configure a few permissions after Laravel installation. Directories within the storage and the cache or bootstrap directories should be writable by your Laravel or web server will not run. In case you are using the Homestead virtual machine, all these permissions were already given.
Application Key
After installing Laravel, you should configure your application key to a random string. This key has already been set for you if you installed Laravel using Composer or the Laravel installer thanks to the PHP Artisan key: generate command.
This string should typically be 32 characters long. The.env environment file can be used to set the key. If you haven't already, you should copy the.env.example file to a new file with the extension.env. Your user sessions and other encrypted data won't be secure if the application key isn't set!
Additional Configuration
Almost no further setting is required with Laravel out of the box. You are free to start creating now! You might want to look at the config/app.php file's documentation, though. It has a number of settings that you might want to modify depending on your application, like timezone and locale.
You could also wish to set up a few extra Laravel components, like
Step 3: Web Server Configuration
Directory Configuration
When serving Laravel, your web server's "web directory" should always be the root. A subdirectory of the "web directory" should not be used to serve a Laravel application. If you do, your application's sensitive files might be made public.
Pretty URLs
Apache
With Laravel, you may offer URLs without the index.php front controller by using the public/.htaccess file. Enable the mod_rewrite module before serving Laravel with Apache to ensure that the server will respect the.htaccess file.
Try this alternative if the.htaccess file provided with Laravel does not function with your Apache installation:
Nginx
All requests will be routed to the index.php front controller if you are using Nginx, according to the directive listed below in your site configuration:
No comments:
Post a Comment