Quick and easy development environment for developing LAMP apps - eg. Laravel applications - using Vagrant.
This setup uses Vagrant to provision an ubuntu LAMP server on virtual box.
If the vagrant Server is already up and running you can access the the application (in the myapp directory): http://localhost:8088/
These IPs will also work: http://127.0.0.1:8088 or http://192.168.94.1:8088
- Getting Start
- Adding Existing Applications
- MySQL Config
- Setting Hostnames
- Enabling xDebug
- Installing Laravel from Scratch
git clone https://github.com/mkeneqa/vagrant-lamp.git
git checkout php7.4
git checkout php7.2
After downloading/cloning, your folder structure should look like this:
│ README.md
│ Vagrantfile
│
├───myapp
│
├───prepare
│ apache2.conf
│ myapp.conf
│ ports.conf
│ setup.sh
│
This will go through the process of provisioning your VM. Additionally, you may want to set up Private networking to use hostname. See Notes on Setting Vagrant with Hostname
vagrant up
Note: Vagrant will still be running when the setup is done.
The vagrant server must be started within the project folder where the Vagrantfile
is located.
Type in the command line:
vagrant up
To stop the server type in the terminal:
vagrant halt
vagrant destroy --f
NOTE: This won't remove files and folders within the myapp
directory
http://localhost:8088/ or the specified domain if hostname is configured
Extra options that may help with setting up your application.
If you alread have an existing application just git clone
it into the myapp
directory
Make sure to put the (.) period at the end to avoid creating a nested folder.
example: git clone https://github.com/user/myapp.git .
Command line : mysql -uroot -proot
host: localhost
or 127.0.0.1
(or whatever ip you have specified if using private network)
user: root
pswd: root
port: 33306
pre-created database: myapp_db
This configuration allows the use of a FQDN and not ip addresses eg. mydomain.local
Uncomment these lines in the Vagrantfile
and save.
You can use whatever domain you want but don't use the .dev
TLD.
# config.vm.network "private_network", ip: "192.168.10.10"
# config.vm.hostname = '<yourdomain>.local'
In Windows open the command line application as Administrator.
Type this in the command line: notepad.exe C:\Windows\System32\drivers\etc\hosts
Add domain entry to hosts file in notepad and save:
eg:
192.168.10.10 <yourdomain>.local
vagrant reload
NOTE: This has been tested on Windows host but should work on other host OS. You'll need to change the OS host file accordingly
Sources:
NOTE: This should already be enabled during the Vagrant provisioning step
xDebug is already installed on the vagrant server. It may need to be enabled via the php.ini
.
First log in to the vagrant server using : vagrant ssh
Then run the following commands (or manually add them to the php.ini
file):
echo 'xdebug.remote_port=9000' >> /etc/php/7.4/apache2/php.ini
echo 'xdebug.remote_enable=true' >> /etc/php/7.4/apache2/php.ini
echo 'xdebug.remote_connect_back=true' >> /etc/php/7.4/apache2/php.ini
echo 'xdebug.remote_autostart=on' >> /etc/php/7.4/apache2/php.ini
echo 'xdebug.remote_host=' >> /etc/php/7.4/apache2/php.ini
echo 'xdebug.max_nesting_level=1000' >> /etc/php/7.4/apache2/php.ini
echo 'xdebug.idekey=PHPSTORM' >> /etc/php/7.4/apache2/php.ini
Restart apache server: sudo apachectl restart
For the PhpStorm IDE here's a tutorial to configure xDebug.
vagrant ssh
cd /var/www/myapp
composer create-project --prefer-dist laravel/laravel .
composer require laravel/ui
php artisan ui bootstrap --auth
npm install
npm run dev
Read more on Laravel frontend scaffolding options
NOTE: Steps above should work for other LAMP apps like Symfony4 and WordPress