Skip to content

How to Connect Your Own Domain to a Laravel App

A practical walk-through for pointing a custom domain at a Laravel app, from DNS records and the public folder to APP_URL, proxy settings and troubleshooting.

10 min readUpdated Nov 27, 2026By XPASS Editorial Team

How to Connect Your Own Domain to a Laravel App

Getting a Laravel application running on a developer machine is the easy part. Getting a real domain name to reach it, with the right address in every link and the right certificate on the connection, is where many first deployments stall. The steps are not difficult, but they involve three separate places: the domain registrar or DNS host, the server that runs the web server and PHP, and the Laravel configuration itself. A mistake in any one of them produces a similar symptom, a page that does not load or loads the wrong thing.

This guide walks through the whole path in the order you would actually do it. It assumes you already have a Laravel project that works and a server or hosting account that can run PHP. If you have not registered a name yet, the domains page shows what is available. If you build with other frameworks too, the same ideas appear in connecting a domain to React, in connecting a domain to Astro and in connecting a domain to Next.js, each with its own build and hosting details.

What you need before you start

Gather four things before touching any setting. First, the domain itself, with access to its DNS management screen. This may be at the registrar or at a separate DNS provider if you have delegated the name servers elsewhere. Second, the public address of the server. For a virtual private server this is a fixed IPv4 address, and sometimes an IPv6 address as well. For managed hosting it may be a hostname instead. Third, shell or panel access to the server, so that you can edit the web server configuration. Fourth, the Laravel project already deployed to a folder on that server, with dependencies installed.

It also helps to decide the final form of the address in advance. Choose whether visitors should land on the bare domain (example.com) or on the www form (www.example.com), and plan for the other one to redirect to it. Search engines and browsers treat the two as different sites, so picking one canonical address and sticking to it avoids duplicate pages and confusing cookie behaviour.

Finally, think about timing. DNS answers are cached for as long as the record's TTL (time to live) allows. If the domain currently serves something important, lower the TTL on the old records a day ahead so that the switch takes effect quickly. For a brand new domain there is nothing cached yet and the change is usually visible almost at once.

How a domain reaches a Laravel app

It helps to picture the chain, because every failure sits at one link of it.

  1. A visitor types your domain. Their device asks a DNS resolver for the address behind that name, a process described in RFC 1034 and summarised in plain language in Cloudflare's DNS overview.
  2. The resolver follows the name servers for your domain and gets back the IP address you entered in your records.
  3. The browser opens a connection to that IP address on port 80 or 443 and sends a request that includes the domain name in the Host header.
  4. The web server (Nginx or Apache, most often) looks at the Host header, picks the matching site configuration and hands PHP requests to PHP-FPM.
  5. Laravel receives the request through its public/index.php entry file, routes it and returns a response.

Notice that DNS only does step 2. It tells the world which machine to contact. It does not tell that machine which project to serve. That is the job of the web server configuration in step 4, and forgetting it is the most common reason a freshly pointed domain shows a default welcome page instead of your application.

Step 1: Add the DNS records

Open the DNS management screen for your domain and add records that point at the server. The table shows the usual choices.

Situation Record for the root domain Record for www
Server with a fixed IPv4 address A record with the IPv4 address CNAME pointing to the root domain, or a second A record
Server that also has IPv6 Add an AAAA record with the IPv6 address next to the A record Same pattern, with AAAA if needed
Host gave you a hostname instead of an IP Use the host's instructions; many DNS providers offer an ALIAS or flattened CNAME for the root CNAME to the hostname

A few rules keep this tidy. A CNAME cannot sit at the root of a domain alongside the other records the root needs, such as those for mail, so the root normally gets an A record. Do not add an AAAA record unless the server really answers on that IPv6 address, because visitors whose networks prefer IPv6 will otherwise reach a dead end. Remove any leftover records from a parking page or a previous host, since two competing A records will send some visitors to the wrong machine.

Keep the TTL moderate while you are setting up, then raise it later if you want fewer lookups. After saving, you can confirm what the world sees with a command such as dig example.com A or nslookup, or with any online DNS lookup tool. If the answer still shows the old address, wait for the previous TTL to expire rather than editing again; repeated edits do not speed anything up.

Step 2: Tell the web server about the domain

Now make the server recognise the name. On Nginx, create a server block for the domain. The important lines are server_name, which lists example.com and www.example.com, and root, which must point to the public folder inside your Laravel project, for example /var/www/myapp/public. The location block should try the requested file first and fall back to index.php so that Laravel handles all other URLs. A separate location block passes .php files to PHP-FPM through its socket.

On Apache, the equivalent is a virtual host with ServerName and ServerAlias entries and a DocumentRoot set to the same public folder, with AllowOverride enabled so that the .htaccess file shipped with Laravel can rewrite requests to index.php. On hosting panels such as Plesk or cPanel, you add the domain in the panel and change its document root setting to the public folder, because the default is usually the account's top folder.

Two warnings apply here. Never set the document root to the project's top folder. That folder contains the .env file, your source code and the vendor directory, and exposing it can leak secrets. Only the public folder should be reachable from the web. Also check file ownership and permissions: the user that runs PHP must be able to write to the storage and bootstrap/cache folders, or Laravel will show a generic server error even though DNS and the web server are fine.

After editing, test the configuration (nginx -t on Nginx, apachectl configtest on Apache), reload the service, and request the domain in a browser or with curl. If you see your application, the connection is working over plain HTTP.

Step 3: Update the Laravel configuration

Laravel keeps environment-specific values in the .env file. A few of them depend on the domain.

  • APP_URL should be the final public address, including the scheme, for example https://example.com. Laravel uses it when building absolute links outside a browser request: emails, queued notifications, scheduled commands and the URL helper in the console.
  • APP_ENV and APP_DEBUG should be set to production and false on a live site. Debug pages can reveal paths and configuration to anyone who triggers an error.
  • SESSION_DOMAIN is only needed if you share cookies across subdomains. Leave it unset for a single site, and if you set it, use a leading dot only when you really want subdomains to share the session.
  • Mail settings such as the from address should use your own domain once mail is configured for it.

After changing .env, run php artisan config:clear, or rebuild the cache with php artisan config:cache if you use cached configuration in production. Forgetting this step is a classic cause of links that still show the old address or localhost.

If the application sits behind a load balancer, a CDN or a reverse proxy that terminates HTTPS, Laravel will see the internal connection rather than the visitor's. In that case configure trusted proxies so that Laravel reads the forwarded scheme and host headers correctly. Without it, generated links may use http even though visitors arrived over https, which leads to mixed content warnings. The framework documentation for your version explains the trusted proxy setting.

Step 4: Add HTTPS and handle www

Modern browsers expect HTTPS, and many features such as secure cookies depend on it. A certificate proves that the server is entitled to answer for your domain and encrypts the connection. Automated certificates are available through the ACME protocol, as explained in Let's Encrypt's overview, and commercial certificates are another route; the SSL page explains the options a provider offers. Whichever you choose, the sequence is the same: DNS must already point at the server, the web server must answer for the domain on port 80, then the certificate is issued and installed on port 443.

Once HTTPS works, add a redirect from HTTP to HTTPS, and from the non-canonical host to the canonical one. In Nginx this is a small server block listening on port 80 that returns a permanent redirect to the https address. Test both variants of the address (with and without www, with and without https) and confirm that each ends on the single address you chose. Then confirm that Laravel's generated links match, using a page that prints a route URL, or by viewing the page source.

If your project will also send email from the domain, plan that now rather than later. Adding the right records for mail is separate from web hosting, and the business email page covers that product. Keep the web records and mail records in the same DNS zone, and avoid deleting mail records while cleaning up old web entries.

Checking and troubleshooting

When something fails, work down the chain from DNS to application instead of guessing. The table lists common symptoms and the first place to look.

Symptom Likely cause What to check
Browser says the site cannot be found DNS record missing or not yet propagated Query the record with dig or an online lookup tool; check you edited the right zone
Browser connects but shows a default server page No matching virtual host or wrong document root server_name or ServerName and the root path
403 or directory listing Document root points to the wrong folder, or index file missing Root should end in public; index.php must exist
404 on every page except the home page Rewrite rules missing try_files in Nginx, or AllowOverride and mod_rewrite in Apache
500 error PHP error, missing .env, wrong permissions on storage Laravel log in storage/logs and the web server error log
Certificate warning Certificate issued for a different name, or expired Names covered by the certificate, including www
Links point to localhost or http Old APP_URL, cached config, or missing trusted proxy setting .env value, config:clear, proxy configuration

Two habits save a lot of time. Read the Laravel log and the web server error log before changing anything, because they usually name the exact problem. And change one thing at a time, testing after each change, so that you know which edit fixed or broke the site.

Limits and what to watch for

Pointing a domain is simple in principle but has edges worth knowing about.

  • Propagation is not instant everywhere. Different resolvers cache differently. A result you see on your laptop may differ from what a colleague sees for a while. Do not keep editing records in response; wait and recheck.
  • Shared hosting may restrict the web root. Some plans do not let you change the document root. In that case you may need to place the public folder contents in the allowed folder and adjust paths in index.php, or use a plan that supports modern PHP application layouts. Check the plan page of your host for what is supported.
  • Email and web records share a zone. Deleting or overwriting a record while fixing the website can silently break mail. Review the whole zone before saving large changes.
  • Environment files are secrets. Never commit .env to a public repository, and never leave a backup copy of it inside the public folder.
  • Renewals matter. If the domain expires, the site disappears along with any email on it. Turn on renewal reminders and keep the contact details on the registration current.
  • Staging is worth having. A subdomain such as staging.example.com lets you test deployments with the same configuration before touching the live address.

Summary

Connecting your own domain to a Laravel app comes down to four aligned pieces. DNS records send visitors to the right machine. The web server recognises the domain and serves only the public folder. The Laravel environment uses the final address in APP_URL and trusts the proxy in front of it if there is one. HTTPS and one canonical address finish the job. When something breaks, walk the chain from DNS to the server to Laravel and read the logs before changing settings.

When you are ready to register or manage a name for your project, the domains page is the place to look at what is available and how it works.

Frequently asked questions

Which DNS record do I need to point a domain at my Laravel server?

For a server with a fixed IPv4 address you normally add an A record for the root domain and either an A record or a CNAME for www. If your host gave you a hostname instead of an IP address, use a CNAME for the www name and ask the host how to handle the root domain.

Why does my domain show the default web server page instead of Laravel?

The web server is usually answering with its default site because no virtual host matches your domain name, or because the document root does not point to the public folder of the Laravel project. Check the server name and the root path in the web server configuration.

Do I need to change APP_URL after connecting a domain?

Yes. Set APP_URL in the environment file to the final address, including https, and clear the configuration cache. Laravel uses it for generated links in queued jobs, emails and console commands.

How long does it take for the domain to start working?

Most changes are visible within minutes, but caches can keep the old answer until the TTL of the old record runs out. Lowering the TTL a day before a planned change shortens the waiting time.

About the author

Bob Kanokphon Thongdee, founder of XPASS VPN

Bob Kanokphon Thongdee

  • Founder of XPASS VPN
  • Co-founder of eSIMonline.asia
  • More than 7 years in online marketing
  • Founder of Cojourney Visa and Cojourney Travel

Start your website the right way

Register a domain, add SSL and set up business email from one place.

.com registration from $18.81 for the first year

Start with a domain

Keep reading

Website Guides

How to Connect Your Own Domain to a React App

A step-by-step guide to putting a React app on your own domain, covering hosting, DNS records, HTTPS, routing fallbacks and email safety.

10 min read

Website Guides

How to Connect Your Own Domain to an Astro Site

A practical guide to connecting a custom domain to an Astro project, covering static and server builds, DNS records, the site setting and common problems.

10 min read

Website Guides

How to Connect Your Own Domain to a Next.js Site

A practical walk-through for pointing a custom domain at a Next.js app, from adding the domain on your host to DNS records, HTTPS and redirects.

10 min read