-
-
Notifications
You must be signed in to change notification settings - Fork 374
Developing Locally
This needs to be expanded
Shopify as of 2016 required all apps to be loaded over HTTPS. Theres several ways to accomplish this; wheather it be with WAMP/AMP, Docker, Vagrant, Homestead, etc. Below is a quick guide for setting up with Docker to develop an app locally.
This guide assumes you've setup Laravel locally and have this package installed successfully.
Versions:
The easeist way to develop locally with SSL is to self-sign a certificate.
Example:
openssl req -new -sha256 \
-key ssl/domain.key \
-subj "/C=US/ST=CA/O=Acme, Inc./CN=localhost.ssl" \
-reqexts SAN \
-config <(cat /etc/ssl/openssl.cnf \
<(printf "\n[SAN]\nsubjectAltName=DNS:localhost.ssl")) \
-out ssl/domain.csr
Replace localhost.ssl
with a domain you wish to use for the app. If you're on OSX, change /etc/ssl/openssl.cnf
with /System/Library/OpenSSL/openssl.cnf
.
This will save ssl/domain.key
and ssl/domain.csr
. You can then add the domain.csr
file to your OS/browser as a trusted root certificate so you do not receieve browser warnings.
As well, add 127.0.0.1 localhost.ssl
to your /etc/hosts
file.
Next, you can use Laravel's Homestead or a simple Docker setup to use the SSL certificate and accept HTTPS traffic.
After generating the above certificate into ssl
directory, and accepting it as a trusted root certificate, we can build a Docker setup to use it.
Create default.conf
in the root of your Laravel project with:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 302 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name _;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
add_header X-Frame-Option ALLOWALL;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header p3p 'CP="Not used"';
root /var/www/html/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
In the above, we are setting up PHP-FPM, certificate serving, redirecting :80 to :443, pointing root to Laravel's public
directory, and setting up some headers.
Create a docker-compose.yml
in the root of your Laravel project with:
nginx:
image: nginx:latest
ports:
- '8000:443'
volumes:
- $PWD/default.conf:/etc/nginx/conf.d/default.conf
- $PWD:/var/www/html
- $PWD/ssl:/etc/nginx/ssl
links:
- php
restart: always
php:
image: php:7-fpm
volumes:
- $PWD:/var/www/html
In the above we do the following:
- Pull the
nginx
image - Bind port 8000 on host to 443 on Docker
- Mount the
default.conf
we created earlier to Nginx - Mount our code to
/var/www/html
- Mount our certificates created previouly in
ssl
directory - Pull the
php
image - Mount our code to
/var/www/html
so PHP-FPM can see the code as well
You may optionally add in the MySQL or Postgres images for a database, if not, you can setup Laravel to use a SQLite file. Be sure to adjust your app's .env
file to use the SQLite file or other database credentials.
If you choose not to pull in a database image for Docker, its easy to just use SQLite.
touch databases/database.sqlite
and change .env
to have DB_CONNECTION=sqlite
You will now have a database to use.
Once above two steps are done, see the README.md
on installing this package.
You should now have:
- Package installed
- Self-signed certificate setup and installed
-
docker-compose.yml
file -
default.conf
file
When finished installing this package, run docker-compose up
.
You should be able to access https://localhost.ssl:8000/login
and see the app login screen.
Again, this is very basic and to be used as a guide. You can achieve the same results using Homstead, Vagrant, etc.
---- Coming soon ----
road map
Welcome to the wiki!
Please see the homepage for a list of relevant pages.