Skip to content

Instantly share code, notes, and snippets.

@sl-digital
Last active December 3, 2015 18:53
Show Gist options
  • Save sl-digital/3e06c4e8ad4b12029166 to your computer and use it in GitHub Desktop.
Save sl-digital/3e06c4e8ad4b12029166 to your computer and use it in GitHub Desktop.
Vagrant LEMP Stack
1) Install new Vagrant box with ubuntu/trusty64
2) sudo apt-get update / upgrade
3) install NGINX
> sudo apt-get install nginx
4) install MySQL
> sudo apt-get install mysql-server-5.6
> sudo mysql_secure_installation
Since we're using Vagrant and want to be able to access the DB remotely, we need to change the binding address and update the user
privileges to allow this.
> sudo nano /etc/mysql/my.cnf
> bind-address = 0.0.0.0
Log into MySQL
> mysql -u root -p
> create user 'root'@'10.0.2.2' identified by 'yourpassword';
> grant all privileges on *.* to 'root'@'10.0.2.2' with grant option;
> flush privileges;
> quit
Restart MySQL
> sudo service mysql restart
5) Install PHP 5.6
> sudo add-apt-repository ppa:ondrej/php5-5.6
> sudo apt-get update
> sudo apt-get install php5-fpm php5 php5-mysqlnd php5-mcrypt
PHP5 installs Apache unless you install php5-fpm before php5!!!
6) Update the default NGINX config for PHP-FPM
> sudo nano /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name server_domain_name_or_IP;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
7) Enable Mcrypt for PHP
> php5enmod mcrypt
8) Restart services
> sudo service mysql restart
> sudo service php5-fpm restart
> sudo service nginx restart
9) Create a PHP info file
> sudo nano /usr/share/nginx/html/info.php
> <?php phpinfo();
10) Load up the test page and check results
You can now forward:
80 to 8080 for NGINX
3306 to 33060 for MySQL
Enable private network
Symlink ./webroot to /usr/share/nginx/html with the default NGINX user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment