For Laravel beginners, the right local development server is the one that points its document root to the project’s public folder, starts PHP and database services together, and matches your app’s PHP version. If that setup is wrong, routes break, assets fail, migrations miss the database, and debugging becomes guesswork. This guide covers local server choices, correct document root setup, database connection, and the daily edit-run-migrate-debug workflow.

What you'll need

  • PHP 8.1 or newer.
  • Composer, the PHP dependency manager, to create or install the project.
  • Laravel project files, either from a fresh create-project install or a cloned repository.
  • A local database engine, usually MySQL, though SQLite can work for quick local setup.
  • Node.js and npm if the project uses Vite assets.
  • A local web server path: php artisan serve, or Apache/Nginx through XAMPP, WAMP, MAMP, or a similar stack.
  • phpMyAdmin if you want browser-based database creation for MySQL.

How do you start a new Laravel project?

Use Composer to create the project, then choose between Laravel’s built-in server and a full Apache or Nginx stack. A fresh install usually needs dependency installation, an .env file, an app key, and database setup before the first route or migration works cleanly.

Fresh install workflow

  1. Create the project. Run composer create-project laravel/laravel example-app from the directory where you keep projects. Composer must be installed first, and Laravel can also be installed with laravel new if that installer is already available.
  2. Open the project root. Move into the new folder and point your editor there. The web server should later point to public/, not the project root, because Laravel’s front controller lives at public/index.php.
  3. Copy the environment file. Duplicate .env.example to .env. Laravel stores secret database passwords in .env, and that file should never be uploaded to the public internet.
  4. Install Node and dependencies. If the app uses Vite assets, run npm install and then npm run dev. Node.js is needed here because CSS and JavaScript compilation is part of the local workflow, not an extra later step.
  5. Start the server. Run php artisan serve. The default local Laravel URL shown is http://127.0.0.1:8000, so open that address unless the command output says otherwise.

Say your project opens at 127.0.0.1:8000 but asset requests return 404. That usually means the Vite build step was skipped, not that Laravel routing is broken. Start the Vite dev server, then refresh the page and check the browser console.

What should I do after cloning a Laravel project locally?

After cloning, install PHP dependencies first, then copy the environment file, then generate or confirm the app key, then configure the database and assets. A cloned repo often fails because the environment file is missing, dependencies are incomplete, or the database credentials still point at the old machine.

Cloned repo workflow

  1. Install PHP packages. Run composer install in the project root. This restores the dependencies listed in composer.json and is the first step after cloning.
  2. Create the local .env. Copy .env.example to .env, then fill in DB_DATABASE, DB_USERNAME, and DB_PASSWORD. If the app uses MySQL, create the database first in phpMyAdmin or MySQL.
  3. Generate the app key. Run php artisan key:generate. Many first-run 500 errors come from a missing or stale application key after cloning.
  4. Run database setup. Use php artisan migrate if the project expects tables on first launch. If the project uses seeds, run the seed command listed in that repo’s README or deployment notes.
  5. Build or watch assets. Run npm install and npm run dev when the app uses Vite. If the project is purely server-rendered, this step may not be needed.

Suppose a cloned project shows a login page, but CSS is plain text and buttons are unstyled. That is often a missing Vite build, not an Apache problem. Run the asset command, then confirm the browser loads the Vite output without 404s.

Do you need Apache or Nginx?

No, not for every local project. php artisan serve is enough for many beginners, but Apache or Nginx is a better fit when you want the local setup to behave more like production, especially for clean URLs, custom virtual hosts, or shared stacks such as XAMPP.

Apache setup basics

Apache needs rewrite support so Laravel can route requests through public/index.php. Turn on mod_rewrite, and set the document root to the project’s public/ folder. If the stack uses .htaccess, it must be allowed to run in that directory.

A minimal Apache virtual host points to something like /path/to/project/public and keeps rewrite handling enabled. If the browser shows directory listings or raw file paths, the root is probably pointing at the project folder instead of public/.

Nginx setup basics

Nginx should route missing files through index.php with try_files. A common pattern is try_files $uri $uri/ /index.php?$query_string; with the root set to the project’s public/ directory. That makes Laravel’s router handle the request.

If Nginx is serving a 404 for a route that exists in Laravel, the server block usually needs a try_files rule. That is a web server rewrite issue, not a controller issue.

When php artisan serve is enough

Use php artisan serve when you want the fastest path to a local app and do not need Apache-specific or Nginx-specific behavior. It is a built-in local development server, and it avoids extra server configuration while you are learning routes, controllers, views, and migrations.

Where should the Laravel public folder point on local server setup?

The document root should point to the project’s public/ directory, not the project root. Laravel’s front controller is public/index.php, so pointing the server one level too high usually causes rewrite failures, broken assets, or exposed application files.

For Apache, set the virtual host document root to /path/to/project/public. For Nginx, set root to the same folder. If the local server points at the top-level project folder, the app may load inconsistently or fail to route clean URLs.

How do I configure the.env file for local database access?

Edit the copied .env file with the database name, username, and password used on your machine. Laravel reads environment config from .env, and database credentials belong there, not in public files. MySQL is common for local Laravel work, but SQLite is also a valid quick-start choice.

Local database values

  1. Create the database. In phpMyAdmin, open localhost/phpmyadmin and create a database name that matches the one you plan to use in DB_DATABASE.
  2. Set the connection values. In .env, fill in DB_CONNECTION, DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, and DB_PASSWORD. Keep the values aligned with your local MySQL account.
  3. Clear cached config. Run php artisan config:clear after editing .env. Laravel may still read cached settings until that cache is cleared.

A common first-timer mistake is changing .env but leaving an old database name in the cached config. The app still points at the wrong database, and migration or login errors follow until the cache is cleared.

Local setup checklist

Step Exact command or setting Expected result Common failure signal
Fresh install composer create-project laravel/laravel example-app New Laravel project folder is created Composer error about PHP version or missing extensions
Cloned repo composer install Vendor packages are installed locally Missing classes, autoload errors, or dependency failures
Environment file Copy .env.example to .env Local config file exists for the app App key or database settings not found
App key php artisan key:generate APP_KEY is filled in 500 error on first load, encryption or session problems
Local server php artisan serve App opens at http://127.0.0.1:8000 Connection refused or wrong port in the browser
Apache/Nginx root path Document root or root points to public/ Routes and assets resolve through Laravel 404s on valid routes or exposed project files
.env database mismatch Match DB_DATABASE, DB_USERNAME, DB_PASSWORD Laravel connects to the intended local database SQLSTATE errors, access denied, or empty result sets
Missing Vite assets npm install then npm run dev CSS and JS load from the Vite dev server 404s for asset files or unstyled pages

Why is the app showing errors?

A 500 error usually means Laravel hit a server-side problem, while missing CSS or JS usually means the asset pipeline or web root is wrong. The fastest fix is to separate the symptom from the root cause: check logs for 500s, check Vite output for asset problems, and check the database settings for SQL errors.

500 errors and log checks

  1. Read the error log. Open storage/logs/laravel.log first. The stack trace often points directly to a missing key, bad config value, or database connection failure.
  2. Clear Laravel cache. Run php artisan config:clear, then php artisan cache:clear if needed. Cached config can keep old .env values alive.
  3. Check the app key. Run php artisan key:generate if the key is blank or the repo was cloned without a valid .env. That is a common first-run fix.

Asset 404s and Vite output

  1. Start the asset server. Run npm run dev from the project root when the app uses Vite. Without that process, the browser may request files that never get served.
  2. Check the page source. Confirm the page is requesting the Vite dev endpoint or built asset files. If not, the layout may be missing the Vite directives used by the app.
  3. Rebuild if needed. Run npm install again if packages are missing, then restart npm run dev. Asset errors often follow an incomplete Node setup.

Database mismatch and config cache

  1. Verify the database name. Compare the database shown in phpMyAdmin with DB_DATABASE in .env. The names must match exactly.
  2. Confirm the connection user. Check DB_USERNAME and DB_PASSWORD against your local MySQL account. A wrong user or password often produces access-denied errors.
  3. Refresh the cached config. Run php artisan config:clear after any database change. If migrations still fail, rerun php artisan migrate.

Picture a route that works in php artisan serve but fails on Apache with a 404. That points to rewrite or document-root configuration, not Laravel routes. Check the virtual host path and confirm that Apache is serving public/ with mod_rewrite enabled.

Common mistakes

  • Pointing the server at the project root instead of public/.
  • Skipping composer install after cloning.
  • Editing .env but forgetting php artisan config:clear.
  • Running Laravel without the Vite dev server when the app expects assets from Node.
  • Using MySQL credentials that do not match the local account.
  • Expecting Apache or Nginx rewrite behavior while the stack does not load Laravel’s front controller.

Keep reading

Frequently asked questions

How do I set up a Laravel project on my local development server?

Install PHP 8.1 or higher, Composer, and a database, then create the project with composer create-project laravel/laravel example-app or install a cloned repo with composer install. Set .env, point the web root to public/, and run php artisan serve or a local Apache or Nginx stack.

Do I need Apache or Nginx to run Laravel locally?

Use Apache or Nginx when you need clean URLs, production-like routing, or a shared stack such as XAMPP with public/ as the document root.

What command starts a Laravel local server?

Run php artisan serve. If the port is already in use, rerun the command with a different port and open the new address shown in the terminal.

Why is my Laravel local app not loading CSS or JS?

Most often, the Vite dev server is not running or the project’s asset commands were skipped. Run npm install and npm run dev, then refresh the page. If the app still loads plain HTML, check that the layout includes the project’s Vite asset directives.

How do I fix a 500 error on a local Laravel setup?

Open storage/logs/laravel.log, run php artisan config:clear, and verify the .env values first. If the error started after cloning, also check php artisan key:generate and database credentials. That sequence catches the most common local causes without guessing.