We study photon-photon correlations and entanglement generation in a one-dimensional waveguide coupled to two qubits with an arbitrary spatial separation. We develop a novel Green function method to study vacuum-mediated qubit-qubit interactions, including both spontaneous and coherent couplings. As a result of these interactions, quantum beats appear in the second-order correlation function. We go beyond the Markovian regime and observe that such quantum beats persist much longer than the qubit life time. Using these non-Markovian processes, a high degree of long-distance entanglement can be generated, making waveguide-QED systems promising candidates for scalable quantum networking.