گفتوگوهای اخیر
Login Dialog
Athena - Chat with AI

Claude 3.7 Sonnet

Claude 3.7 Sonnet
گفتوگوی مستقیم با مدل Claude-3.7-Sonnet، محصول Anthropic
من از مدل Claude-3.7-Sonnet که محصول Anthropic هست استفاده میکنم هر سوالی داری بپرس.

Developing a Laravel Web App: From Initialization to Deployment
Here's a comprehensive guide to creating a Laravel web app on your Mac, integrating it with GitHub, and deploying it to an Ubuntu VPS.
Step 1: Set Up Your Mac Development Environment
-
Install Homebrew (if not already installed):
bash1/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Install PHP:
bash1brew install php
-
Install Composer (PHP dependency manager):
bash1brew install composer
-
Install Node.js and npm (for frontend assets):
bash1brew install node
-
Install Git (if not already installed):
bash1brew install git
Step 2: Create a New Laravel Project
-
Create a new Laravel project using Composer:
bash1composer create-project laravel/laravel my-laravel-app
-
Navigate to your project directory:
bash1cd my-laravel-app
-
Test your installation by starting Laravel's development server:
bash1php artisan serve
Visit http://localhost:8000 in your browser to see the Laravel welcome page.
Step 3: Initialize Git Repository and Connect to GitHub
-
Initialize a Git repository:
bash1git init
-
Add all files to Git:
bash1git add .
-
Make your first commit:
bash1git commit -m "Initial Laravel project setup"
-
Create a new repository on GitHub:
- Go to github.com and log in
- Click the "+" icon in the top right and select "New repository"
- Name your repository (e.g., "my-laravel-app")
- Don't initialize with README, .gitignore, or license
- Click "Create repository"
-
Connect your local repository to GitHub:
bash1git remote add origin https://github.com/yourusername/my-laravel-app.git 2git branch -M main 3git push -u origin main
Step 4: Prepare Your Ubuntu VPS
-
Connect to your VPS via SSH:
bash1ssh username@your_server_ip
-
Update the system:
bash1sudo apt update && sudo apt upgrade -y
-
Install required packages:
bash1sudo apt install -y php php-cli php-fpm php-mbstring php-xml php-zip php-mysql php-curl unzip nginx mysql-server git
-
Install Composer:
bash1curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
-
Configure MySQL:
bash1sudo mysql_secure_installation
Create a database for your Laravel app:
bash1sudo mysql -u root -p 2CREATE DATABASE laravel_db; 3CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'your_password'; 4GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'localhost'; 5FLUSH PRIVILEGES; 6EXIT;
Step 5: Deploy Your Laravel App to the VPS
-
Create a directory for your app:
bash1sudo mkdir -p /var/www/my-laravel-app 2sudo chown -R $USER:$USER /var/www/my-laravel-app
-
Clone your repository from GitHub:
bash1cd /var/www 2git clone https://github.com/yourusername/my-laravel-app.git 3cd my-laravel-app
-
Install PHP dependencies:
bash1composer install --no-dev --optimize-autoloader
-
Set proper permissions:
bash1sudo chown -R www-data:www-data /var/www/my-laravel-app/storage 2sudo chown -R www-data:www-data /var/www/my-laravel-app/bootstrap/cache
-
Set up environment file:
bash1cp .env.example .env 2php artisan key:generate
-
Edit the .env file with your production settings:
bash1nano .env
Update database settings:
1DB_CONNECTION=mysql 2DB_HOST=127.0.0.1 3DB_PORT=3306 4DB_DATABASE=laravel_db 5DB_USERNAME=laravel_user 6DB_PASSWORD=your_password
-
Run migrations:
bash1php artisan migrate
Step 6: Configure Nginx
-
Create an Nginx server block:
bash1sudo nano /etc/nginx/sites-available/my-laravel-app
-
Add the following configuration:
nginx1server { 2 listen 80; 3 server_name your_domain.com www.your_domain.com; 4 root /var/www/my-laravel-app/public; 5 6 add_header X-Frame-Options "SAMEORIGIN"; 7 add_header X-Content-Type-Options "nosniff"; 8 9 index index.php; 10 11 charset utf-8; 12 13 location / { 14 try_files $uri $uri/ /index.php?$query_string; 15 } 16 17 location = /favicon.ico { access_log off; log_not_found off; } 18 location = /robots.txt { access_log off; log_not_found off; } 19 20 error_page 404 /index.php; 21 22 location ~ \.php$ { 23 fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; 24 fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 25 include fastcgi_params; 26 } 27 28 location ~ /\.(?!well-known).* { 29 deny all; 30 } 31}
Note: Replace
php8.1-fpm.sock
with your PHP version if different. -
Enable the site:
bash1sudo ln -s /etc/nginx/sites-available/my-laravel-app /etc/nginx/sites-enabled/ 2sudo nginx -t 3sudo systemctl restart nginx
Step 7: Set Up Continuous Deployment (Optional)
-
Create a deployment script on your VPS:
bash1nano /var/www/my-laravel-app/deploy.sh
-
Add the following content:
bash1#!/bin/bash 2cd /var/www/my-laravel-app 3git pull origin main 4composer install --no-dev --optimize-autoloader 5php artisan migrate --force 6php artisan config:cache 7php artisan route:cache 8php artisan view:cache 9sudo chown -R www-data:www-data /var/www/my-laravel-app/storage 10sudo chown -R www-data:www-data /var/www/my-laravel-app/bootstrap/cache
-
Make the script executable:
bash1chmod +x /var/www/my-laravel-app/deploy.sh
-
Run the script whenever you want to deploy updates:
bash1/var/www/my-laravel-app/deploy.sh
Step 8: Set Up SSL with Let's Encrypt (Recommended)
-
Install Certbot:
bash1sudo apt install certbot python3-certbot-nginx
-
Obtain and install SSL certificate:
bash1sudo certbot --nginx -d your_domain.com -d www.your_domain.com
-
Set up auto-renewal:
bash1sudo systemctl status certbot.timer
Your Laravel application should now be successfully deployed and accessible via your domain name with HTTPS!
