We present an ab inito treatment of the inverse photonic bandgap (or photonic crystal) device design problem. Using first principles, we derive the two-dimensional inverse Helmholtz equation that solves for the dielectric function that supports a given electromagnetic field with the desired properties. We show that the problem is ill-posed, meaning a solution often does not exist for the design problem. Our work elucidates fundamental limits to any inverse problem based design approach for arbitrary and optimal design of photonic devices. Despite these severe limitations, we achieve remarkable success in two design problems of particular importance to atomic physics applications, but also of general importance to the rest of the photonic community. As the first demonstration of our technique, we arbitrarily design the full dispersion curve of a photonic crystal waveguide. Dispersion control is important for maintaining the shape of pulses as they propagate along the waveguide. For our second demonstration, we take a point defect photonic crystal cavity in the nominal acceptor configuration (where the central defect has a lower index of refraction than the bulk material) and force it into the donor configuration (where the defect has a higher index of refraction than the bulk material), while requiring that the electromagnetic field maintain the properties of the acceptor mode. We were able to cross over this threshold while retaining a 93.6 percent overlap with the original mode.