elementor / wp2static

WordPress static site generator for security, performance and cost benefits
https://wp2static.com
The Unlicense
1.42k stars 266 forks source link

crawlPort not being honored #443

Closed dnrce closed 3 years ago

dnrce commented 5 years ago

I am running WordPress in a docker container with container port 80 mapped to host port 8080. The site URL is http://localhost:8080. I have configured the crawl port in WP2Static to 80, yet I see the following error during crawling:

cURL error:Failed to connect to localhost port 8080: Connection refused

If my understanding of crawlPort is correct, I expect WP2Static to use port 80 instead of trying 8080.

Am I doing something wrong or is this a bug? Thanks!

wpjesus-alt commented 4 years ago

You can solve this by keeping the ports the same, and specifying a new IP address instead.

If you are using docker-compose.yml, instead of

ports:

  • '8080:80'
  • '4430:443'

You could do:

ports:

  • '127.0.0.2:80:80'
  • '127.0.0.2:443:443'

And for each subsequent site you spin up, use 127.0.0.3, 127.0.0.4 etc

Make sure in wp-config.php, you set the following

if ( defined( 'WP_CLI' ) ) { $_SERVER['HTTP_HOST'] = '127.0.0.2';

cdeadspine commented 3 years ago

I can't find any information anywhere about this "crawlport" setting. I am trying to run bitnami/helm chart in kubernetes, and the wordpress installation doesnt really know that nginx is running on another port. The crawl stage is using the wrong port, and I can't edit the wp-config.php apparently.

Is there any way to set this crawlport setting from wp cli?

john-shaffer commented 3 years ago

WP2Static 7 doesn't have a crawl port setting currently. If you'd like to add one, then it could be added to https://github.com/leonstafford/wp2static-addon-advanced-crawling

IIRC, WP2Static 6 had this settting but has been renamed to https://github.com/leonstafford/static-html-output. You might have better luck with that.

leonstafford commented 3 years ago

Yep, closing this off. Need to serve WP from the same port as is defined in your Site URL admin setting, then will be fine.

A new simple way to host local dev sites has been born since: https://lokl.dev

ghost commented 8 months ago

For anyone experiencing this issue, do something like this:

wp-config.php (WARNING: inside GitHub actions, need to use host-gateway instead of host.docker.internal)

// ...
if( empty( $_SERVER['SERVER_NAME'] ) ) {
$_SERVER['SERVER_NAME'] = "host.docker.internal"; // inside GitHub actions, need to use `host-gateway`
}
if ( empty($_SERVER['HTTP_HOST']) ) {
$_SERVER['HTTP_HOST'] = "host.docker.internal"; // inside GitHub actions, need to use `host-gateway`
}
define( 'WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] );
define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] );
// ...

docker-compose.yaml


# https://medium.com/codex/how-to-dockerize-your-wordpress-site-73adff9db697
version: "3.8"
services:
db:
image: mariadb:10.5
restart: always
volumes:
- ./db:/var/lib/mysql
ports:
- '3306:3306'
healthcheck:
test: [ "CMD", "/usr/local/bin/healthcheck.sh", "--su-mysql", "--connect", "--innodb_initialized" ]
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress

wordpress: image: wordpress:6.4 restart: always depends_on: db: condition: "service_healthy" ports:

volumes: db: wordpress:


> ./github/workflows/build.yaml
```yaml
name: Build
on:
  push:
jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:

      - name: checkout repository
        uses: actions/checkout@v4

      - name: start services
        run: "docker compose up -d"

        # https://wp2static.com/developers/wp-cli/
      - name: set deployment url
        run: "docker compose run --rm wp-cli wp2static options set deploymentURL https://example.com"

      - name: detect
        run: "docker compose run --rm wp-cli wp2static detect"

      - name: crawl
        run: "ls -la ./wordpress && chmod -R 777 ./wordpress && ls -la ./wordpress && docker compose run --rm wp-cli wp2static crawl"

      - name: post-process
        run: "docker compose run --rm wp-cli wp2static post_process"