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, Bluesky, and Blogger.
I recently posted about Get Xdebug Working With Docker and PHP 8.4 to show you how easy it is to get an Xdebug connection working. In that tutorial, I hard-coded INI settings to keep the tutorial focused on setting up Xdebug. In a real application, you want your Docker images to be flexible so each developer can configure their own settings without affecting the image configuration.
In this post, I'll show you how to use environment variables to make your images super flexible. As of v8.3, PHP supports fallback values with the INI environment variable syntax, so we can really make our INI configuration clean.
If you reference the previous tutorial, our
xdebug.ini
file looked like the following snippet:
; build/php/conf.d/xdebug.ini file
[xdebug]
xdebug.mode = debug
xdebug.client_host = host.docker.internal
; Or use the host machine IP address:
; xdebug.client_host = 192.168.86.203
xdebug.start_with_request = yes
If another developer on your team doesn't want to start Xdebug by default, they'd have to update the INI file, and either commit the change or just revert it. Gross.
That is no way to live, especially since PHP now supports
default fallback values in INI files. Before we get to that, we
could also configure Xdebug directly with environment variables.
The following is equivalent to our xdebug.ini
file:
services:
app:
build:
context: .
dockerfile: build/Dockerfile
target: development
ports:
- "8080:80"
volumes:
- .:/srv/app
environment:
XDEBUG_CONFIG: "client_host=0.0.0.0 start_with_request=yes"
XDEBUG_MODE: "debug,develop"
If we moved the environment values to an unversioned ENV file, each developer could manage Xdebug settings locally. Another way to configure Xdebug is through INI like we initially did, but using envrionment variables:
; build/php/conf.d/xdebug.ini file
[xdebug]
xdebug.mode = ${PHP_XDEBUG_MODE:-debug,develop}
xdebug.client_host = ${PHP_XDEBUG_CLIENT_HOST:-host.docker.internal}
xdebug.start_with_request = ${PHP_XDEBUG_START_WITH_REQUEST:-trigger}
I've prefixed these variables with PHP_
to avoid
conflicts and quickly recognize which ENV values were meant to be
used with INI configuration. For example, XDEBUG_MODE
is reserved for Xdebug configuration directly, so if we want to
configure it via our INI ENV variable we need a unique name.
If you restart the Docker image, you can verify these settings
by adding phpinfo(); exit;
to the top of
public/index.php
or connect to the container:
$ docker compose up --build -d
$ docker compose exec app bash
# In the container
$ php -i | grep xdebug\.start_with_request
xdebug.start_with_request => trigger => trigger
If you want to try customizing these values locally, add the
following to your compose.yaml
file:
services:
app:
build:
context: .
dockerfile: build/Dockerfile
target: development
ports:
- "8080:80"
volumes:
- .:/srv/app
+ env_file:
+ - .docker.env
Then, create a .docker.env
and
.docker.env.example
file in the root of your project.
Add sensible defaults to the example file and add
.docker.env
to your .gitignore
file.
Here's an example of the contents:
PHP_XDEBUG_MODE=debug
PHP_XDEBUG_CLIENT_HOST=host.docker.internal
# Or use your computer's local network IP
# PHP_XDEBUG_CLIENT_HOST=192.168.86.250
PHP_XDEBUG_START_WITH_REQUEST=trigger
You will need to recreate the container to see the updated ENV values, but once you do, you should see your ENV settings take effect:
And that's it, your INI settings are easy to modify without affecting the image build files.
You can now make your Docker images flexible using environment
variables with INI settings. I also showed you how to use Xdebug's
built-in environment variables to configure things if you prefer
simplicity. However, not all settings can be set via the
XDEBUG_CONFIG
environment, so use the method of
configuration that works best for you!
The post Flexible Docker Images with PHP INI Environment Variables 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/flexible-docker-images-with-php-ini-environment-variables
The Laravel Process Approval package adds a structured and efficient approval process to your Laravel applications. Automate requesting and receiving approvals for your application with this highly configurable package. It has advanced abilities, such as multiple approvers, that you can customize to build complex approval requirements.
Let's say that you need sign-off from multiple people on a purchase order, license, or document model:
As the CEO, you have the ability to sign and approve:
The approval process triggers various events you can use to customize application logic when a model is submitted, approved, rejected, and so on.
You can learn more about this package, get full installation instructions, and view the source code on GitHub.
The post Add Approvals to Your Laravel Application 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/add-approvals-to-your-laravel-application
Another month means another fresh batch of excellent themes for WordPress.com. Let’s look at some of the latest additions to the WordPress.com themes gallery, with great options for content creators, small businesses, event organizers, and personal sites. Preview each one below (and maybe try taking one for a spin).
With a clean, single-hued design, minimal photography, and approachable fonts, CoachAva is built for professional coaches looking to highlight their core offerings and showcase their expertise.
Whether you’re a seasoned executive coach, a life coach, or a subject matter expert looking to sell digital or in-person services, CoachAva can help you establish trust with potential clients by putting your thought leadership front and center. Blocks make it easy to share blog posts, podcasts, and/or customer testimonials on your homepage. The flexible design makes it easy to define, package, and showcase your different offerings, connecting clients to the perfect programs.
Ideal for podcasters building their first site, Castcore features bold, attention-grabbing titles and a minimalist aesthetic that keeps your listeners focused on what matters most – your content.
With a simple homepage design, this template makes it easy for listeners to scroll through your recent content to find the right episode. Castcore is a great option for podcasters who want to build their subscriber base. The Podcast Player block makes it super easy to create an embedded mini-player for your episodes: simply copy your podcast’s RSS URL to engage listeners right on your page. Choose a grey and black color combo for a classic design or go young and bold with bright yellow.
CoachBen’s dark theme with bright accents offers a bold and professional design that perfectly reflects a coach at the top of their game. Striking and to the point, this theme allows professional coaches to quickly articulate their value proposition and define their services.
With pre-designed blocks for displaying company logos of past clients, a calendar of speaking events, and a blog subscription, there are plenty of ways to show potential clients your expertise and experience. When they’re ready to dig in, they can learn more about specific offerings on your courses page or reach out to schedule a call.
Greenseed is a beautifully simple, highly adaptable theme that makes it easy for businesses to take their brick-and-mortar brands online. Designed with full-site editing in mind, Greenseed can be customized to match any brand style, but its open spaces and bold visuals make it a particularly great choice for businesses looking to establish a streamlined online presence that embraces custom photography.
This minimal, approachable layout gives your photos space to breathe while providing key business information like address, phone number, and store hours. Link to your reservations page or provide visitors with a contact form to make it easy for potential customers to make an appointment or plan a visit.
Like the jewelry and accessory brands it was built for, Aether embodies modern elegance. With delicate fonts and natural-toned color palettes, this product-focused template offers a tasteful design that allows artisan accessories and jewelry to truly sparkle.
With social media integrations and the ability to highlight products on your homepage, Aether creates a flexible hub for your digital brand. You can allow your customers to purchase products directly through WordPress’s e-commerce plugins or you can link your website to an existing storefront. With Aether, you can be sure your customers will understand your brand’s commitment to quality and design.
With a bold split-page design and minimalist elements, Miko keeps your brand center stage. Best for individuals, creators, or service providers who want to make a lasting visual impact, this template allows visitors to navigate through all of the pages of your site on the left side without ever navigating away from the image and title anchored on the right.
Featuring a variety of hyper-modern font options and cool color combos, Miko can lean sweet and delicate or bold and artistic, effortlessly complimenting a huge range of personal and professional website identities. Regardless of the style you choose, Miko is the perfect theme for anyone who wants to present themselves as a modern, polished professional with an eye for design.
The best way to market your upcoming conference is with a sleek custom website. Conference is a flexible template that helps conference planners create a credible online presence.
The Conference template can support both marketing and event logistics: You can highlight your speakers, sponsors, and conference news to draw in new attendees via the signup form. Once attendees register, the site acts as a home base for key information, providing pages for the conference location, daily schedules, and lists of attendees to help your participants connect in advance. Whether you are hosting a multi-day affair or an intimate workshop, Conference can scale to meet the needs of your event.
Ready to give your site a makeover? You can explore these themes by clicking the “Demo” button on each theme page. Whether you’re starting a coaching business or looking to improve your professional online presence, you might just find the perfect jumping-off point for your future website.
Most premium themes are available to use at no extra charge for customers on the Personal plan or above. You can explore all of our premium themes by navigating to the “Themes” page, which is under “Appearance” in the left-side menu of your WordPress.com dashboard, or by clicking the button below:
Explore all WordPress.com themesPartner themes are third-party products that can be purchased for $99/year each on the Business or Commerce plans, so if you haven’t found what you’re looking for today, there are plenty of alternatives available.
Read more https://wordpress.com/blog/2024/12/04/hot-off-the-press-new-wordpress-com-themes-for-december-2024/
When working with conditional data modifications in Laravel applications, the transform() helper provides an elegant solution. This powerful utility function enables selective data transformation while gracefully handling null values. Let's explore how this helper can streamline your data processing workflows.
The transform() helper accepts three parameters to process your data:
// Basic transformation
$result = transform('hello world', fn ($text) => strtoupper($text));
// Output: HELLO WORLD
// Handling null with default
$result = transform(null, fn ($value) => $value * 2, 'default');
// Output: 'default'
Let's explore practical applications of transform() in a user profile system:
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
class ProfileController extends Controller
{
public function formatUserData(User $user)
{
return [
'profile' => transform($user->profile, function ($profile) {
return [
'display_name' => transform(
$profile->name,
fn ($name) => ucwords(strtolower($name)),
'Anonymous User'
),
'avatar' => transform(
$profile->avatar_url,
fn ($url) => asset($url),
'/images/default-avatar.png'
),
'bio' => transform(
$profile->biography,
fn ($bio) => str_limit($bio, 160),
'No biography provided'
),
'joined_date' => transform(
$profile->created_at,
fn ($date) => $date->format('F j, Y'),
'Recently'
)
];
}, [
'display_name' => 'Guest User',
'avatar' => '/images/guest.png',
'bio' => 'Welcome, guest!',
'joined_date' => 'N/A'
])
];
}
}
When working with configuration values:
<?php
namespace App\Services;
class CacheService
{
public function getCacheTimeout()
{
return transform(
config('cache.timeout'),
fn ($timeout) => $timeout * 60,
3600
);
}
}
The transform() helper shines when compared to traditional conditional statements:
// Traditional approach
$displayName = $user->name ? ucwords($user->name) : 'Guest';
// Using transform()
$displayName = transform($user->name, fn ($name) => ucwords($name), 'Guest');
This helper excels at making your code more readable and maintainable while handling data transformations and null cases elegantly.
The post Enhancing Data Processing with Laravel's transform() Method 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/transform
Xdebug has a history of having a steep setup learning curve. I am here to show you that setting up Xdebug doesn't have to be painful. In fact, I am confident that you can start using Xdebug with Docker in about a minute.
OK, maybe it will take some of you a few minutes :)
We will demonstrate the setup with Laravel, PHP 8.4 and Xdebug v3.4.0, the latest stable versions at the time of writing.
The gist of what we need to get Xdebug configured with a Docker image includes:
compose.yaml
file to start the containerIn this post, we are going to use Apache to simplify the server setup; however, the Dockerfile code is identical to configuring Xdebug in a PHP-FPM image.
We will start by setting up a demo project if you want to follow along:
laravel new xdebug-demo --git --no-interaction
cd xdebug-demo
mkdir -p build/php/conf.d build/apache
touch compose.yaml \
build/Dockerfile \
build/php/conf.d/xdebug.ini \
build/apache/vhost.conf
We created folders and files for our setup via the command line,
but feel free to make them however you want. In addition to the
typical Docker files, we created a vhost.conf
file to
configure the web root path to our application.
Next, add the following to your build/Dockerfile
file:
FROM php:8.4-apache as base
LABEL maintainer="Paul Redmond"
RUN docker-php-ext-install pdo_mysql opcache && \
a2enmod rewrite negotiation
COPY build/apache/vhost.conf /etc/apache2/sites-available/000-default.conf
FROM base as development
RUN cp $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini
COPY build/php/conf.d/xdebug.ini $PHP_INI_DIR/conf.d/xdebug.ini
RUN pecl channel-update pecl.php.net && \
pecl install xdebug-3.4.0 && \
docker-php-ext-enable xdebug
FROM base as app
RUN cp $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
COPY . /srv/app
The Dockerfile has quite a few lines, so lets go over the most
important code to help you grasp how to configure Xdebug. First, we
use multi-stage builds so we can configure Xdebug in development
environments. Before the development
stage is the
base
stage, which has the foundational setup our image
needs such as PHP extensions we want in any environment
and configuring Apache.
Next the development
stage copies the development
version of the PHP.ini file, copies the xdebug.ini
configuration that will hold our customizations we make to Xdebug.
We use v3.4.0
which has support for PHP 8.4 and is the
latest stable at the time of writing.
Last, we have a app
stage, which is what our
application image would use in production builds. Using the
app
target omits configuring Xdebug and uses the
production version of the php.ini file.
We aren't here to learn how to configure Apache, we just want to
use it to quickly demonstrate how easy it is to set up Xdebug in
Docker. Just add the following code to the
build/apache/vhost.conf
file, which is copied into the
Docker image to point to the application code:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /srv/app/public
<Directory "/srv/app/public">
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Next, we need to configure Xdebug via the
xdebug.ini
file we created. Add the following to this
file if you are following along:
; build/php/conf.d/xdebug.ini file
[xdebug]
xdebug.mode = debug
xdebug.client_host = host.docker.internal
; Or use the host machine IP address:
; xdebug.client_host = 192.168.86.203
xdebug.start_with_request = yes
Our customizations are needed to define the client host. Since
we are using a Docker network, Xdebug needs to know how to
communicate with our host machine. If you are using Docker desktop,
Docker has a host.docker.internal
host that points to
your host computer.
If not, you will need to find your computer's local network IP and use that. We could power this value with an environment variable, but I'll save that for a future post.
Last, we use xdebug.start_with_request = yes
to
always start Xdebug with every request. We can disable Xdebug using
our editor's UI when we don't want to use Xdebug, but it will
always attempt to establish a connection.
Before we verify an Xdebug connection, we need to configure our
application container. We will use Docker compose to run our
application with Docker by adding the following to
compose.yaml
:
services:
app:
build:
context: .
dockerfile: build/Dockerfile
target: development
ports:
- "8080:80"
volumes:
- .:/srv/app
Our app
service targets the
development
stage of our build, mounts a volume so we
can change our code without rebuilding the image, and uses port
8080
to serve the application locally.
We can now build and start our image using Docker Compose:
docker compose up --build -d
The previous command will build the image, start the container, and run it in the background. At this point, Xdebug is ready to receive connections, however, we need to tweak one thing in our IDE to get it working.
We will use PhpStorm, but you can use any editor you want that
supports Xdebug. Since we are using Docker, we need to configure a
server in PhpStorm that maps our Docker volume to our local project
code. You can do so by opening Settings > PHP >
Servers and configuring a localhost server with a mapping
of /srv/app
:
If you don't have a localhost server, you can add one from this
settings page using port 8080
and selecting the
Xdebug
debugger. The server mapping allows our IDE to
understand how to map the server stack trace to files in the
project.
Next, we are ready to enable Xdebug using the Bug icon near the top right menu that says "Start Listening for PHP Debug Connections" when you hover over it:
When you click it, you should see the icon turn green.
The last thing we need to do is set a breakpoint. Open up the
routes/web.php
file and set a breakpoint on the only
line of the homepage route:
If you open your project in a web browser (localhost:8080), PhpStorm should prompt you to connect the first time. After that, it will automatically pause on any breakpoints you set. Once you are done debugging, you can click the bug icon to disable Xdebug connections.
You should now be able to use Xdebug with your project! I also showed you a bonus topic - using multi-stage images to set up development tools and a separate stage for production settings. Using multi-stage builds can take your images to another level of flexability.
If you get stuck on the editor portion of setting up Xdebug, PhpStorm has extensive documentation on how to Configure Xdebug. Xdebug's documentation is another excellent reference, including docs on setup, tools, configuration options, and more.
The post Get Xdebug Working With Docker and PHP 8.4 in One Minute 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/get-xdebug-working-with-docker-and-php-84-in-one-minute
Page 1 of 1378