گفت‌و‌گوهای اخیر

برای مشاهده گفت‌و‌گوها وارد شوید.

User Account Dialog

Athena - Chat with AI

Login Dialog

Athena - Chat with AI

Claude 3.7 Sonnet

Claude 3.7 Sonnet

بازگشت
Claude 3.7 Sonnet

Claude 3.7 Sonnet

گفت‌وگوی مستقیم با مدل Claude-3.7-Sonnet، محصول Anthropic

۱۰ سکه برای هر پیام

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

Claude 3.7 SonnetCL
I want to develop a web app by laravel. tell me step by step. how to create it. initiate it on my mac. integrate it on github and deploy it on a ubunto vps

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

  1. Install Homebrew (if not already installed):

    bash
    1/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install PHP:

    bash
    1brew install php
  3. Install Composer (PHP dependency manager):

    bash
    1brew install composer
  4. Install Node.js and npm (for frontend assets):

    bash
    1brew install node
  5. Install Git (if not already installed):

    bash
    1brew install git

Step 2: Create a New Laravel Project

  1. Create a new Laravel project using Composer:

    bash
    1composer create-project laravel/laravel my-laravel-app
  2. Navigate to your project directory:

    bash
    1cd my-laravel-app
  3. Test your installation by starting Laravel's development server:

    bash
    1php artisan serve

    Visit http://localhost:8000 in your browser to see the Laravel welcome page.

Step 3: Initialize Git Repository and Connect to GitHub

  1. Initialize a Git repository:

    bash
    1git init
  2. Add all files to Git:

    bash
    1git add .
  3. Make your first commit:

    bash
    1git commit -m "Initial Laravel project setup"
  4. 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"
  5. Connect your local repository to GitHub:

    bash
    1git 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

  1. Connect to your VPS via SSH:

    bash
    1ssh username@your_server_ip
  2. Update the system:

    bash
    1sudo apt update && sudo apt upgrade -y
  3. Install required packages:

    bash
    1sudo apt install -y php php-cli php-fpm php-mbstring php-xml php-zip php-mysql php-curl unzip nginx mysql-server git
  4. Install Composer:

    bash
    1curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
  5. Configure MySQL:

    bash
    1sudo mysql_secure_installation

    Create a database for your Laravel app:

    bash
    1sudo 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

  1. Create a directory for your app:

    bash
    1sudo mkdir -p /var/www/my-laravel-app 2sudo chown -R $USER:$USER /var/www/my-laravel-app
  2. Clone your repository from GitHub:

    bash
    1cd /var/www 2git clone https://github.com/yourusername/my-laravel-app.git 3cd my-laravel-app
  3. Install PHP dependencies:

    bash
    1composer install --no-dev --optimize-autoloader
  4. Set proper permissions:

    bash
    1sudo 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
  5. Set up environment file:

    bash
    1cp .env.example .env 2php artisan key:generate
  6. Edit the .env file with your production settings:

    bash
    1nano .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
  7. Run migrations:

    bash
    1php artisan migrate

Step 6: Configure Nginx

  1. Create an Nginx server block:

    bash
    1sudo nano /etc/nginx/sites-available/my-laravel-app
  2. Add the following configuration:

    nginx
    1server { 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.

  3. Enable the site:

    bash
    1sudo 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)

  1. Create a deployment script on your VPS:

    bash
    1nano /var/www/my-laravel-app/deploy.sh
  2. Add the following content:

    bash
    1#!/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
  3. Make the script executable:

    bash
    1chmod +x /var/www/my-laravel-app/deploy.sh
  4. Run the script whenever you want to deploy updates:

    bash
    1/var/www/my-laravel-app/deploy.sh

Step 8: Set Up SSL with Let's Encrypt (Recommended)

  1. Install Certbot:

    bash
    1sudo apt install certbot python3-certbot-nginx
  2. Obtain and install SSL certificate:

    bash
    1sudo certbot --nginx -d your_domain.com -d www.your_domain.com
  3. Set up auto-renewal:

    bash
    1sudo systemctl status certbot.timer

Your Laravel application should now be successfully deployed and accessible via your domain name with HTTPS!

Claude 3.7 SonnetCL