Installation Guide
Complete guide to install and configure your Laravel application
Server Requirements
Ensure your server meets these minimum requirements:
Minimum Requirements
- PHP: 8.1 or higher
- Composer: 2.0 or higher
- Database: MySQL 8.0+ / PostgreSQL 13+
- Web Server: Apache 2.4+ / Nginx 1.18+
- Node.js: 16+ (for asset compilation)
- NPM: 8+ or Yarn 1.22+
Required PHP Extensions:
- BCMath, Ctype, cURL, DOM
- Fileinfo, Filter, Hash
- JSON, Mbstring, OpenSSL
- PCRE, PDO, Session
- Tokenizer, XML, ZIP
Tip: Use Laravel Homestead or Valet for easy local development environment setup.
Local Installation
1
Download and Extract
Download the application package and extract it to your desired location.
# Extract the ZIP file
unzip laravel-app.zip
# Navigate to project directory
cd laravel-app
2
Install PHP Dependencies
Use Composer to install all required PHP packages.
# Install Composer dependencies
composer install
# For production, use:
composer install --optimize-autoloader --no-dev
3
Install Frontend Dependencies
Install JavaScript packages using NPM or Yarn.
# Using NPM
npm install
# Or using Yarn
yarn install
4
Create Environment File
Copy the example environment file and configure it.
# Copy environment file
cp .env.example .env
# Generate application key
php artisan key:generate
5
Configure Environment
Edit the .env file with your local settings.
APP_NAME="Your App"
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password
6
Run Migrations
Set up the database structure.
# Run database migrations
php artisan migrate
# Seed the database (optional)
php artisan db:seed
# Or do both at once
php artisan migrate:fresh --seed
7
Compile Assets
Build frontend assets.
# For development
npm run dev
# For production
npm run build
# Watch for changes (development)
npm run watch
8
Start Development Server
Launch the Laravel development server.
# Start the server
php artisan serve
# Custom host and port
php artisan serve --host=0.0.0.0 --port=8080
Visit http://localhost:8000 in your browser!
Environment Configuration
Essential Environment Variables
| Variable | Description | Example |
|---|---|---|
APP_NAME |
Application name | "My Laravel App" |
APP_ENV |
Environment (local/production) | local |
APP_KEY |
Application encryption key | base64:... |
APP_DEBUG |
Debug mode | true (local), false (production) |
APP_URL |
Application URL | http://localhost |
DB_CONNECTION |
Database driver | mysql / pgsql |
MAIL_MAILER |
Mail driver | smtp / log / mailgun |
Database Configuration
MySQL Configuration
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_app
DB_USERNAME=root
DB_PASSWORD=secret
PostgreSQL Configuration
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=laravel_app
DB_USERNAME=postgres
DB_PASSWORD=secret
Running Migrations
# Run all pending migrations
php artisan migrate
# Rollback the last migration
php artisan migrate:rollback
# Reset and re-run all migrations
php artisan migrate:fresh
# Check migration status
php artisan migrate:status
Production Deployment
Important: Never deploy with
APP_DEBUG=true in production!
Optimization Commands
# Optimize configuration loading
php artisan config:cache
# Optimize route loading
php artisan route:cache
# Optimize view loading
php artisan view:cache
# Create cached bootstrap file
php artisan optimize
# Install production dependencies
composer install --optimize-autoloader --no-dev
# Build production assets
npm run build
File Permissions
# Set correct permissions
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
Web Server Configuration
Apache (.htaccess):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Nginx:
server {
listen 80;
server_name yourdomain.com;
root /var/www/app/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
Troubleshooting
If you see permission errors:
sudo chmod -R 775 storage bootstrap/cache
sudo chown -R $USER:www-data storage bootstrap/cache
Regenerate autoload files:
composer dump-autoload
php artisan clear-compiled
php artisan optimize:clear
- Verify database credentials in
.env - Ensure database server is running
- Check database exists:
CREATE DATABASE your_database; - Clear config cache:
php artisan config:clear
# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm install
# Try using specific Node version (via nvm)
nvm use 16
npm run dev