The LQ problem, i.e. the finite-horizon linear quadratic optimal control problem with nonnegative state constraints, is studied for positive linear systems in continuous time and in discrete time. Necessary and sufficient optimality conditions are obtained by using the maximum principle. These conditions lead to a computational method for the solution of the LQ problem by means of a corresponding Hamiltonian system. In addition, the necessary and sufficient conditions are proved for the LQ -optimal control to be given by the standard LQ-optimal state feedback law. Then sufficient conditions are established for the positivity of the LQ-optimal closed-loop system. In particular, such conditions are obtained for the problem of minimal energy control with penalization of the final state. Moreover, a positivity criterion for the LQ-optimal closed-loop system is derived for positive discrete-time systems with a positively invertible (dynamics) generator. The main results are illustrated by numerical examples.