In the field of web development, the Laravel framework is called a classic. It has smooth and elegant syntax and powerful functions, coupled with numerous expansion packages, making the Laravel framework one of the most popular PHP frameworks currently. This article will lead readers to understand the installation steps of the Laravel framework.
1. Environmental requirements
Before you start installing the Laravel framework, make sure that your development environment meets the following requirements:
2. Installation steps
Open your terminal window (you can open CMD on a Windows computer), execute the following code to start installing Composer.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php composer-setup.php php -r "unlink('composer-setup.php');"
Open the terminal window and execute the following code to start installing the Laravel framework.
composer create-project laravel/laravel laravel-project
Where laravel-project is the name of your new project.
After the Laravel framework is installed, execute the following command to start the Laravel project.
cd laravel-project php artisan serve
Now, you can open your browser and enter localhost:8000 to access your Laravel project.
3. Laravel environment configuration
Find the public folder in the Laravel installation directory and use it as the site root directory. In Apache, the configuration of the site root directory can be completed through the VirtualHost directive.
Add the following configuration code in VirtualHost:
<VirtualHost *:80> DocumentRoot /path/to/laravel-project/public ServerName yourdomain.com <Directory /path/to/laravel-project/public> AllowOverride All Require all granted </Directory> </VirtualHost>
Where /path/to/laravel-project/public should be replaced with your Laravel project directory. You should also replace yourdomain.com with your domain name.
In Nginx, the configuration code is as follows:
server { listen 80; server_name yourdomain.com; root /path/to/laravel-project/public; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_pass unix:/run/php/php7.2-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
Among them, /path/to/laravel-project/public should be replaced with your Laravel project directory. You should also replace yourdomain.com with your domain name.
In Laravel, environment variables are saved in the .env file and can be modified by modifying the file.
You can copy a .env.example file by executing the following command and name it .env.
cp .env.example .env
You can modify the name of the Laravel project by modifying the APP_NAME variable in the .env file.
4. Conclusion
This article introduces the installation steps of the Laravel framework. We hope this tutorial is helpful to you. The Laravel framework has an excellent PHP code style, comes with a template engine, Symfony components, caching system and Artisan command line tool, and also provides a simple MVC architecture and database abstraction layer. If you are a web development engineer, we recommend you to use the Laravel framework.
The above is the detailed content of [Organization and Sharing] Installation steps of Laravel framework. For more information, please follow other related articles on the PHP Chinese website!