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

如何为客户在本地主机部署已完成的Laravel项目

Hey there! No stress at all—setting up a Laravel project locally for the first time can feel a bit overwhelming, but let’s walk through this step by step, nice and easy. I’ll make sure every part makes sense:

第一步:先搞定本地环境

Laravel needs a few basic tools to run, so let’s confirm these are set up first:

  • Check PHP version: Laravel 9+ requires PHP 8.0 or higher. Open your terminal (CMD/PowerShell for Windows, Terminal for Mac/Linux) and run php -v to check your version. If it’s too low, I recommend installing XAMPP or WAMP—they come with pre-configured PHP, Apache, and MySQL, which is super beginner-friendly.
  • Install Composer: Composer is Laravel’s dependency manager. Run composer -V in your terminal to see if it’s installed. If not, grab the installer from the official Composer site, follow the wizard, and make sure to check the box that adds Composer to your system PATH (so you can use it anywhere in the terminal).
  • Prepare a database: XAMPP/WAMP includes MySQL. Start MySQL from their control panel, then open phpMyAdmin (usually at http://localhost/phpmyadmin). Create an empty database and note down its name, the username (default is root), and password (XAMPP defaults to blank, WAMP might be blank or root).
第二步:Handle the project files
  • Extract the project zip file your client gave you to a convenient location: If using XAMPP, put it in the htdocs folder (e.g., htdocs/your-client-project); if not using a pre-built server, just pick a folder you can easily find.
  • Copy the environment config file: There’s a .env.example file in the project root. Copy it and rename the copy to .env—this is Laravel’s core config file, and it’s required. You can do this via terminal:
    • Linux/Mac: cp .env.example .env
    • Windows CMD: copy .env.example .env
第三步:Configure environment variables

Open the .env file with an editor like VS Code or Notepad++, then update the database section to match the info you noted earlier:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your-database-name
DB_USERNAME=root
DB_PASSWORD=your-database-password (leave blank if there’s none)

Also, set the APP_URL to match your setup: If using Apache, use APP_URL=http://localhost/your-client-project; if using Laravel’s built-in server, use APP_URL=http://localhost:8000.

第四步:Install project dependencies

Go back to your terminal, navigate to the project root folder (e.g., cd htdocs/your-client-project), then run:
composer install
This will download all the PHP packages Laravel needs. It might take a few minutes the first time—if it’s slow, you can switch to a domestic mirror first by running composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/.

第五步:Generate an application key

Run this command in the terminal:
php artisan key:generate
This creates an encryption key for your app—Laravel can’t run without it, so this step is non-negotiable.

第六步:Sync the database structure

There are two ways to get your database set up:

  • Use Laravel migrations: Run php artisan migrate in the terminal—this will automatically create all the tables the project needs.
  • Import a database backup: If your client provided a SQL backup file, open phpMyAdmin, select your database, go to the "Import" tab, and upload the backup file. This is usually faster if the project already has existing data.
第七步:Start the project

Now you can launch the app with one of these options:

  • Laravel’s built-in development server: Run php artisan serve in the terminal. Once it says "Server running on http://localhost:8000", open that URL in your browser.
  • Apache/Nginx (XAMPP/WAMP): Make sure Apache is running in your XAMPP/WAMP control panel, then visit http://localhost/your-client-project directly in your browser.
Quick fixes for common issues
  • Permission errors: If you get errors about the storage or bootstrap/cache folders, run chmod -R 775 storage bootstrap/cache on Linux/Mac. For Windows, right-click those folders, go to Properties > Security, and give "Everyone" read/write permissions.
  • Missing PHP extensions: If Composer complains about missing extensions (like fileinfo or mbstring), open your php.ini file (found in XAMPP/WAMP’s PHP folder), remove the semicolon ; from the start of the extension line, then restart Apache.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 09:41:52