The essential news about content management systems and mobile technology. Powered by Perfect Publisher and XT Search for Algolia.
The News Site publishes posts to the following channels: Facebook, Instagram, Twitter, Telegram, Web Push, Tumblr, and Blogger.
The recent announcements at LaraconUS have sparked a renewed interest in cloud-based deployments within the Laravel community. As the debate continues on how to deploy your apps, one thing is clear: the cloud is becoming a more viable option for Laravel users.
In this article, we'll explore how to prepare your Laravel app for deployment in a cloud environment using FrankenPHP, Caddy, Dockerfiles, and finally deploying it to Sevalla.
So where do we start? In the local environment of course! đ¤
For the sake of simplicity, we'll assume you have a fresh Laravel app installed on your local machine, which connects to a PostgreSQL database to read/write some data.
Before we move on, make sure you have a .env
file
in your project root with the following content:
.env
:
...
DB_CONNECTION=pgsql
...
Once that's verified, we can start building. đ¤ âď¸
It's always a good idea to have a local development environment that closely resembles your production environment. This way, you can catch any issues early on and avoid surprises when you deploy your app in production.
To mimic the production setup we're going to use, we'll rely on Docker and Docker Compose. If you don't have Docker installed on your machine, you can download it from the official website.
First off, create a new file called compose.yml
in
the root of your Laravel project and add the following content:
compose.yml
:
services:
php:
image: dunglas/frankenphp:php8.3-alpine
command: php artisan serve --host 0.0.0.0 --port 8080
ports:
- 8080:8080
volumes:
- .:/app
This configuration file defines a service called
php
that uses the
dunglas/frankenphp:php8.3-alpine
image, which is a
lightweight FrankenPHP image that includes necessary extensions to
run a Laravel app. We also expose port 8080
to access
the app from the host machine.
To test your configuration, try running the following command in your terminal:
docker compose up [-d]
You should see a Laravel error page explaining the connection
was not established to the database because of a missing driver
when you navigate to https://0.0.0.0:8080
in your
browser. This is expected as we haven't connected our Laravel app
to a database yet.
Awesome, so far we've configured our Laravel app to be served by
a FrankenPHP runtime running php artisan serve
.
Next, let's connect our local app with a PostgreSQL database!
To connect your Laravel app to a PostgreSQL database, we'll need to do a couple of things.
First, we need to set the following environment variables in
your .env
file:
.env
:
...
DB_CONNECTION=pgsql
DB_HOST=db
DB_PORT=5432 # default PostgreSQL port
DB_DATABASE=main
DB_USERNAME=admin
DB_PASSWORD=password
Following that, you'll need to add new services to your
compose.yml
file, and create a custom
Dockerfile
for your dev environment. Create and update
the files with the following content:
Dockerfile.dev
:
FROM dunglas/frankenphp:php8.3-alpine
RUN install-php-extensions pdo_pgsql
Dockerfile.dev
is only meant to be used by your
local/development environment, and it extends the
dunglas/frankenphp:php8.3-alpine
image to include the
pdo_pgsql
extension, which is required to connect to a
PostgreSQL database.
compose.yml
:
services:
init:
build:
dockerfile: Dockerfile.dev
command: php artisan migrate
depends_on:
db:
condition: service_healthy
volumes:
- .:/app
php:
build:
context: .
dockerfile: Dockerfile.dev
command: php artisan serve --host 0.0.0.0 --port 8080
ports:
- 8080:8080
depends_on:
init:
condition: service_completed_successfully
volumes:
- .:/app
db:
image: postgres:16.4-alpine
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: password
POSTGRES_DB: main
volumes:
- /var/lib/postgresql/data
healthcheck:
test: pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB
interval: 1s
There is a lot going on here, let's take a look at what has changed and why:
php
service to use a custom
Dockerfile called Dockerfile.dev
to build a new image
that includes the necessary extensions to connect to a PostgreSQL
database.db
that uses the
postgres:16.4-alpine
image to run a PostgreSQL
database. We've also defined some environment variables to set up
the database user, password, and database name.db_data
to
persist the data in the database on your machine, and Docker could
reuse it when you restart the services.init
was also added that
reuses Dockerfile.dev
. This image is used to run the
php artisan migrate
command to run your database
migrations. The depends_on
key ensures that the
db
service is up and running before the migrations are
run.php
service now depends on the
init
service to ensure that the database migrations
are run before the Laravel app starts.db
service to
ensure that the PostgreSQL database is up and running before the
init
service runs the migrations.To test your configuration, run the following command in your terminal:
docker compose up --build
Your application should now be connecting to your PostgreSQL database, and your database migrations are always run. đ
Your local envnironment is now ready to mimic your production environment. You can now develop your app locally and test a really similar setup you'll use in production.
It's time to make the necessary changes for your production environment.
The first step is to tell Docker which directories it can safely
ignore when building the production image. Create a new file called
.dockerignore
in the root of your Laravel project and
add the following content:
.dockerignore
:
vendor
bootstrap/chache/*
tests
This file tells Docker to ignore the vendor
,
bootstrap/cache
, and tests
directories.
Then, create a Dockerfile
that will be used to
build your production image:
Dockerfile
:
FROM dunglas/frankenphp:php8.3-alpine
ENV SERVER_NAME=":8080"
RUN install-php-extensions @composer pdo_pgsql
WORKDIR /app
COPY . .
RUN composer install \
--ignore-platform-reqs \
--optimize-autoloader \
--prefer-dist \
--no-interaction \
--no-progress \
--no-scripts
This Dockerfile
is similar to the
Dockerfile.dev
we created earlier, but it includes a
few additional steps:
SERVER_NAME
environment variable to
:8080
to instruct Caddy to listen on port
8080
.@composer
PHP extension to install
Composer in the image.composer install
command is run to install the
dependencies of your Laravel app./app
and copied
the contents of your Laravel app to the image.To test your changes in your local environment, you'll need to produce a production build of your app. Run the following command in your terminal:
docker build -t my-laravel-app .
This command builds a new Docker image called
my-laravel-app
based on the Dockerfile
in
the current directory.
To test your newly built production image, use the following command:
docker run -p 8080:8080 -e APP_KEY=<your-app-key> my-laravel-app
Replace <your-app-key>
with the value of the
APP_KEY
environment variable in your .env
file or grab a key from here.
Visit 0.0.0.0:8080 in your browser, and your app should start in production mode. It may error due to the lack of a database connection, but that's expected.
Now that you have a production-ready Docker image, you can deploy it to a cloud provider. đ
In this tutorial, we'll use Sevalla, a new cloud provider that offers a
simple way to deploy Dockerfile
-based deployments.
As your app depends on a PostgreSQL database, you're better off provisioning a new PostgreSQL database on Sevalla first. Once you're logged in the Sevalla dashboard,
Once your database is ready, you can create your Laravel app on Sevalla.
APP_KEY
environment variable required by
LaravelDockerfile
as build typeIf your app is ready, you can now connect it with your PostgreSQL database.
Then, set the following environment variables in the "Environment variables" tab with your database's connection details:
DB_CONNECTION
DB_HOST
DB_PORT
DB_DATABASE
DB_USERNAME
DB_PASSWORD
We recommned using the internal network address of your database
as the DB_HOST
value. This way, your app can connect
to the database over a private network.
The last step is to set up a Job process for your application to run the database mirgations before starting the app.
php artisan migrate
--force
If this is also done, you can now initiate a manual deployment of your app in the Deployments tab. đ
If all went well, congrats! You've successfully prepared your Laravel app for the cloud. đ
In this article, we've explored:
docker compose
.By following these steps, you can take your Laravel app to new heights and enjoy the benefits of cloud-based deployments. đ¤
The post Prepare your Laravel app for the cloud appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/prepare-your-laravel-app-for-the-cloud
Prezet is a new Laravel Blogging app from Ben Bjurstrom that transforms markdown files into SEO-friendly blogs, articles, and documentation!
If you want to learn more about Prezet check out this Laravel News creator series interview we did.
<iframe width="1238" height="696" src="https://www.youtube.com/embed/GCsRyzwNqM8" title="Prezet: Laravel Markdown Blogging with Ben Bjurstrom" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>One of the differences between other solutions is Prezet is designed to run with your existing Laravel apps. This way you get the following features all for free:
Unified Deployment: Content and Laravel applications coexist in a single codebase with a unified deployment process.
Familiar Environment: Leverages existing Laravel and Blade knowledge, eliminating the need to learn new frameworks.
Seamless Integration: Allows easy incorporation of dynamic features within the Laravel framework. For example, need a mailing list signup in your blog? It's just another Laravel route:
Getting started with Prezet is simple and all you need to do is run these steps:
composer require benbjurstrom/prezet
php artisan prezet:install
php artisan serve
php artisan prezet:index
Of course, the installation guide has a full breakdown of what all these commands do and why they are needed.
Check out Prezet today if you are looking for a markdown friendly blogging app.
The post Prezet: Markdown Blogging for Laravel appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/prezet
John Kostak has been building websites for longer than most social media networks have even been around. So splashy features donât interest him muchâheâs far more into performance, reliability, and compatibility. Which is why he and his company, Web Development USA, have been using WordPress.com from the start.
In this fun Q&A, John shares more about his WordPress journey, what matters most to him as a developer, and a few of his favorite sites (in spite of the fact that it was like making him pick his favorite child). Note: The interview has been edited for clarity and length.
If Johnâs love for WordPress.com has you reconsidering your current hosting environment, you can learn more about our specs and get started at WordPress.com/hosting.
Jeremy: How long have you been using WordPress and WordPress.com?
John: I have been building websites for about 15 or 16 years and started in a corporate environment for a large company. We never had an internal digital team and we basically created our own digital agency within this big corporate company. And that was pretty innovative back then.
Then out of that, I spun off and started Web Development USA. That began in 2015, and so next year will be our 10th year, which is crazy to think about. But it went quickly because we really do enjoy this. And we look for people who find this to be a passion, as we do.
Jeremy: Have you been using WordPress.com the entire time?
John: Yes we have. We started doing some testing with SiteGround and Elementor hosting, but we still like WordPress.com the best. You know you can go through a McDonaldâs three miles away or 10,000 miles away on the other side of the planet and your lunch is going to be reasonably what you expect. Thatâs what WordPress.com feels like with its consistency and the familiarity of the UI and getting around.
Jeremy: What do you like most about WordPress.com? Is it about ease of use on your side as a builder? Convenience for the customer? Both?
John: Resiliency. With Jetpack at the core and all the updates that it does, we just donât have that much of a risk of things exploding, especially when we bring contractors in and out. We can always fall back to a previous state, and we have an exact record of it. We can get into PHP code. We can get into the very, very back end if we want. We can really be dangerous if we want, without being too afraid of it.
Overall, it is certainly the all-around performance, security, and cadence that you use for backing up sites.
Jeremy: What are some of your favorite features when building sites on WordPress? Do you have go-to themes, blocks, plugins, etc.?
John: Well, itâs changed over the years. We used to use standard old-school wireframe and theme templates that were very basic. And then we went into more âcustom designerâ mode, I would say, with templates and flashy designs. We graduated from Walmart t-shirts to Gucci t-shirts. And, you know, we enjoyed that for a while.
Now weâre going back to robust wireframes and doing more from scratch. Whatâs more important now is really the entire stack, including performance and compatibility. You know, we just donât have time to troubleshoot when we have some whizzy feature on the site. We donât have time to go in and look for why the thing is down. So, we are sort of simplifying certain things and then standardizing on a certain stack.
Jeremy: What excites you about the future of WordPress.com? Are there any new features youâre especially excited to try out and use?
John: Honestly, we just donât have time to get into a lot of that. We donât look much to experimental features or anything like that. Weâre trusting that by the time the feature or tool makes its way into being a standard of WordPress, it will be tried and true. Weâre not looking for early adopter types of things anymore.
The reality is that our value add is more about custom coding for integrationsâmaybe for a particular reservation system that has to shake hands and stay for a while on the site before it goes out to a third-party point of sale. It takes some custom coding there. Thatâs where our focus has really beenâmanaged services and then a lot more programming. Weâve been onboarding more programmers in the last 18 months than we did the first eight years of the company.
Jeremy: Do you have a few favorite client sites that you can share?
John: Well, Jeremy, itâs like asking you whoâs your favorite child.
Jeremy: Depending on the week, I can give you a pretty good answer.
John: Yeah, thatâs a good point! Sure, I have a few:
Even though WordPress.com provides the freedom and tools to create stunningly beautiful and innovative websites, thatâs not why developers choose us. Folks like John Kostak rely on WordPress.com because we have the most performant, secure, and compatible infrastructure out there. If you made it this far, you already know that you donât have to take our word for it.
Learn more about our top-notch hosting and get started:
WordPress.com/hostingRead more https://wordpress.com/blog/2024/09/05/developer-interview-john-kostak/
Taylor tweeted this morning:
"I'm excited to announce that Laravel has raised a $57M Series A in partnership with Accel."
"I believe that Laravel is the most productive way to build full-stack web applications, and Laravel Cloud will be the platform for shipping those applications that this community deserves."
Partnering with Accel has allowed Laravel start building a world-class engineering and leadership team that has resulted in Laravel Cloud (demoed at Laracon) and also another product that will be announced at Laracon AU in November.
He also follows up with some important takeaways from the announcement.
First, Iâm not going anywhere. Iâm still leading Laravel as CEO, and Iâm working closely with all of our teams to ensure weâre building the best products possible for our community.
Second, we remain committed to open source. Since partnering with Accel, weâve hired additional engineering support dedicated to open source development. I also remain the primary curator of all features in the Laravel framework. Inertia 2.0 and our first-party VS Code extension are a direct result of our increased open source engineering capacity. Accel deeply understands open source and developer focused tooling, with previous investments in Sentry, Vercel, and Linear.
For more info on this, they've made a special announcement video with answers to some common questions:
<iframe width="1238" height="696" src="https://www.youtube.com/embed/BCV_357WGaM" title="Laravel Special Announcement" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>**Where is the money going? **
Scaling up the team by hiring in many positions and building out the new Laravel Cloud. Also, they are putting paid employees on the open source side to continue working, building, and making Laravel even better.
This is a breaking story and we will update this as more information is out.
The post Laravel raises a $57 million Series A from Accel appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/laravel-raises-57-million-series-a
The Laravel team released v11.22 this week, with the
chaperone()
Eloquent method for inverse relations,
support for passing backed Enums to Queuable methods, the ability
to pass backed Enums to route ->name()
and
->domain()
methods, and more.
Samuel Levy contributed the Eloquent inverse/chaperone model relation that Taylor demonstrated in his 2024 Larcon US keynote during the open-source part of the talk.
public function comments(): HasMany
{
return $this->hasMany(Comment::class)->chaperone('post');
}
The chaperone()
/inverse()
method
avoids unexpected N+1 queries by linking back to the parent after
the relationship query has run. The above relationship will link
the appropriate Post
model in the correct relation on
Comment
instances (with scopes intact).
See Pull Request #51582 for more details.
Seth Phat contributed support for BackedEnum in Queuable trait methods:
onQueue()
onConnection()
allOnQueue()
allOnConnection()
Here's an example from the pull request:
use App\Enums\QueueConnection;
use App\Enums\QueueName;
// Before
public function register()
{
$user = User::create([...]);
SendWelcomeEmailJob::dispatch($user)
->withConnection(QueueConnection::REDIS->value)
->onQueue(QueueName::HIGH->value);
}
// After
public function register()
{
$user = User::create([...]);
SendWelcomeEmailJob::dispatch($user)
->withConnection(QueueConnection::REDIS)
->onQueue(QueueName::HIGH);
}
@NickSdot contributed passing BackedEnum
to Route domain()
and name()
methods:
// Before
Route::domain(InterfaceDomain::Marketing->value)
->name(Routes::Home->value)
->get('/contact', ContactController::class);
// After
Route::domain(InterfaceDomain::Marketing)
->name(Routes::Home)
->get('/'contact, ContactController::class);
You can see the complete list of new features and updates below and the diff between 11.21.0 and 11.22.0 on GitHub. The following release notes are directly from the changelog:
Model::getEventDispatcher()
by
@inmula in https://github.com/laravel/framework/pull/52602withProgressBar
in
InteractsWithIO by @robinmoisson
in https://github.com/laravel/framework/pull/52623The post Chaperone Eloquent Models in Laravel 11.22 appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/laravel-11-22-0
Page 15 of 1359