We construct some families of p-ary minimal and distance-optimal codes and some families of locally repairable p-ary codes by the homogenization method for a prime p. For this, we use the code \(C_{(D_{F_h})^c}\) associated with the complement of the defining set \(D_{F_h}\) generated from the homogenization \(F_h\) of a multi-variable function F. We first find two criteria: one is a criterion for the code \(C_{(D_{F_h})^c}\) to be a minimal code, and the other is a criterion for \(C_{(D_{F_h})^c}\) to be an LRC (Locally Repairable Code) with locality \(t\ge 2\) . Then we focus on the codes \(C_{(\Delta _h)^{c^*}}\) , which are the cases where the defining sets \(D_F\) are certain down-sets \(\Delta\) of \(\mathbb {F}_p^n\) generated by one maximal element with support size at most two. We obtain several infinite families of minimal p-ary linear codes, using the first criterion; some of them are also distance-optimal. Furthermore, we produce several infinite families of LRCs with locality two including an infinite family of alphabet-optimal LRCs, using the second criterion.