-4

How can I create a laravel 5 dev site with DDEV ? (see https://github.com/drud/ddev/issues/898#issuecomment-463203604)

  • 2
    To make a great contribution here on Stack Overflow you'll want to give a full question (and optionally answer it yourself). But people don't just want a link to somewhere else, they want a robust question and a great answer. I know this is your first time here, but go ahead and update this question to be what you want it to be, and if you know a good answer, add the answer yourself. – rfay Sep 18 '19 at 02:03

2 Answers2

2

I created a Laravel 5 dev site on Win10 using DDEV and Docker Desktop with Linux containers. Note that it was not necessary to install composer on Win10 since composer installed by DDEV in the web container was used instead.
Here are the steps:

  • Created a d:\laravel5 folder

  • Opened a PowerShell window as administrator and switched to this folder

  • Ran ddev config and selected the default "php" project type:

PS D:\laravel5> ddev config
Creating a new ddev project config in the current directory (D:\laravel5)
Once completed, your configuration will be written to D:\laravel5\.ddev\config.yaml

Project name (laravel5):

The docroot is the directory from which your site is served.
This is a relative path from your project root at D:\laravel5
You may leave this value blank if your site files are in the project root
Docroot Location (current directory):
Found a php codebase at D:\laravel5.
Project Type [drupal6, drupal7, drupal8, wordpress, typo3, backdrop, php] (php):
Project type has no settings paths configured, so not creating settings file.
Configuration complete. You may now run 'ddev start'.
Instrumentation is opted in, but SentryDSN is not available.
Instrumentation is opted in, but SegmentKey is not available.
PS D:\laravel5>

DDEV created a d:\laravel5\.ddev folder that will be modified with the addition of 4 files before running the ddev start command.

Note that for the DDEV "php" project type, the Laravel 5 PHP prerequisites are all satisfied
PHP >= 7.2.0
BCMath PHP Extension
Ctype PHP Extension
JSON PHP Extension
Mbstring PHP Extension
OpenSSL PHP Extension
PDO PHP Extension
Tokenizer PHP Extension
XML PHP Extension

  • Created the file .ddev\config.laravel5.yaml with content
docroot: blog/public
  • Created the file .ddev\docker-compose.laravel5.yaml with content
version: '3.6'

services:
  web:
    environment:
      - DB_HOST=db
      - DB_PORT=3306
      - DB_DATABASE=db
      - DB_USERNAME=db
      - DB_PASSWORD=db
  • Created the file .ddev\nginx-site.conf with content
# ddev default config

# You can override ddev's configuration by placing an edited copy
# of this config (or one of the other ones) in .ddev/nginx-site.conf
# See https://ddev.readthedocs.io/en/stable/users/extend/customization-extendibility/#providing-custom-nginx-configuration

## Set https to 'on' if x-forwarded-proto is https
#map $http_x_forwarded_proto $fcgi_https {
#    default off;
#    https on;
#}

server {

    listen 80;
    server_name laravel5.ddev.site;
    # The WEBSERVER_DOCROOT variable is substituted with
    # its value when the container is started.
    root $WEBSERVER_DOCROOT;

    include /etc/nginx/monitoring.conf;
    include /mnt/ddev_config/nginx/*.conf;

}
  • Created the file .ddev\nginx\laravel5.conf with content:
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    ## Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
    #sendfile off;
    error_log /dev/stdout info;
    access_log /var/log/nginx/access.log;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        #fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
  • Ran ddev start:
PS D:\laravel5> ddev start
Starting laravel5...
Using custom nginx configuration in nginx-site.conf
Using custom nginx partial configuration: [D:\laravel5\.ddev\nginx\laravel5.conf]
Custom configuration takes effect when container is created,
usually on start, use 'ddev restart' if you're not seeing it take effect.
Creating volume "laravel5-mariadb" with default driver
Building db
Building web
Creating ddev-laravel5-db ... done                                                                                                     Creating ddev-laravel5-dba ... done                                                                                                    Creating ddev-laravel5-web ... done                                                                                                    
ddev-router is up-to-date
Successfully started laravel5
Project can be reached at https://laravel5.ddev.site https://127.0.0.1:32789
Instrumentation is opted in, but SentryDSN is not available.
Instrumentation is opted in, but SegmentKey is not available.
PS D:\laravel5>
  • Ran ddev ssh and executed the following shell commands in the web container
cd /var/www/html
composer create-project --prefer-dist laravel/laravel blog "5.8.*"

The output was as follows:

freefall322@laravel5-web:/var/www/html$ cd /var/www/html
freefall322@laravel5-web:/var/www/html$ composer create-project --prefer-dist laravel/laravel blog "5.8.*"
Installing laravel/laravel (v5.8.35)
  - Installing laravel/laravel (v5.8.35): Loading from cache
Created project in blog
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 80 installs, 0 updates, 0 removals
  - Installing symfony/polyfill-ctype (v1.12.0): Loading from cache
  - Installing phpoption/phpoption (1.5.0): Loading from cache
  - Installing vlucas/phpdotenv (v3.6.0): Loading from cache
  - Installing symfony/css-selector (v4.3.4): Loading from cache
  - Installing tijsverkoyen/css-to-inline-styles (2.2.1): Loading from cache
  - Installing symfony/polyfill-php72 (v1.12.0): Loading from cache
  - Installing symfony/polyfill-mbstring (v1.12.0): Loading from cache
  - Installing symfony/var-dumper (v4.3.4): Loading from cache
...
(skipping many lines of output)
...
phpunit/phpunit suggests installing phpunit/php-invoker (^2.0)
phpunit/phpunit suggests installing ext-xdebug (*)
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
> @php artisan key:generate --ansi
Application key set successfully.
freefall322@laravel5-web:/var/www/html$  
Route::get('/foo', function () {
    //
    try {
        DB::connection()->getPdo();
        if(DB::connection()->getDatabaseName()){
            echo "Yes! Successfully connected to the DB: " . DB::connection()->getDatabaseName();
        }else{
            die("Could not find the database. Please check your configuration.");
        }
    } catch (\Exception $e) {
        die("Could not open connection to database server.  Please check your configuration.");
    }
});

Note: to install latest version of Laravel, instead of

composer create-project --prefer-dist laravel/laravel blog "5.8.*"

remove the version specifier and just use

composer create-project --prefer-dist laravel/laravel blog

I tried this today and it installed Laravel 6.0

0

You can create a Laravel 5 dev site using ddev as below:

mkdir projectName
cd projectName
ddev config --project-type=laravel --docroot=public --create-docroot
ddev start
ddev composer create --prefer-dist laravel/laravel:5.8.*
ddev exec "cat .env.example | sed  -E 's/DB_(HOST|DATABASE|USERNAME|PASSWORD)=(.*)/DB_\1=db/g' > .env"
ddev exec "php artisan key:generate"
ddev launch

See the ddev Laravel quick start documentation.

B.K
  • 847
  • 10
  • 6