You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Bitbucket Pipeline将Laravel项目部署至无Composer的共享主机?

Yes, this approach works perfectly!

You absolutely can build your full Laravel project in Bitbucket Pipelines (handling all dependencies, migrations, and asset compilation there) then deploy the ready-to-run code to your server via git-ftp—this is actually a great solution for servers that don't have Composer, Node.js, or other build tools installed. Let's fix up your pipeline configuration and cover key details to make this work smoothly.

First, adjust your bitbucket-pipelines.yml

Here's a refined version of your config with critical fixes and improvements:

image: php:7.2-fpm
pipelines:
  branches:
    master:
      - step:
          caches:
            - composer
            - node
          script:
            # Install system dependencies (including git-ftp upfront)
            - apt-get update && apt-get install -y unzip gnupg ssh git-ftp
            # Install Composer globally
            - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
            # Install required PHP extensions for Laravel (critical missing step!)
            - docker-php-ext-install mbstring pdo_mysql
            # Install Laravel dependencies for production (skip dev packages)
            - composer install --no-dev --optimize-autoloader
            # Set up Node.js and compile frontend assets
            - curl -sL https://deb.nodesource.com/setup_8.x | bash -
            - apt-get install -y nodejs
            - npm install
            - npm run production
            # Configure environment file
            - php -r "file_exists('.env') || copy('.env.pipelines', '.env');"
            - php artisan key:generate
            # Run database migrations (force to avoid interactive prompts)
            - php artisan migrate --force
            # Deploy via git-ftp: use "init" for first deploy, switch to "push" afterward
            # --all ensures we upload ignored files like vendor/ and compiled assets
            - git ftp init --user $FTP_USERNAME --passwd $FTP_PASSWORD --all $FTP_HOST_PATH

Key notes to avoid pitfalls:

  • PHP Extensions: Your original config was missing Laravel-required extensions like pdo_mysql and mbstring—without these, Composer and Artisan commands will fail. The docker-php-ext-install line fixes this.
  • git-ftp --all Flag: By default, git-ftp follows your .gitignore rules, which exclude critical directories like vendor/ and compiled frontend assets. The --all flag overrides this to upload every file from your built project.
  • Migrate with --force: Production migrations require the --force flag to skip the interactive confirmation prompt (Pipelines can't respond to user input). Important: Ensure your Pipeline can access your database—if your DB is locked down to server-only access, you may need to whitelist Bitbucket's IPs or use an SSH tunnel to connect.
  • First Deploy vs. Subsequent Deploys: Use git ftp init only for your first deployment (it uploads all files). After that, replace it with git ftp push to only upload changed files—this is much faster.
  • Cache Optimization: Added the node cache to speed up repeated npm install runs, just like the existing composer cache.

Additional critical tips:

  1. Secure Environment Variables: Don't hardcode sensitive values (like DB passwords) in .env.pipelines. Instead, use placeholders (e.g., DB_PASSWORD=${DB_PROD_PASSWORD}) and add these variables to your Bitbucket repo's Settings > Repository Variables—they'll automatically inject into the Pipeline.
  2. Server File Permissions: After deployment, make sure your server's storage/ and bootstrap/cache/ directories have write permissions. You can add a command to the Pipeline (before deploy) like chmod -R 775 storage bootstrap/cache, or set permissions manually on the server.
  3. Backup First: Before your first deploy, back up all existing files on your server to avoid accidental data loss.

内容的提问来源于stack exchange,提问作者Tomjesch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:30:00