Jump to content

Using DDEV for local ProcessWire development (tips & tricks)


bernhard

Recommended Posts

This thread is intended to be a collection of useful tips and tricks when developing PW sites using the awesome DDEV development environment.

First tip (and only issue I've had since almost a year) is how to prevent an endless redirect loop when using "force HTTPS" in htaccess: https://github.com/processwire/processwire-requests/issues/452

 

  • Like 2
Link to comment
Share on other sites

  • bernhard changed the title to Using DDEV for local ProcessWire development (tips & tricks)
  • 4 weeks later...

What would really be great is a tutorial on how to set up a project in DDEV, something I'm trying to figure out right now ?

Edit: Spoke too soon. This is so easy it sounds like a lie.

  1. `ddev config` - Choose PHP project
  2. `git clone https://github.com/processwire/processwire.git web` - Downloads PW into the 'web' directory
  3. `ddev launch` - Go through the config, enter db, db, db, db in the database step

Done

  • Like 4
Link to comment
Share on other sites

I have created an alias command to get the same settings for all my projects ? 

alias ddc='ddev config --php-version "8.1" --database "mysql:8.0" --webserver-type "apache-fpm"'

So for me its this:

  1. ddc --> setup a new ddev project
  2. git init --> initialise a new git repo
  3. git clone git@github.com:baumrock/RockShell.git
  4. cd RockShell
  5. php rockshell pw-install

I should maybe create an alias for that too ? 

  • Like 4
Link to comment
Share on other sites

  • 2 weeks later...

Having problems with laragon so decided to switch to ddev. Installed docker & ddev just fine. Then wanted to set it up with an existing project, rather than start from scratch.

So what I did was:

  • change to the project directory
  • ddev config
  • ddev start
  • imported the database (ddev import-db ...) using a copy downloaded from the live site

That all seemed to execute properly. Then I ran the url given by ddev and clearly the php was executed but the db could not be found:

Quote

Exception: SQLSTATE[HY000] [2002] No such file or directory (in wire/core/WireDatabasePDO.php line 509)

#0 wire/core/WireDatabasePDO.php (509): PDO->__construct('mysql:dbname=hi...

The dbname etc. were the details for the live site (although I was expecting it to look for the dev site details as the $config->paths->root had not changed) EDIT: under ddev it has changed, so I changed my test condition in config.php for the dev environment accordingly

Unfortunately, since laragon is not working any more (not php8.0 compatible and unable to upgrade) I couldn't get into phpmyadmin and export the database there).

Any ideas on how to hook everything back together, @bernhard, @heldercervantesor others?

EDIT: I see ddev changes all the database details to 'db'. I changed all the name, users etc to match, but still no luck.

Link to comment
Share on other sites

Update to the above post. I changed all the name/user details to the defaults:

	$config->dbName = 'db';
	$config->dbUser = 'db';
	$config->dbPass = 'db';
	$config->dbPort = '3306';

I realised that ddev assigns a dynamic db port so I added a static host_db_port: "3306" to .ddev/config.yaml.

I can access the db in phpMyAdmin  - and in the phpStorm database tool (now that it has a static port).

I added a var_dump of pdoConfig to check what PW is looking for, namely

array(5) { ["dsn"]=> string(40) "mysql:dbname=db;host=localhost;port=3306" ["user"]=> string(2) "db" ["pass"]=> string(2) "db" ["options"]=> array(2) { [3]=> int(2) [1002]=> string(16) "SET NAMES 'utf8'" } ["reader"]=> array(4) { ["dsn"]=> string(0) "" ["user"]=> string(0) "" ["pass"]=> string(0) "" ["options"]=> string(0) "" } }

This matches exactly the config data I enetered into phpStorm's database tool (host: localhost, port:3306, user:db, password:db, database:db) which connects sucessfully.

But I still get this error

Quote

Excuse me… Error: Exception: SQLSTATE[HY000] [2002] No such file or directory (in wire/core/WireDatabasePDO.php line 511)

#0 wire/core/WireDatabasePDO.php (511): PDO->__construct('mysql:dbname=db...', 'db', 'db', Array)

where the last array is ["options"] in the var_dump above.

Any ideas? ?

Link to comment
Share on other sites

9 hours ago, MarkE said:

I wonder if we could contribute a cms QuickStart for ddev. It would be nice to have ProcessWire listed there!

Would be great to have ProcessWire listed to get some visibility! Though I'm not sure what benefits those quickstart options have?

Link to comment
Share on other sites

12 minutes ago, bernhard said:

I'm not sure what benefits those quickstart options have?

Technically, not a lot, since the generic QuickStart works well. The main reason would be for visibility. Someone installing ddev might be prompted to think about ProcessWire as a solution. 

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Well, late to the party, having been a long-time user of devilbox for local docker-based development. However, the need to support distinct per-project tech stack differences has forced a move away from devilbox to ddev and, apart from the need to make a few local .env changes, it's working out really well so far. Highly recommend it if you haven't tried it out yet.

 

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

Just tried out ddev for the first time and it looks like it is working really well.  Thanks @bernhard and others for contributing to this thread.  Ddev looks way easier then my previous setup based on homebrew https://getgrav.org/blog/macos-monterey-apache-multiple-php-versions.

Here's the steps I had to take to get started with ddev.  I'm writing it here so that other people don't have to spend much time with this.

  1. `ddev config` - Choose `php` project.  Docroot location = `wwwroot` and let it create the folder
  2. `git clone --branch dev https://github.com/processwire/processwire.git wwwroot` - Downloads the latest PW dev branch into the 'wwwroot' directory
  3. `ddev start` and open the site's url.  It will look something like https://pwtest.ddev.site/
  4. Go through Processwire Installer and enter the configurations
  5. The Processwire installer might complain about " Unable to determine if Apache mod_rewrite (required by ProcessWire) is installed. On some servers, we may not be able to detect it until your .htaccess file is place. Please click the 'check again' button at the bottom of this screen, if you haven't already." - Just click the "Continue to Next Step" button
  6. `ddev describe` - Shows the name, urls, and ports of the running servers
  7. Enter the following in the Processwire Installer
  8. DB Name = db
  9. DB User = db
  10. DB Pass = db
  11. DB Host = db
  12. DB Port = 3306
  13. Character Set = utf8mb4 - if you want emojis?
  14. DB Engine = InnoDB
  15. Done.  Just follow the rest of the prompts to access your site
On 9/15/2022 at 1:59 AM, bernhard said:

Would be great to have ProcessWire listed to get some visibility! Though I'm not sure what benefits those quickstart options have?

Maybe it could automatically create a site/config-ddev.php that gets automatically included into site/config.php?  https://ddev.readthedocs.io/en/stable/users/topics/cms_specific_help/ and https://ddev.readthedocs.io/en/stable/developers/project-types/.

Something like:

// Automatically generated include for settings managed by ddev.
if (file_exists(__DIR__ . '/config-ddev.php') && getenv('IS_DDEV_PROJECT') == 'true') {
  include __DIR__ . '/config-ddev.php';
}

Looks like all of the custom CMS projects are located at https://github.com/drud/ddev/tree/master/pkg/ddevapp

After looking at some of the .go files, it looks like it can get a little complex? https://github.com/drud/ddev/blob/master/pkg/ddevapp/drupal.go

Oh well.  Now it's time to have some fun with ddev and Processwire!

  • Like 3
Link to comment
Share on other sites

Is DDEV "supposed to be" used on mac or linux ? On windows you need either wsl2 or the docker desktop. On windows, can anyone tell me why Laragon is not by far easier to use than DDEV when it comes to switching between php versions ? Is it about working in virtual environments ? With virtualbox it can just as well be extended, version controlled, and shared.

Link to comment
Share on other sites

3 hours ago, gmclelland said:

Maybe it could automatically create a site/config-ddev.php that gets automatically included into site/config.php?  https://ddev.readthedocs.io/en/stable/users/topics/cms_specific_help/ and https://ddev.readthedocs.io/en/stable/developers/project-types/.

That's one of the things that "php rockshell pw-setup" does.

6 minutes ago, pwired said:

Is DDEV "supposed to be" used on mac or linux ? On windows you need either wsl2 or the docker desktop. Can anyone tell me why Laragon is not by far easier to use than DDEV ?

DDEV is supposed to be used with docker, so you can use it on any OS. You'll get exactly the same environment no matter who is working on the project - that's especially great in teams. Laragon is not by far easier to use but a lot easier to setup. But you only need to setup DDEV once. Then it runs and runs and runs. And with ddev setting up a new project is by far easier then it was with Laragon for me. It's just "ddev config" and you are done.

The biggest benefit for me is that you get a real unix dev environment. So if you have some special need for your server (eg creating thumbnails from PDF via poppler-utils you are out of luck with laragon). With DDEV you simply add poppler-utils to the config of the web container and you can develop everything locally and it will work the same on the live server.

Also the config of the project can be added to the project's git repo. That means everybody can just do a git pull && ddev start and will have a working version of the project with all the settings and tools needed for it to run. You can't do that with laragon.

  • Like 5
Link to comment
Share on other sites

Quote

Also the config of the project can be added to the project's git repo. That means everybody can just do a git pull && ddev start and will have a working version of the project with all the settings and tools needed for it to run. You can't do that with laragon.

Thanks for posting. Yes I figured it has to do with this flexibility. Virtualbox and even Vmware are poor (bloated) virtual environments when it comes to dev. I tried Vagrant in the past but didn't like it. I already have linux on a second partition so I will try ddev or something like devilbox.

Link to comment
Share on other sites

23 hours ago, gmclelland said:

DB Host = db

Interesting... for me it's always
$config->dbHost = 'ddev-projectname-db';

20 hours ago, pwired said:

Is DDEV "supposed to be" used on mac or linux ?

You can use it on both actually quite easily. The benefit is (as @bernhard already mentioned) it's Docker-based and you could move on to almost any other machine just with your local config.
BUT on Linux it depends a bit on your distro as Arch doesn't has the needed packages - even in the AUR they are missing. Ubuntu, Debian and Fedora/CentOS work totally fine.

One thing I learned the hard way... talk to your real host to know what they are using so you can create a matching DDEV host with PHP, MySQL/MariaDB versions matching that exact provider.
That makes things way easier sometimes.

20 hours ago, pwired said:

On windows, can anyone tell me why Laragon is not by far easier to use than DDEV when it comes to switching between php versions ?

I can't as Laragon is one of most wonderful dev-setups you can use in my opinion. Install and go from there.
It was always a real pleasure to use it and I never ever had any issues with it by itself. Yet... sometimes (as mentioned above) the real hosting company didn't match up with the Laragon setup which caused minor issues at some point - it's years back so I don't remember the details anymore.

  • Like 1
Link to comment
Share on other sites

On 9/14/2022 at 11:42 AM, MarkE said:

Unfortunately, since laragon is not working any more (not php8.0 compatible and unable to upgrade)

That's weird. Laragon keeps working fine for me, with several PHP versions, one of them being 8.1.8.

On 9/14/2022 at 11:42 AM, MarkE said:

I couldn't get into phpmyadmin and export the database there

There are far better tools than phpMyAdmin. Try HeidiSQL

Link to comment
Share on other sites

Quote

I had problems with laragon and the support is not great.

So how is that ? They have lots of docs, articles and vids which you don't even need because it works out of the box
and the interface is self explaining. With version 5.x they did a great job to make it work with php8.x
Frameworks, Addons, libs, third party tools and features are conveniently bundled in one directory (c:/laragon/bin)
e.g. easy switch between php5.x 7.x and 8.x for both old and new projects.

By the way ... did someone mention that Docker Desktop is no longer free like it obvious was before ?
I don't mean if you are running a company with 250+ employees

If you develop closed source or proprietary software with Docker Desktop it requires a paid subscription for professional use.
Selling Websites or Apps developed With Docker Desktop is commercial use and needs a Docker Pro license.

The Docker engine is free without any hassle so linux might be the better choice of something like Lazydocker ?

 

Link to comment
Share on other sites

27 minutes ago, pwired said:

By the way ... did someone mention that Docker Desktop is no longer free like it obvious was before ?
I don't mean if you are running a company with 250+ employees

If you develop closed source or proprietary software with Docker Desktop it requires a paid subscription for professional use.
Selling Websites or Apps developed With Docker Desktop is commercial use and needs a Docker Pro license.

Docker FAQ seems to disagree:

Quote

Docker Desktop may be used for free as part of a Docker Personal subscription for:

  • Small companies (less than 250 employees AND less than $10 million in annual revenue)

This is further clarified in the Docker Subscription Service Agreement:

Quote

(a) The Docker Desktop component of the Service at the level of the Personal Offering (as described on the Pricing Page) is further restricted to: (i) your “Personal Use”, (ii) your “Educational Use”, (iii) your use for a non-commercial open source project, and (iv) your use in a “Small Business Environment”. [...] (iii) a “Small Business Environment” is a commercial undertaking with fewer than 250 employees and less than US $10,000,000 (or equivalent local currency) in annual revenue; 

The Service Agreement is a bit messy (kind of seems like they might've updated one section and forgot another, so numerals are not in sync), but at least based on this the small business exception is still in place and applies to the desktop component as well 🙂

Link to comment
Share on other sites

11 hours ago, MarkE said:

Any more context and documentation for that teaser?

https://github.com/baumrock/RockShell#how-to-use-rockshell

It's a command line interface for installing PW (php rockshell pw-install) and it also has an opinionated setup command (php rockshell pw-setup). Creating commands is very easy. You can list all available commands via "php rockshell"

58 minutes ago, pwired said:

By the way ... did someone mention that Docker Desktop is no longer free like it obvious was before ?
I don't mean if you are running a company with 250+ employees

If you develop closed source or proprietary software with Docker Desktop it requires a paid subscription for professional use.
Selling Websites or Apps developed With Docker Desktop is commercial use and needs a Docker Pro license.

The Docker engine is free without any hassle so linux might be the better choice of something like Lazydocker ?

I'm afraid I don't understand what you want to say. But here's the conditions from their FAQ page:

Quote

Docker Desktop may be used for free as part of a Docker Personal subscription for:

  • Small companies (less than 250 employees AND less than $10 million in annual revenue)
  • Personal use
  • Education and learning (as a student or instructor, either in an academic or professional environment)
  • Non-commercial open source projects

teppo was faster 🙂 

  • Like 2
Link to comment
Share on other sites

I will be glad if I am wrong and you guys are right that Docker Desktop is free for commercial use.

I was reading from here:
https://www.docker.com/pricing/faq/

Docker Desktop may be used for free as part of a Docker Personal subscription for:
-Personal use
-Education and learning (as a student or instructor, either in an academic or professional environment)
-Non-commercial open source projects

So that means a Docker Personal subscription is needed, right ?

-Personal use I understood as not commercial use but I must be wrong about that.

 

Link to comment
Share on other sites

See the first bullet point under "Docker desktop may be used for free as part of a Docker Personal subscription for":

Quote

Docker Desktop may be used for free as part of a Docker Personal subscription for:

  • Small companies (less than 250 employees AND less than $10 million in annual revenue)

This is repeated in other documents, including the service agreement. You don't have to (and can't, that would be quite impossible) fill all the conditions for free use, just one, and use within "small companies" (or "small businesses") is one of them.

  • Like 1
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...