├── .editorconfig ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── Vagrantfile ├── refresh.sh ├── scripts ├── clean-v2.sh ├── clean.sh └── util.sh ├── site.yml └── templates └── phpmyadmin.j2 /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | insert_final_newline = true 5 | indent_style = space 6 | charset = utf-8 7 | 8 | [*.{sh,js,php,css,scss}] 9 | end_of_line = lf 10 | charset = utf-8 11 | 12 | [*.{js,json,yml}] 13 | indent_size = 2 14 | 15 | [*.php] 16 | indent_size = 4 17 | 18 | [*.{md,markdown}] 19 | indent_size = 4 20 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Autodetect text files 2 | * text=auto 3 | 4 | # Force sh file use lf 5 | *.sh text eol=lf 6 | 7 | .gitattributes eol=lf 8 | Vagrantfile eol=lf 9 | 10 | *.php text eol=lf 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | .idea 3 | package.box 4 | index.php 5 | site.retry 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Pinglei Guo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lnmp 2 | Vagrant box for PHP projects 3 | 4 | Deprecated, see https://github.com/dyweb/miemieda 5 | 6 | For PHP5.X see [legacy/ubuntu-14.04-PHP5](https://github.com/at15/lnmp/tree/legacy/ubuntu-14.04-PHP5) branch. 7 | The [feature/php7](https://github.com/at15/lnmp/tree/feature/php7) branch is also deprecated, PHP7 is now in the master branch. 8 | 9 | - [Vagrant Cloud PHP7.x](https://atlas.hashicorp.com/at15/boxes/lnmp7/) 10 | - [Vagrant Cloud PHP5.x](https://atlas.hashicorp.com/at15/boxes/lnmp/) 11 | 12 | ## Include 13 | 14 | - Ubuntu 16.04 LTS 15 | - Nginx 1.10.1 `ppa:nginx/stable` 16 | - MySQL 5.7 17 | - PHP 7.1 `ppa:ondrej/php` 18 | - Composer `/usr/local/bin/composer` 19 | - Redis 3.07 `ppa:chris-lea/redis-server` 20 | - Phpmyadmin 4.5.4.1 (nginx config is `/etc/nginx/conf.d/phpmyadmin.conf`) 21 | 22 | ## Requirement 23 | 24 | - Virtualbox 4.3+ (5.0 is tested, the guest addtion is working on windows, Mac user may 25 | need to update TODO: the issue for brew cask installed vbox) 26 | - Vagrant latest 27 | - Host OS: Fedora 25, Ubuntu 16.10, Windows 10 (not tested but should work) 28 | 29 | ## Usage 30 | 31 | ### Use the pre-built box 32 | 33 | Deprecated, this repo will be moved to https://github.com/dyweb, the box on Atlas will also change. 34 | 35 | Use the following Vagrantfile, and run `vagrant up --provider virtualbox` 36 | 37 | - edit your host machine's `hosts` file, add `127.0.0.1 mysql.lk`, and use `mysql.lk:8080` to visit phpmyadmin 38 | - use `localhost:8080` to visit nginx welcome page 39 | 40 | If you have a bad network, you can run the provison multiple times, it has side effects, but won't break your 41 | PHP projects. 42 | 43 | - `vagrant up --provison` works when your vm is stop or running 44 | - `vagrant reload --provision` would restart the vm and run the provision when start 45 | 46 | As for package management tools, you will have problem running `npm` inside the box 47 | when your using windows host due to symbolic link. 48 | 49 | - npm can be solved using `npm install --no-bin-links` see https://github.com/npm/npm/issues/5874 50 | - composer may have similar problem 51 | 52 | For windows users, I suggest running `git` and `npm` in your git bash or cmd instead of inside the vm. 53 | Since most PHP projects use node for building assets instead of application server, running instead vm 54 | is not a must. 55 | 56 | ````ruby 57 | # -*- mode: ruby -*- 58 | # vi: set ft=ruby : 59 | 60 | Vagrant.configure(2) do |config| 61 | 62 | # The pre built box is on https://atlas.hashicorp.com/at15/boxes/lnmp7/ 63 | config.vm.box = "at15/lnmp7" 64 | 65 | # If the base box updated, you can't update your current vm without destroy it 66 | config.vm.box_check_update = true 67 | 68 | # Forward guest 80 to host 8080 69 | config.vm.network "forwarded_port", guest: 80, host: 8080 70 | 71 | # Use 777 for the default mount folder. which works for Ubuntu and Mac, windows always got 777 72 | config.vm.synced_folder ".", "/vagrant", \ 73 | :disabled => false, \ 74 | :mount_options => ['dmode=777,fmode=777'] 75 | 76 | config.vm.provider "virtualbox" do |vb| 77 | # Don't show the GUI unless you have some bug 78 | vb.gui = false 79 | # Customize the amount of memory on the VM: 80 | vb.memory = "1024" 81 | # Config the name 82 | vb.name = "lnmp7" 83 | end 84 | end 85 | ```` 86 | 87 | ### Build the box 88 | 89 | - `git clone git@github.com:at15/lnmp.git` 90 | - `cd lnmp` 91 | - `vagrant up` it will run the provision using Ansible. see [site.yml](site.yml) for detail 92 | - ssh into the vm and run `util/clean.sh` to clean up apt stuff before you package the box 93 | - `vagrant package` to build the new box 94 | - upload it to [Atlas](https://atlas.hashicorp.com/boxes/search?utm_source=vagrantcloud.com&vagrantcloud=1) 95 | 96 | ## Acknowledgement 97 | 98 | - https://github.com/LukeXuan/atlas-centos7 99 | - https://github.com/leonidas/ansible-nvm 100 | - https://github.com/arbabnazar/ansible-roles/tree/master/LEMP 101 | 102 | ## License 103 | 104 | MIT 105 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.configure(2) do |config| 5 | 6 | # the base box is ubuntu 16.04 LTS 7 | config.vm.box = "bento/ubuntu-16.04" 8 | 9 | # need to check update 10 | config.vm.box_check_update = true 11 | 12 | # forward guest 80 to host 8080 13 | config.vm.network "forwarded_port", guest: 80, host: 8080 14 | 15 | # Use 777 for the default mount folder. which works for Ubuntu and Mac, windows always got 777 16 | config.vm.synced_folder ".", "/vagrant", \ 17 | :disabled => false, \ 18 | :mount_options => ['dmode=777,fmode=777'] 19 | 20 | config.vm.provider "virtualbox" do |vb| 21 | # Don't show the GUI unless you have some bug 22 | vb.gui = false 23 | # Customize the amount of memory on the VM: 24 | vb.memory = "1024" 25 | # Config the name 26 | vb.name = "at15-lnmp" 27 | end 28 | 29 | 30 | # Run Ansible from the Vagrant Guest 31 | config.vm.provision "ansible_local" do |ansible| 32 | ansible.playbook = "site.yml" 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /refresh.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo "try to update the base box, ubuntu 16.04 LTS" 4 | vagrant box update 5 | echo "destroy the old box" 6 | vagrant destroy -f 7 | echo "up" 8 | vagrant up 9 | 10 | echo "a new instance is up and running, use vagrant ssh to login" 11 | -------------------------------------------------------------------------------- /scripts/clean-v2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -eux 2 | 3 | # delete docs packages 4 | dpkg --list \ 5 | | awk '{ print $2 }' \ 6 | | grep -- '-doc$' \ 7 | | xargs apt-get -y purge; 8 | 9 | # Delete X11 libraries 10 | apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6; 11 | 12 | # Delete obsolete networking 13 | apt-get -y purge ppp pppconfig pppoeconf; 14 | 15 | # Delete oddities 16 | apt-get -y purge popularity-contest installation-report command-not-found command-not-found-data friendly-recovery; 17 | 18 | apt-get -y autoremove; 19 | apt-get -y clean; 20 | 21 | # Remove docs 22 | rm -rf /usr/share/doc/* 23 | 24 | # Remove caches 25 | find /var/cache -type f -exec rm -rf {} \; 26 | 27 | # delete any logs that have built up during the install 28 | find /var/log/ -name *.log -exec rm -f {} \; 29 | -------------------------------------------------------------------------------- /scripts/clean.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | source ./util.sh 4 | 5 | # https://gist.github.com/justindowning/5921369 6 | print_green 'Clean apt' 7 | 8 | sudo apt-get -y autoremove 9 | sudo apt-get -y clean 10 | 11 | print_green 'Cleanup bash history' 12 | 13 | sudo unset /root/.bash_history 14 | sudo unset /home/vagrant/.bash_history 15 | sudo rm /root/.bash_history 16 | sudo rm /home/vagrant/.bash_history 17 | 18 | print_green 'Bash history for root and vagrant are removed' 19 | 20 | # TODO: clean up apt-cache, log file 21 | -------------------------------------------------------------------------------- /scripts/util.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # http://askubuntu.com/questions/162391/how-do-i-fix-my-locale-issue 4 | # two way 5 | # on server, use export LC_ALL 6 | # on client, This is a common problem if you are connecting remotely, 7 | # so the solution is to not forward your locale. 8 | # Edit /etc/ssh/ssh_config and comment out SendEnv LANG LC_* line. 9 | 10 | export LC_ALL="en_US.UTF-8" 11 | 12 | function print_green { 13 | echo -e "\e[32m${1}\e[0m" 14 | } 15 | -------------------------------------------------------------------------------- /site.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | become: true 3 | vars: 4 | mysql_root_pass: vagrant 5 | phpmyadmin_pass: vagrant 6 | phpmyadmin_host: mysql.lk 7 | nvm_user: vagrant 8 | handlers: 9 | - name: restart nginx 10 | service: name=nginx state=restarted enabled=yes 11 | tasks: 12 | - name: Update repository 13 | apt: 14 | update_cache: yes 15 | - name: Update all packages to the latest version 16 | apt: 17 | upgrade: dist 18 | - name: Install essential tools 19 | apt: name={{ item }} state=present 20 | with_items: 21 | - git 22 | - vim 23 | - curl 24 | - wget 25 | - build-essential 26 | - gcc 27 | - make 28 | 29 | # Start of PPA 30 | # Add nginx stable repository from PPA and install its signing key. 31 | - name: Add nginx PPA 32 | apt_repository: 33 | repo: 'ppa:nginx/stable' 34 | - name: Add redis PPA 35 | apt_repository: 36 | repo: 'ppa:chris-lea/redis-server' 37 | - name: Add PHP PPA 38 | apt_repository: 39 | repo: 'ppa:ondrej/php' 40 | # End of PPA 41 | 42 | # Start of Installation 43 | - name: Install nginx 44 | apt: 45 | name: nginx 46 | - name: Install redis 47 | apt: 48 | name: redis-server 49 | 50 | # NOTE: the password problem 51 | # https://coderwall.com/p/sqdaya/mysql-server-installation-with-custom-password-in-ansible--2 52 | - name: Set MySQL root password before installing 53 | debconf: name='mysql-server' question='mysql-server/root_password' value='{{ mysql_root_pass }}' vtype='password' 54 | - name: Confirm MySQL root password before installing 55 | debconf: name='mysql-server' question='mysql-server/root_password_again' value='{{ mysql_root_pass }}' vtype='password' 56 | - name: Install MySQL 57 | apt: name={{ item }} state=present 58 | with_items: 59 | - mysql-server 60 | - mysql-client 61 | 62 | - name: Install PHP7 63 | apt: name={{ item }} state=present 64 | # TODO: enable error report 65 | with_items: 66 | - php7.1-fpm 67 | - php7.1-mcrypt 68 | - php7.1-zip 69 | - php7.1-redis 70 | - php7.1-xdebug 71 | - php7.1-curl 72 | - php7.1-gd 73 | - php7.1-intl 74 | - php7.1-mysql 75 | - php7.1-sqlite3 76 | - php7.1-xml 77 | - php7.1-mbstring 78 | - name: Check if composer is installed 79 | # http://stackoverflow.com/questions/21892603/how-to-make-ansible-execute-a-shell-script-if-a-package-is-not-installed 80 | command: bash -c 'which composer' 81 | register: composer_check 82 | failed_when: False 83 | - name: Install composer 84 | become_user: root 85 | command: bash -c 'curl -sS https://getcomposer.org/installer | php && chmod +x composer.phar && mv composer.phar /usr/local/bin/composer' 86 | when: composer_check.stdout.find('composer') == -1 87 | 88 | - name: Set phpmyadmin webserver 89 | # TODO: how to skip this 90 | debconf: name='phpmyadmin' question='phpmyadmin/reconfigure-webserver' value='apache2' vtype='multiselect' 91 | - name: Set phpmyadmin dbconfig 92 | debconf: name='phpmyadmin' question='phpmyadmin/dbconfig-install' value='true' vtype='boolean' 93 | - name: Set phpmyadmin mysql admin user 94 | debconf: name='phpmyadmin' question='phpmyadmin/mysql/admin-user' value='root' vtype='string' 95 | - name: Set phpmyadmin mysql admin user password 96 | debconf: name='phpmyadmin' question='phpmyadmin/mysql/admin-pass' value='{{ mysql_root_pass }}' vtype='password' 97 | - name: Set phpmyadmin admin user password 98 | debconf: name='phpmyadmin' question='phpmyadmin/mysql/app-pass' value='{{ phpmyadmin_pass }}' vtype='password' 99 | - name: Set phpmyadmin admin user password confirm 100 | debconf: name='phpmyadmin' question='phpmyadmin/app-password-confirm' value='{{ phpmyadmin_pass }}' vtype='password' 101 | - name: Install phpmyadmin 102 | apt: 103 | name: phpmyadmin 104 | - name: Update hosts for phpmyadmin 105 | lineinfile: 106 | dest: /etc/hosts 107 | # NOTE: must use double quote https://github.com/ansible/ansible/issues/4818 108 | line: "127.0.0.1\t{{ phpmyadmin_host }}" 109 | - name: Copy nginx config for phpmyadmin 110 | template: 111 | src: /vagrant/templates/phpmyadmin.j2 112 | dest: /etc/nginx/conf.d/phpmyadmin.conf 113 | owner: root 114 | group: root 115 | # TODO: file mode 116 | notify: restart nginx 117 | 118 | - name: Install nvm for user vagrant 119 | become_user: "{{ nvm_user }}" 120 | git: repo=https://github.com/creationix/nvm.git dest=~/.nvm 121 | - name: Export NVM_DIR 122 | become_user: "{{ nvm_user }}" 123 | lineinfile: 124 | dest: ~/.bashrc 125 | line: "export NVM_DIR=$HOME/.nvm" 126 | create: yes 127 | - name: Add nvm.sh to bashrc 128 | become_user: "{{ nvm_user }}" 129 | lineinfile: 130 | dest: ~/.bashrc 131 | line: "[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads nvm" 132 | create: yes 133 | - name: Check if node is installed 134 | become_user: "{{ nvm_user }}" 135 | command: bash -c 'which node' 136 | register: node_check 137 | failed_when: False 138 | - name: Install latest node LTS 139 | become_user: "{{ nvm_user }}" 140 | # Thanks to https://truongtx.me/2015/11/02/ansible-install-and-work-with-nodejs-using-nvm 141 | command: bash -c '. ~/.nvm/nvm.sh; nvm install lts/*; nvm alias default lts/*' 142 | # FIXME: the check is not working, it still change every time run provision 143 | when: node_check.stdout.find('node') == -1 144 | 145 | # End of Installation 146 | -------------------------------------------------------------------------------- /templates/phpmyadmin.j2: -------------------------------------------------------------------------------- 1 | # FIXME: this configuration is not secure 2 | server { 3 | listen 80; 4 | root /usr/share/phpmyadmin/; 5 | index index.php; 6 | server_name {{ phpmyadmin_host }}; 7 | 8 | location ~ \.php($|/) { 9 | fastcgi_split_path_info ^(.+\.php)(.*)$; 10 | fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; 11 | fastcgi_index index.php; 12 | include /etc/nginx/fastcgi_params; 13 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 14 | } 15 | } 16 | --------------------------------------------------------------------------------