[proofplan]
We construct the desired function $f$ in two stages. First, we use the local compactness and Hausdorff property to find a compact set $L$ with $K \subset \operatorname{int}(L) \subset L \subset U$. Then we apply the classical [Urysohn's Lemma](/theorems/887) to the normal space $L$ (which is normal by [Compact Hausdorff Spaces Are Normal](/theorems/1027)) to produce a continuous function separating $K$ from $L \setminus \operatorname{int}(L)$, and extend it by zero outside $L$.
[/proofplan]
[step:Construct a compact set $L$ sandwiched between $K$ and $U$]
For each $x \in K$, the space $X$ is locally compact Hausdorff, so there exists an open set $V_x \subset X$ and a compact set $C_x \subset X$ with $x \in V_x \subset C_x$. Define $W_x := V_x \cap U$, which is open in $X$, contains $x$, and satisfies $\overline{W_x} \subset \overline{V_x} \subset C_x$ (since $C_x$ is compact in a Hausdorff space, it is closed by [Compact Subspaces and Hausdorff Spaces](/theorems/307)). Moreover $\overline{W_x}$ is a closed subset of the compact set $C_x$, hence compact.
The open sets $\{W_x\}_{x \in K}$ cover $K$. By compactness of $K$, there exist finitely many points $x_1, \ldots, x_m \in K$ with $K \subset W_{x_1} \cup \cdots \cup W_{x_m}$. Define
\begin{align*}
L := \overline{W_{x_1}} \cup \cdots \cup \overline{W_{x_m}}.
\end{align*}
Since each $\overline{W_{x_i}}$ is compact, $L$ is compact (a finite union of compact sets is compact). Since each $W_{x_i} \subset U$ and $\overline{W_{x_i}} \subset C_{x_i}$, we need to verify $L \subset U$. Each $W_{x_i} = V_{x_i} \cap U \subset U$, so $\overline{W_{x_i}} \subset \overline{U}$. This does not immediately give $L \subset U$.
To refine: since $X$ is locally compact Hausdorff, for each $x \in K$ we can find an open $V_x$ with $x \in V_x$ and $\overline{V_x}$ compact and $\overline{V_x} \subset U$. This uses the regularity of locally compact Hausdorff spaces: by [Separation of Compact Sets in Hausdorff Spaces](/theorems/1026), the compact set $\{x\}$ and the closed set $X \setminus U$ can be separated by open sets, giving $V_x$ with $x \in V_x$ and $\overline{V_x} \subset U$. More precisely: since $x \in U$ and $X$ is locally compact Hausdorff, there exists an open $O_x$ with $x \in O_x$ and $\overline{O_x}$ compact. The set $\overline{O_x}$ is a compact Hausdorff space, hence normal by [Compact Hausdorff Spaces Are Normal](/theorems/1027). The sets $\{x\}$ and $\overline{O_x} \setminus U$ are disjoint closed subsets of $\overline{O_x}$ (the latter is closed in $\overline{O_x}$ since $U$ is open in $X$). By normality of $\overline{O_x}$, there exist disjoint open sets $A, B$ in $\overline{O_x}$ with $\{x\} \subset A$ and $\overline{O_x} \setminus U \subset B$. Taking $V_x := A \cap O_x$, which is open in $X$, we have $x \in V_x$ and $\overline{V_x}^X \cap \overline{O_x} \subset \overline{A}^{\overline{O_x}} \subset \overline{O_x} \setminus B \subset U$. Since $V_x \subset O_x$ and $\overline{O_x}$ is closed, $\overline{V_x} \subset \overline{O_x}$, so $\overline{V_x} \subset U$ and $\overline{V_x}$ is a closed subset of the compact $\overline{O_x}$, hence compact.
Now define $W := V_{x_1} \cup \cdots \cup V_{x_m}$ (open, contains $K$) and $L := \overline{V_{x_1}} \cup \cdots \cup \overline{V_{x_m}}$ (compact, contained in $U$). We have
\begin{align*}
K \subset W \subset L \subset U,
\end{align*}
and $W$ is open, so $K \subset \operatorname{int}(L)$.
[guided]
The goal of this step is to interpose a compact set $L$ between $K$ and $U$: we need $K \subset \operatorname{int}(L) \subset L \subset U$. This requires two properties of locally compact Hausdorff spaces: local compactness (to produce compact neighbourhoods) and a form of regularity (to ensure the compact neighbourhood fits inside $U$).
For each $x \in K$, local compactness provides an open $O_x$ with $\overline{O_x}$ compact. But $\overline{O_x}$ may extend outside $U$. To fix this, we use normality of the compact Hausdorff space $\overline{O_x}$ (guaranteed by [Compact Hausdorff Spaces Are Normal](/theorems/1027)). Inside $\overline{O_x}$, the point $x$ and the closed set $\overline{O_x} \setminus U$ are disjoint closed sets. Normality separates them by disjoint open sets $A \ni x$ and $B \supset \overline{O_x} \setminus U$. Taking $V_x := A \cap O_x$, we get $\overline{V_x} \subset \overline{O_x} \setminus B \subset U$, and $\overline{V_x}$ is compact as a closed subset of $\overline{O_x}$.
Covering $K$ by finitely many $V_{x_1}, \ldots, V_{x_m}$ and setting $L = \overline{V_{x_1}} \cup \cdots \cup \overline{V_{x_m}}$ gives a compact set with $K \subset V_{x_1} \cup \cdots \cup V_{x_m} \subset L \subset U$.
[/guided]
[/step]
[step:Apply Urysohn's Lemma on the compact set $L$]
The compact Hausdorff space $L$ is normal by [Compact Hausdorff Spaces Are Normal](/theorems/1027). The sets $K$ and $L \setminus W$ are disjoint closed subsets of $L$: $K$ is compact, hence closed in the Hausdorff space $L$; and $L \setminus W$ is closed in $L$ since $W$ is open in $X$ and hence $W \cap L$ is open in $L$.
By [Urysohn's Lemma](/theorems/887) applied to the normal space $L$ with the disjoint closed sets $K$ and $L \setminus W$, there exists a continuous function $g: L \to [0, 1]$ with $g \equiv 1$ on $K$ and $g \equiv 0$ on $L \setminus W$.
[guided]
We now apply the classical [Urysohn's Lemma](/theorems/887), which requires a normal space and two disjoint closed subsets. The compact Hausdorff space $L$ is normal by [Compact Hausdorff Spaces Are Normal](/theorems/1027).
The two closed sets are: $K$ (compact, hence closed in the Hausdorff space $L$ by [Compact Subspaces and Hausdorff Spaces](/theorems/307)) and $L \setminus W$ (the complement of the open set $W \cap L$ in $L$, hence closed). They are disjoint because $K \subset W$.
Urysohn's Lemma produces $g: L \to [0,1]$ with $g|_K \equiv 1$ and $g|_{L \setminus W} \equiv 0$.
[/guided]
[/step]
[step:Extend by zero to obtain $f \in C_c(X)$]
Define the function
\begin{align*}
f: X &\to [0, 1] \\
x &\mapsto \begin{cases} g(x) & \text{if } x \in L, \\ 0 & \text{if } x \in X \setminus L. \end{cases}
\end{align*}
**$f$ is well-defined.** The two cases agree on $L \cap (X \setminus L) = \varnothing$, so there is no conflict. On the boundary $\partial L$ (which is contained in $L$ since $L$ is closed in $X$), the function $g$ is defined and equals $0$ (since $\partial L \subset L \setminus \operatorname{int}(L) \subset L \setminus W$, and $g \equiv 0$ on $L \setminus W$).
**$f$ is continuous.** The sets $L$ and $X \setminus \operatorname{int}(L)$ are closed subsets of $X$ whose union is $X$ (since $L \cup (X \setminus \operatorname{int}(L)) = X$, noting $\operatorname{int}(L) \subset L$). On $L$, the function $f = g$ is continuous. On $X \setminus \operatorname{int}(L)$, the function $f \equiv 0$ is continuous. On the overlap $L \setminus \operatorname{int}(L) = L \cap (X \setminus \operatorname{int}(L))$, both definitions agree: $g \equiv 0$ on $L \setminus W \supset L \setminus \operatorname{int}(L)$. By the pasting lemma (gluing continuous functions on closed sets that agree on the intersection), $f$ is continuous on $X$.
**$f \equiv 1$ on $K$.** For $x \in K$, we have $x \in L$ and $f(x) = g(x) = 1$.
**$\operatorname{supp}(f)$ is compact and contained in $U$.** The support $\operatorname{supp}(f) = \overline{\{x \in X : f(x) \neq 0\}}$. Since $f(x) = 0$ for all $x \in X \setminus L$ and $f(x) = g(x) = 0$ for $x \in L \setminus W$, the set $\{x : f(x) \neq 0\} \subset W \subset L$. Therefore $\operatorname{supp}(f) \subset \overline{W} \subset L$ (since $L$ is closed). The support is a closed subset of the compact set $L$, hence compact by [Compact Subspaces and Hausdorff Spaces](/theorems/307). Since $L \subset U$, we have $\operatorname{supp}(f) \subset U$.
In particular, $f \in C_c(X)$.
[/step]