There has been much research activity recently in relation to the optimal placement of virtual machines (VMs) on physical servers. Usually the objective is to consolidate the VMs on servers for energy-saving purposes in a cloud environment. In this paper, we study the problem of optimizing the allocation of VMs having different placement constraints (e.g., security and anti-collocation) and characteristics (e.g., memory and disk capacity), given a set of physical hosts with known specifications, in order to achieve the objective of maximizing the cloud provider's revenue. This is an important resource allocation problem in data centers. Our approach is based on the formulation of the problem as an integer linear programming (ILP) problem. The ILP model produces an optimal placement for VMs with different placement constraints. Given a model of VM placement constraints, offered resources and required VM sets, the model devises a plan to allocate VMs to servers in a way that maximizes revenue, having due regard both to customer requirements and server capacities. The performance of the algorithms is evaluated by means of numerical experiments. Experiments suggest that this model and its associated solution strategy is practical for the offline development of VM-to-server allocation plans given a typical mix of customer demands for virtualized computing resources in small or medium data centers.