Laravel is a popular PHP framework that provides many convenient features and tools such as a good declarative syntax that can be installed through composer, consistent API, easy-to-use ORM, integrated authorization system and more . In this article, we will explain how to install the Laravel framework.
First of all, before using Laravel, you need to make sure that your computer environment has PHP7, Composer, MySQL database and Node.js installed. Here we take macOS as an example to show how to install Laravel.
Step 1: Install Composer
Enter the following command in the terminal:
curl -sS https://getcomposer.org/installer | php
The above command will download the installer of Composer using the curl command and run it through the php command. When the execution is completed, an executable file named composer.phar will be generated in the current directory.
In order for Composer to run in the global environment, it needs to be moved to the /usr/local/bin directory:
mv composer.phar /usr/local/bin/composer
Step 2: Install Laravel
When Composer After the installation is complete, you can use the following command to create a project named Laravel in the terminal:
composer create-project --prefer-dist laravel/laravel myproject
where, myproject is the name of the project you want to create, you can name it arbitrarily.
After the project is successfully created, the terminal will display the following prompt message:
Writing lock file Generating autoload files
Next, you need to configure the database information in the .env file. You can open the .env file with the following command:
nano myproject/.env
In the .env file, modify the following configuration items:
DB_DATABASE=yourdatabase DB_USERNAME=yourusername DB_PASSWORD=yourpassword
After the modification is completed, save and exit the file.
Step 3: Start Laravel
Use the following command to start Laravel:
cd myproject php artisan serve
After that, open http://localhost:8000 in your favorite browser and you will You can see Laravel’s welcome page.
If you need to deploy the Laravel project to a production environment, you can upload the code to the server, and then run the following command in the project root directory to optimize the project:
php artisan optimize
This can improve Laravel's Performance and speed.
Conclusion
Laravel is a feature-rich PHP framework with a good declarative syntax, consistent API, easy-to-use ORM, integrated authorization system and more. Through the above steps, you can successfully install the Laravel framework on your computer and start it, so that you can start using Laravel to develop your own applications.
The above is the detailed content of How to install Laravel framework (steps). For more information, please follow other related articles on the PHP Chinese website!