Solving 1d poisson equation with point source and periodic boundary condition 
How can I solve poisson equation with two point charge sources in periodic 1D domain analytically. 
  $$\dfrac{d^2\phi}{dx^2}=-\dfrac{q}{\epsilon_0}\left(\delta(x-x')-\delta(x+x')\right)\,,$$
  where $x\in[-L/2,L/2]$ and $\phi(x)=\phi(x+L)$?

The solution is 
$$
\phi=
\begin{cases}
& \dfrac{q}{\epsilon_0 L}(L-2x')x \quad|x|\leq x' \\
& \dfrac{q}{\epsilon_0 L}(L-2x)x' \quad x'\leq|x|\leq\dfrac{L}{2}
\end{cases}
$$
which can be found in Hockney's book Computer Simulation Using Particles.
 A: The key is to note that for $x\neq \pm x'$, your equation reduces to the Laplace equation.  You can solve this fairly trivially in one dimension, which will leave you with three solutions 
$\phi_1,\phi_2,$ and $\phi_3$, corresponding to the regions $R_1=[-L/2,-x']$, $R_2=[-x',x']$, and $R_3=[x',L/2]$.
To unify these into a single solution, note that the Poisson equation gives you jump conditions on the derivatives of $\phi$.  For example, at $x=-x'$, you have that
$$\lim_{\epsilon\rightarrow 0} \left.\frac{d\phi}{dx}\right|^{-x'+\epsilon}_{-x'-\epsilon} = \phi'_2(-x')-\phi'_1(-x')$$
which is also equal to
$$ \lim_{\epsilon\rightarrow 0} \int_{-x'-\epsilon}^{-x'+\epsilon}\frac{d^2\phi}{dx^2} dx = \lim_{\epsilon\rightarrow 0} \int_{-x'-\epsilon}^{-x'+\epsilon}\frac{q}{\epsilon_0} \delta(x+x') = \frac{q}{\epsilon_0}$$
This, along with the fact that $\phi$ is continuous everywhere, should give you two boundary conditions at $x=-x'$ and two at $x=+x'$.  The demand for periodicity should give you the rest.
A: Integrating twice we arrive at:
$$\phi(x)=-\frac{q}{\epsilon_0}\left[(x-x')\Theta(x-x')-(x+x')\Theta(x+x')\right]+Cx+D$$
(I've used $\int\delta(x)dx=\Theta(x)$ and $\int\Theta(x)dx=x\Theta(x)$).
Now, since $x$ is restricted to $[-\frac L2,\frac L2]$ we only need to set $\phi(-\frac L2)=\phi(\frac L2)=0$. Potential is defined up to an arbitrary constant so we can make it zero at the boundaries.
This gives $C=-\frac{2qx'}{\epsilon_0L}$ and $D=-\frac{qx'}{\epsilon_0}$
Finally,
$$\phi(x)=-\frac{q}{\epsilon_0}\left[(x-x')\Theta(x-x')-(x+x')\Theta(x+x')\right]-\frac{2qx'}{\epsilon_0L}x-\frac{qx'}{\epsilon_0}$$
In other form:
$$\phi(x)=\begin{cases}
-\frac{q}{\epsilon_0L}(L+2x)x'&-\frac L2\le x\le -x'\\
\frac{q}{\epsilon_0L}(L-2x')x&|x|\le x'\\
\frac{q}{\epsilon_0L}(L-2x)x'&x'\le x\le \frac L2
\end{cases}$$
Which is different from the solution you provided over the interval $[-L/2,-x']$, but it's continuous at $x=-x'$ as it should be (the one you provided is not).
