0%

LEMP development environment using Vagrant

LEMP development environment using Vagrant

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-with-nginx-on-an-ubuntu-14-04-server

Vagrantfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
# config.vm.box_check_update = false
config.vm.synced_folder "code/", "/vagrant", :group => 'www-data', mount_options: ['dmode=777','fmode=775']
# Network
# config.vm.network "forwarded_port", guest: 80, host: 8080
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
config.vm.network "private_network", ip: "192.168.33.10"
# config.vm.network "public_network"
config.vm.provision "shell", inline: <<-SHELL
apt-get update
SHELL
end

Stuff

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
vagrant up
vagrant ssh
# Nginx
sudo apt install nginx -y
sudo vim /etc/nginx/sites-available/default
sudo nginx -t
sudo systemctl reload nginx
# MySQL
sudo apt install mysql-server -y
sudo mysql_secure_installation # Optional
# PHP
sudo apt-get install php-fpm php-mysql -y
sudo vim /etc/php/7.0/fpm/php.ini # Optional
cgi.fix_pathinfo=0 # 0 more secure
sudo systemctl restart php7.0-fpm.service
sudo vim /etc/nginx/sites-available/default
sudo nginx -t
sudo systemctl reload nginx
# phpMyAdmin (Optional)
sudo apt install phpmyadmin -y
TAB to skip choosing server, then type db password
sudo phpenmod mcrypt
sudo vim /etc/nginx/sites-available/default
sudo nginx -t
sudo systemctl reload nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# sudo vim /etc/nginx/sites-available/default
# Nginx static file (default)
server {
listen 80 default_server;
listen [::]:80 default_server;
root /vagrant;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
autoindex on;
try_files $uri $uri/ =404;
}
}
# Nginx with php
server {
listen 80 default_server;
listen [::]:80 default_server;
root /vagrant;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
autoindex on;
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
# phpMyAdmin (Optional)
server {
listen 8080;
listen [::]:8080;
root /usr/share/phpmyadmin;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}

Laravel

https://www.digitalocean.com/community/tutorials/how-to-deploy-a-laravel-application-with-nginx-on-ubuntu-16-04

  • multi-byte string support: php-mbstring
  • XML support: php-xml
  • Composer
  • unzip (which allows Composer to handle zip files) at the same time.
  • php-zip for laravel installer
1
2
3
4
5
sudo apt install php-mbstring php-xml composer unzip php-zip -y
# Installer
composer global require "laravel/installer"
echo 'export PATH="$HOME/.config/composer/vendor/bin:$PATH"' >> .bashrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# sudo vim /etc/nginx/sites-available/default
server {
listen 8087 default_server;
listen [::]:8087 default_server;
root /vagrant/YOUR_LARAVEL_FOLDER/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}

lazy Vargantfile

https://stackoverflow.com/questions/7739645/install-mysql-on-ubuntu-without-password-prompt
https://github.com/mauserrifle/vagrant-debian-shell/blob/master/install-phpmyadmin.sh
https://askubuntu.com/questions/294736/run-a-shell-script-as-another-user-that-has-no-password

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
# config.vm.box_check_update = false
config.vm.synced_folder "code/", "/vagrant", :group => 'www-data', mount_options: ['dmode=777','fmode=775']
# Network
# config.vm.network "forwarded_port", guest: 80, host: 8080
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# config.vm.network "public_network"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.provision "shell", inline: <<-SHELL
sudo apt-get update -y > /dev/null
echo '---vagrant: installing nginx---'
sudo apt-get install nginx -y
echo '---vagrant: installing mysql---'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password secret'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password secret'
sudo apt-get install mysql-server -y
echo '---vagrant: installing php---'
sudo apt-get install php-fpm php-mysql -y
NGINX='server {
listen 80 default_server;
listen [::]:80 default_server;
root /vagrant;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
autoindex on;
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}'
echo "$NGINX" > /etc/nginx/sites-available/default
sudo systemctl reload nginx
echo '---vagrant: installing phpMyAdmin---'
echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect none" | debconf-set-selections
echo "phpmyadmin phpmyadmin/dbconfig-install boolean true" | debconf-set-selections
echo 'phpmyadmin phpmyadmin/mysql/app-pass password secret' | debconf-set-selections
sudo apt-get install phpmyadmin -y
sudo phpenmod mcrypt
PMA='server {
listen 8080;
listen [::]:8080;
root /usr/share/phpmyadmin;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}'
echo "$PMA" >> /etc/nginx/sites-available/default
sudo systemctl reload nginx
echo '---vagrant: installing Laravel enviromment---'
sudo apt-get install php-mbstring php-xml composer unzip php-zip -y
LARAVEL='server {
listen 8087 default_server;
listen [::]:8087 default_server;
root /vagrant/laravel/testing/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}'
echo "$LARAVEL" >> /etc/nginx/sites-available/default
sudo systemctl reload nginx
echo '---vagrant: installing laravel/installer---'
sudo -H -u ubuntu bash -c 'composer global require "laravel/installer"'
cd /home/ubuntu
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> .bashrc
SHELL
end
# NOTE:
#
# Done! Then configure nginx(laravel part) yourself.
# vagrant ssh
# cd YOUR.vm.synced_folder
# laravel new testing
# sudo vim /etc/nginx/sites-available/default
# sudo systemctl reload nginx
#
# Available sites
# http://192.168.33.10 # autoindex
# http://192.168.33.10:8080 # phpMyAdmin
# http://192.168.33.10:8087 # Laravel

Conclusion

https://github.com/lovenery/vagrant-laravel