Master Composer & Laravel: Step-by-Step Setup Guide for Beginners
This tutorial explains what Composer is, walks through installing Laravel, creating a new project, configuring Nginx, handling common permission and font‑loading issues, and provides practical command‑line examples for a complete backend setup.
What is Composer
Composer is a PHP dependency management tool that allows you to combine many small open‑source packages into a complete project. It replaces the old project‑level open‑source model where each library was distributed as a separate project.
Install Laravel
Use Composer to install the Laravel installer and create a new Laravel project:
composer global require "laravel/installer" composer create-project --prefer-dist laravel/laravel blogCheck the Laravel version with:
laravel -vCreate a New Project
1. Enter the working directory
cd /data/www/2. Create the project
composer create-project --prefer-dist laravel/laravel blogThis command creates a directory named blog. Running it a second time may cause the terminal to hang.
3. View the project files
subl .4. Backend – composer.json
The composer.json file lists the project’s PHP dependencies; the require section shows that the project uses Laravel 5.5 and its transitive dependencies.
5. Frontend – package.json
The package.json file lists JavaScript dependencies managed by npm, such as axios for HTTP requests, cross‑env, and webpack. Note that the default Bootstrap configuration uses the Sass source /resources/assets/sass/app.scss.
6. Install npm packages
sudo apt install npm npm iAfter installation, all front‑end packages are placed in the generated node_modules directory.
7. Environment file
A .env file is generated automatically with the project’s environment configuration.
8. View the site in a browser
Add an entry to /etc/hosts: 127.0.1.1 l.blog.com Then open l.blog.com in a browser.
9. Nginx configuration
Test the Nginx configuration with: sudo nginx -t Edit the Nginx configuration directory (e.g., subl /usr/local/nginx/conf/nginx.conf) to add a server block that matches *.blog.com. The server root should point to /data/www/blog.com/public so that Nginx serves Laravel’s index.php. Important include files are enable-php.conf (PHP communication) and enable-laravel.conf (Laravel‑specific settings). Example location block:
location / {
try_files $uri $uri/ /index.php$is_args$args;
}Q&A
Q: unexpectedValueException: the stream or file “/data/www/blog.com/storage/logs/laravel.log” could not be opened: Permission denied A: The issue is related to file permissions. Fix it with: sudo chmod -R 777 . Note the capital “R”.
Q: The site keeps loading indefinitely (spinning) A: Open developer tools (F12) and check the Network tab. A request to fonts.googleapis.com is pending because the default view references the Raleway Google font. Remove or comment out the font reference in resources/views/welcome.blade.php or in /resources/assets/sass/app.scss where Bootstrap imports it. After commenting, recompile the assets with: npm run prod Q: Accessing l.blog.com shows the LNMP one‑click installer page A: The Nginx server block is not configured correctly. Edit /usr/local/nginx/conf/nginx.conf , add the proper server configuration, test with sudo nginx -t , then reload:
sudo nginx -s reloadSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
