From e3ab75e908fa1f112f289903a4a34a74e617ec76 Mon Sep 17 00:00:00 2001 From: Eelco Maljaars Date: Tue, 12 Jun 2018 06:56:05 +0200 Subject: [PATCH] Basic vagrant setup to allow local development in a virtual machine --- README.md | 17 +++++++++++- Vagrantfile | 66 ++++++++++++++++++++++++++++++++++++++++++++++ vagrant/fpm.conf | 24 +++++++++++++++++ vagrant/nginx.conf | 35 ++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 Vagrantfile create mode 100644 vagrant/fpm.conf create mode 100644 vagrant/nginx.conf diff --git a/README.md b/README.md index c6ea6e002..b8f5a6ae3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,19 @@ # PixelFed Federated Image Sharing -> This project is still in active development and not yet ready for use. \ No newline at end of file +> This project is still in active development and not yet ready for use. + +## Creating a local dev environment using Vagrant + +Prerequisits : + - version of vagrant (vagrantup.com) + - version of virtualbox 5.x + - at least 2 GB of RAM to spare + +Setup : + - download and install both vagrant and virtualbox + - run 'vagrant up' from the root of te repository + - after succesfull deployment, access pixelfed at + http://127.0.0.1:8080 + + diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 000000000..0b5121621 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,66 @@ + +# Thank You StackOverflow! +# http://stackoverflow.com/questions/26811089/vagrant-how-to-have-host-platform-specific-provisional-step +module OS + def OS.windows? + (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil + end + + def OS.mac? + (/darwin/ =~ RUBY_PLATFORM) != nil + end + + def OS.unix? + !OS.windows? + end + + def OS.linux? + OS.unix? and not OS.mac? + end +end + + +Vagrant.configure("2") do |config| + config.vm.box = "ubuntu/bionic64" + + #if OS.unix? + # config.vm.synced_folder ".", "/vagrant", type: "nfs" + #end + + config.vm.define "pixelfed" + config.vm.hostname = "pixelfed.local" + + + config.vm.provision :shell do |shell| + shell.inline = " + apt-get update && apt-get -y upgrade && \ + apt-get -y install php7.2-fpm php7.2-gd php7.2-mbstring php-imagick \ + php7.2-mysql mysql-server-5.7 redis-server \ + graphicsmagick php-json php-services-json jpegoptim nginx-full \ + optipng pngquant gifsicle composer && \ + cd /vagrant && \ + su vagrant -c 'composer install' && cp .env.example .env && \ + mysql -e 'create database homestead' && \ + mysql -e \"grant all on homestead.* to 'homestead'@'localhost' identified by 'secret'\" && \ + cp /vagrant/vagrant/fpm.conf /etc/php/7.2/fpm/pool.d/pixelfed.conf && \ + systemctl restart php7.2-fpm && \ + cp /vagrant/vagrant/nginx.conf /etc/nginx/sites-available/pixelfed.conf && \ + rm /etc/nginx/sites-enabled/default && \ + ln -s /etc/nginx/sites-available/pixelfed.conf /etc/nginx/sites-enabled/ && \ + systemctl restart nginx && \ + php artisan key:generate && php artisan storage:link && \ + php artisan migrate && php artisan horizon && \ + php artisan serve --host=localhost --port=80 + " + + end + + config.vm.provider "virtualbox" do |v| + v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] + v.customize ["modifyvm", :id, "--memory", "2048"] + end + + config.vm.network :forwarded_port, guest: 80, host: 8080 +end + + diff --git a/vagrant/fpm.conf b/vagrant/fpm.conf new file mode 100644 index 000000000..5ad9ccd89 --- /dev/null +++ b/vagrant/fpm.conf @@ -0,0 +1,24 @@ +[pixelfed] +listen = 127.0.1.1:9000 +listen.backlog = -1 +user = vagrant +group = vagrant +pm = dynamic +pm.max_children = 50 +pm.start_servers = 5 +pm.min_spare_servers = 5 +pm.max_spare_servers = 35 +pm.process_idle_timeout = 10s +pm.max_requests = 0 +ping.response = pong +access.log = /var/log/fpm.log +access.format = "%R - %u %t \"%m %r\" %s" +request_terminate_timeout = 0 +request_slowlog_timeout = 0 +slowlog = /var/log/fpm-pixelfed-slow.log +chdir = /vagrant/public +catch_workers_output = yes +php_admin_value[post_max_size] = 25M +php_admin_value[short_open_tag] = On +php_admin_value[upload_max_filesize] = 25M + diff --git a/vagrant/nginx.conf b/vagrant/nginx.conf new file mode 100644 index 000000000..0ae83d00f --- /dev/null +++ b/vagrant/nginx.conf @@ -0,0 +1,35 @@ +server { + listen *:80; + listen [::]:80 ; + + server_name pixelfed.local; + + gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; + + index index.html index.htm index.php; + + access_log /var/log/nginx/pixelfed.local-plain.access.log combined; + error_log /var/log/nginx/pixelfed.local-plain.error.log; + + location / { + root /vagrant/public; + index index.html index.htm index.php; + try_files $uri $uri/ /index.php?q=$uri&$args; + } + + location ~ \.php$ { + root /vagrant/public/; + include /etc/nginx/fastcgi.conf; + + fastcgi_pass 127.0.1.1:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_buffer_size 32k; + fastcgi_buffers 16 16k; + fastcgi_connect_timeout 3m; + fastcgi_read_timeout 3m; + fastcgi_send_timeout 3m; + } + +} +