Skip to main content
See what's recently landed on the Neon backend: Object Storage, Functions, AI Gateway, and more
/ORMs/Laravel (Eloquent)

Connect from Laravel to Neon

Set up a Neon project in seconds and connect from a Laravel application

View as Markdown
Pre-built prompt for connecting Laravel to Lakebase Postgres

Laravel is a PHP web application framework. Connecting to Neon from Laravel is the same as connecting to any Postgres database from Laravel. Only the connection details differ.

To connect to Neon from Laravel:

  1. Create a Neon project

    If you do not have one already, create a Neon project.

    1. Navigate to the Projects page in the Neon Console.
    2. Click New Project.
    3. Specify your project settings and click Create Project.
  2. Configure the connection

    Open the .env file in your Laravel app and replace the database settings. New Laravel projects use DB_CONNECTION=sqlite with the other DB_* lines commented out; replace them with the following:

    DB_CONNECTION=pgsql
    DB_HOST=[neon_hostname]
    DB_PORT=5432
    DB_DATABASE=[dbname]
    DB_USERNAME=[user]
    DB_PASSWORD=[password]
    DB_SSLMODE=require

    If you have a connection string (postgresql://[user]:[password]@[neon_hostname]/[dbname]), copy its parts into the matching variables. The pooled hostname (with -pooler) works with these settings.

    You can find your database connection details by clicking the Connect button in the Console nav. For more information, see Connect from any application.

  3. Test the connection

    Run Laravel's default migrations against your Neon database, then show the connection details:

    php artisan migrate
    php artisan db:show

    db:show lists the Postgres version, your Neon host, and the tables the migrations created.

Connection issues

With older Postgres clients/drivers, including older PDO_PGSQL drivers, you may receive the following error when attempting to connect to Neon:

ERROR: The endpoint ID is not specified. Either upgrade the Postgres client library (libpq) for SNI support or pass the endpoint ID (the first part of the domain name) as a parameter: '&options=endpoint%3D'. See [https://neon.com/sni](/sni) for more information.

If you run into this error, see the following for an explanation of the issue and workarounds: The endpoint ID is not specified.

  • If using a connection string to connect to your database, try Workaround A. Pass the endpoint ID as an option. For example:

    postgresql://[user]:[password]@[neon_hostname]/[dbname]?options=endpoint%3D[endpoint_id]

    Replace [endpoint_id] with your compute's endpoint ID, which you can find in your Neon connection string. It looks similar to this: ep-cool-darkness-123456.

  • If using database connection parameters, as shown above, try Workaround D. Specify the endpoint ID in the password field. For example:

    DB_PASSWORD=endpoint=<endpoint_id>$<password>

Schema migration with Laravel

For schema migration with Laravel, see:

Next steps

Need help?

Join our Discord Server to ask questions or see what others are doing with Neon. For paid plan support options, see Support.

Last updated on

Was this page helpful?
Edit on GitHub