The Greens function has been an indispensable tool to study many-body systems that remain one of the biggest challenges in modern quantum physics for decades. The complicated calculation of Greens function impedes the research of many-body systems. The appearance of the noisy intermediate-scale quantum devices and quantum-classical hybrid algorithm inspire a new method to calculate Greens function. Here we design a programmable quantum circuit for photons with utilizing the polarization and the path degrees of freedom to construct a highly-precise variational quantum state of a photon, and first report the experimental realization for calculating the Greens function of the two-site Fermionic Hubbard model, a prototypical model for strongly-correlated materials, in photonic systems. We run the variational quantum eigensolver to obtain the ground state and excited states of the model, and then evaluate the transition amplitudes among the eigenstates. The experimental results present the spectral function of Greens function, which agrees well with the exact results. Our demonstration provides the further possibility of the photonic system in quantum simulation and applications in solving complicated problems in many-body systems, biological science, and so on.