Constructions of optimal locally repairable codes (LRCs) in the case of $(r+1) \nmid n$ and over small finite fields were stated as open problems for LRCs in [I. Tamo et al., "Optimal locally repairable codes and connections to matroid theory", 2013 IEEE ISIT]. In this paper, these problems are studied by constructing almost optimal linear LRCs, which are proven to be optimal for certain parameters, including cases for which $(r+1) \nmid n$. More precisely, linear codes for given length, dimension, and all-symbol locality are constructed with almost optimal minimum distance. 'Almost optimal' refers to the fact that their minimum distance differs by at most one from the optimal value given by a known bound for LRCs. In addition to these linear LRCs, optimal LRCs which do not require a large field are constructed for certain classes of parameters.