Sunday, April 21, 2019

Setting Vagrant with VHOST




1. Install Vagrant in this article.

2. Log to your Vagrant from directory projects with Vagrantfile.
  •  vagrant ssh
3. From your Vagrant server type: 
  • sudo nano /etc/apache2/apache2.conf
4. Add this text in apache2.conf

<Directory /home/vagrant/public_html/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

Directory /home/vagrant/public_html/ : I put my vagrant directory sync in this path. If you use /var/www/ you can skip this step.

5. From your Vagrant server go to: 
  • cd /etc/apache2/sites-available/
6. Create vhost file for example: sample.conf

7. In sample.conf create this configuration:

<VirtualHost *:80>
        ServerName sample.notcom

        ServerAdmin webmaster@localhost
        DocumentRoot /home/vagrant/public_html/php/sample

        ErrorLog ${APACHE_LOG_DIR}/error-sample.log
        CustomLog ${APACHE_LOG_DIR}/access-sample.log combined
</VirtualHost>

ServerName: Use this to access app from browser.
DocumentRoot: path to your sync projects registered in Vagrantfile
ErrorLog and CustomLog: Log Apache2

8. Register sample.conf to sites-enabled
  • sudo a2ensite sample.conf

9. Restart your apache
  • sudo service apache2 restart
10. Access your app using:
  • sample.notcom
  • IP registered in Vagrantfile. config.vm.network "private_network", ip: "192.168.33.10"
  • If, it's still not works use registered PORT in Vagrantfile: 192.168.33.10:8064
11. Remember that you need to install some PHP extensions, PHPMYADMIN, composer, etc in your Vagrant server environment.
Share:

0 comments:

Post a Comment