Once you have up and running Vagrant and VirtualBox in your machine you need to follow these steps to create a VM and install all necessary dependencies to run PHP Projects.


 vagrant vm

Step 1. Go to the Directory where you have the Vagrantfile and then execute

$ vagrant suspend

 this will stop the VM if it is running.

then with a text editor, replace the content of the Vagrantfile with this:

Vagrant.configure("2") do |config|
  # VM with CentOS 7
  config.vm.box = "geerlingguy/centos7"
  # Use private network
  config.vm.network "private_network", ip: ""

  # sync a project folder between host computer and VM
  config.vm.synced_folder "./projects", "/var/www/projects"

  # Enable provisioning with a shell script. Additional provisioners such as
  # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
  # documentation for more information about their specific syntax and use.
   config.vm.provision "shell", inline: <<-SHELL
     sudo yum -y update
     sudo yum -y install perl wget nano cronie zip unzip grubby gcc gcc-c++ kernel-devel re2c make
     cd /tmp
     curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
     sudo yum  -y install MariaDB-server MariaDB-client
     sudo yum -y install epel-release
     wget http://rpms.remirepo.net/enterprise/remi-release-7.9.rpm
     sudo rpm -Uvh remi-release-7.9.rpm
     sudo yum install yum-utils -y
     sudo yum install nginx -y
     sudo yum-config-manager --enable remi-php82
     sudo yum -y --enablerepo=remi,remi-php82 install php-fpm php-common
     sudo yum -y --enablerepo=remi,remi-php82 install php-gd php-mysqlnd php-mbstring php-xml php-intl php-mcrypt php-pdo php-xmlrpc php-soap php-opcache php-json php-cli php-devel php-odbc php-pecl-apcu php-pear php-zip
     sudo systemctl start firewalld
     sudo systemctl enable firewalld  
     sudo systemctl start mariadb
     sudo systemctl enable mariadb
     sudo systemctl start nginx
     sudo systemctl enable nginx
     sudo systemctl start php-fpm
     sudo systemctl enable php-fpm
     sudo systemctl start firewalld
     sudo systemctl enable firewalld
     sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
     sudo firewall-cmd --reload
     sudo chown -R mysql:mysql /var/lib/mysql
     curl -fsSL https://rpm.nodesource.com/setup_16.x | bash -
     sudo yum install –y nodejs
     curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
     sudo rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg
     sudo yum install yarn

 Save the file.


Step 2. Execute

$ mkdir projects
$ vagrant up --provision

First you will create the projects folder where you will be sync'ing all your code between host machine and VM, then you wil lturn on and provision the VM. This process may take a few minutes in get done.

Step 2. Open a SSH Console to configure new provisioned Virtual Machine.

$ vagrant ssh


Step 3. Open up ports 80 and 443 to allow requests from the outside world into the VM.

$ sudo firewall-cmd --permanent --add-port=80/tcp
$ sudo firewall-cmd --permanent --add-port=443/tcp
$ sudo firewall-cmd --reload
$ # make sure the ports were added and loaded
$ sudo firewall-cmd --list-ports

 you will see something like this:


You may also need to disable SELinux.


Step 4. Tune VM to work with Enterprise Class PHP Projects.

$ sudo grubby --update-kernel=ALL --args="elevator=noop"


$ sudo nano /etc/sysctl.conf

remove all lines if any and replace with:

#####  Performance kernel conf
##     Ruben Elizondo
## restrict file swapping as much as possible. not recommended to set it to 0
vm.swappiness = 1
fs.file-max = 5000000
net.core.netdev_max_backlog = 400000
net.core.optmem_max = 10000000
net.core.rmem_default = 10000000
net.core.rmem_max = 10000000
net.core.somaxconn = 100000
net.core.wmem_default = 10000000
net.core.wmem_max = 10000000
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_congestion_control = bic
net.ipv4.tcp_ecn = 0
net.ipv4.tcp_max_syn_backlog = 12000
net.ipv4.tcp_max_tw_buckets = 2000000
net.ipv4.tcp_mem = 30000000 30000000 30000000
net.ipv4.tcp_rmem = 30000000 30000000 30000000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_syncookies = 0
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_wmem = 30000000 30000000 30000000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
kernel.sem=250 32000 32 1024


Save the file and then

$ sudo nano /etc/security/limits.conf

add this just right below #@student

*                -	 nofile          16384

Save the file.

Then restart your VM to enable all these changes.

$ exit
$ vagrant suspend
$ vagrant up

 Next Up: