diff --git a/.travis.yml b/.travis.yml index 27672ef8..e1c5c653 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,15 @@ language: php sudo: false dist: trusty +cache: + - apt + addons: - postgresql: "9.5" + postgresql: "9.6" + apt: + packages: + - nginx + - realpath services: - postgresql @@ -33,6 +40,7 @@ install: - if [[ $setup = 'basic' ]]; then travis_retry composer install --no-interaction --prefer-dist; fi - if [[ $setup = 'stable' ]]; then travis_retry composer update --no-interaction --prefer-dist --prefer-stable; fi - if [[ $setup = 'lowest' ]]; then travis_retry composer update --no-interaction --prefer-dist --prefer-lowest --prefer-stable; fi + - travis/install-nginx.sh before_script: - psql -U travis -c 'create database travis_ci_test' @@ -43,7 +51,7 @@ before_script: - php artisan db:seed - php artisan token:generate - phantomjs --webdriver=127.0.0.1:9515 --webdriver-loglevel=ERROR & - - php artisan serve & + #- php artisan serve & - sleep 5 # Give artisan some time to start serving script: diff --git a/travis/default-site.tpl.conf b/travis/default-site.tpl.conf new file mode 100644 index 00000000..c0bb9b1f --- /dev/null +++ b/travis/default-site.tpl.conf @@ -0,0 +1,19 @@ +server { + listen 8000 default_server; + listen [::]:8000 default_server ipv6only=on; + + root {ROOT}/public; + + access_log /tmp/access.log; + error_log /tmp/error.log; + + location ~* "\.php(/|$)" { + include fastcgi.conf; + fastcgi_pass php; + } + + location / { + # First attempt to serve request as file, then as directory, then fall back to index.php. + try_files $uri $uri/ /index.php$is_args$args; + } +} diff --git a/travis/fastcgi.tpl.conf b/travis/fastcgi.tpl.conf new file mode 100644 index 00000000..28ccdeb6 --- /dev/null +++ b/travis/fastcgi.tpl.conf @@ -0,0 +1,39 @@ +fastcgi_param QUERY_STRING $query_string; +fastcgi_param REQUEST_METHOD $request_method; +fastcgi_param CONTENT_TYPE $content_type; +fastcgi_param CONTENT_LENGTH $content_length; + +fastcgi_param SCRIPT_NAME $fastcgi_script_name; +fastcgi_param REQUEST_URI $request_uri; +fastcgi_param DOCUMENT_URI $document_uri; +fastcgi_param DOCUMENT_ROOT $document_root; +fastcgi_param SERVER_PROTOCOL $server_protocol; +fastcgi_param HTTPS $https if_not_empty; + +fastcgi_param GATEWAY_INTERFACE CGI/1.1; +fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; + +fastcgi_param REMOTE_ADDR $remote_addr; +fastcgi_param REMOTE_PORT $remote_port; +fastcgi_param SERVER_ADDR $server_addr; +fastcgi_param SERVER_PORT $server_port; +fastcgi_param SERVER_NAME $server_name; + +# PHP only, required if PHP was built with --enable-force-cgi-redirect +fastcgi_param REDIRECT_STATUS 200; + +fastcgi_split_path_info ^(.+\.php)(.*)$; +fastcgi_param PATH_INFO $fastcgi_path_info; +#fastcgi_index index.php; +fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + +# fastcgi_intercept_errors on; +fastcgi_ignore_client_abort off; +fastcgi_connect_timeout 60; +fastcgi_send_timeout 1800; +fastcgi_read_timeout 1800; +fastcgi_buffer_size 128k; +fastcgi_buffers 4 256k; +fastcgi_busy_buffers_size 256k; +fastcgi_temp_file_write_size 256k; +fastcgi_keep_conn on; diff --git a/travis/install-nginx.sh b/travis/install-nginx.sh new file mode 100644 index 00000000..60ac410f --- /dev/null +++ b/travis/install-nginx.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +set -e +set -x + +DIR=$(realpath $(dirname "$0")) +USER=$(whoami) +PHP_VERSION=$(phpenv version-name) +ROOT=$(realpath "$DIR/..") +PORT=8000 +SERVER="/tmp/php.sock" + +function tpl { + sed \ + -e "s|{DIR}|$DIR|g" \ + -e "s|{USER}|$USER|g" \ + -e "s|{PHP_VERSION}|$PHP_VERSION|g" \ + -e "s|{ROOT}|$ROOT|g" \ + -e "s|{PORT}|$PORT|g" \ + -e "s|{SERVER}|$SERVER|g" \ + < $1 > $2 +} + +# Make some working directories. +mkdir "$DIR/nginx" +mkdir "$DIR/nginx/sites-enabled" +mkdir "$DIR/var" + +PHP_FPM_BIN="$HOME/.phpenv/versions/$PHP_VERSION/sbin/php-fpm" +PHP_FPM_CONF="$DIR/nginx/php-fpm.conf" + +# Build the php-fpm.conf. +tpl "$DIR/php-fpm.tpl.conf" "$PHP_FPM_CONF" + +# Start php-fpm +"$PHP_FPM_BIN" --fpm-config "$PHP_FPM_CONF" + +# Build the default nginx config files. +tpl "$DIR/nginx.tpl.conf" "$DIR/nginx/nginx.conf" +tpl "$DIR/fastcgi.tpl.conf" "$DIR/nginx/fastcgi.conf" +tpl "$DIR/default-site.tpl.conf" "$DIR/nginx/sites-enabled/default-site.conf" + +# Start nginx. +nginx -c "$DIR/nginx/nginx.conf" diff --git a/travis/nginx.tpl.conf b/travis/nginx.tpl.conf new file mode 100644 index 00000000..13a26ad4 --- /dev/null +++ b/travis/nginx.tpl.conf @@ -0,0 +1,52 @@ +error_log /tmp/error.log; +pid /tmp/nginx.pid; +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + # Set an array of temp and cache file options that will otherwise default to restricted locations accessible only to root. + client_body_temp_path /tmp/client_body; + fastcgi_temp_path /tmp/fastcgi_temp; + proxy_temp_path /tmp/proxy_temp; + scgi_temp_path /tmp/scgi_temp; + uwsgi_temp_path /tmp/uwsgi_temp; + + ## + # Basic Settings + ## + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + # server_tokens off; + # server_names_hash_bucket_size 64; + # server_name_in_redirect off; + include /etc/nginx/mime.types; + default_type application/octet-stream; + + ## + # Logging Settings + ## + access_log /tmp/access.log; + error_log /tmp/error.log; + + ## + # Gzip Settings + ## + gzip on; + gzip_disable "msie6"; + + ## + # Virtual Host Configs + ## + # include {DIR}/nginx/conf.d/*.conf; + include {DIR}/nginx/sites-enabled/*; + + upstream php { + server 127.0.0.1:{PORT}; + } +} diff --git a/travis/php-fpm.tpl.conf b/travis/php-fpm.tpl.conf new file mode 100644 index 00000000..fdbf2aa8 --- /dev/null +++ b/travis/php-fpm.tpl.conf @@ -0,0 +1,9 @@ +[global] + +[travis] +user = {USER} +listen = {PORT} +listen.mode = 0666 +pm = static +pm.max_children = 5 +php_admin_value[memory_limit] = 32M