Configuration for local wordpress development using docker - wordpress

I'm new to Wordpress development (and especially Apache web server configuration) and I'm having trouble configuring and understanding the configuration for a local Wordpress environment using Docker.
I expose ports 8080 and 443 from the Wordpress docker image.
ports:
- 8080:80
- 443:443
It runs, connects to the database and is available at http://localhost:8080.
The urls in the database (local copy of production db) point to https://example.com and I therefore get quite a lot of CORS errors for scripts and images etc. All the links also point to the production site and I am thus unable to navigate the local version of the site.
How should I configure the .htaccess and wp-config.php file in order to be able to:
Run the site on localhost:8080 without being redirected to https://example.com on every link I click.
Run the site at https://localhost (configure redirects over https)
Thirdly I would also like to understand what does define('WP_SITEURL', 'http://'. $_SERVER['SERVER_NAME']); and define('WP_HOME', 'http://'. $_SERVER['SERVER_NAME']); actually do, i.e. what happens internally when this is set and how should I configure this correctly in my case.
It doesn't really help my understanding that WP_SITEURL points to where the site is located and WP_HOME is where the user points his browser to when accessing your site.
Also how does <VirtualHost>...</VirtualHost> fit into this, can this help?
I would appreciate any help pointing me in the right direction to understand the core principles better.

Go to the mysql database using phpmyadmin or any other tool you like. Then go to 'wp_options' table and change values of options 'siteurl' & 'home' to "localhost:8080"

Related

Wordpress styles dont load on ddev ngrok live link

I have setup a simple wordrpress environment with ddev.
I am trying to use the ddev share function which should give out
a live preview of the local WP site but when I try visiting the site from another
computer on a different ethernet then the site loads up, all in regards to html and some
primitive css but not the whole thing.
Locally ofcourse everything loads well.
In my console of the ngrok site I get various warnings like such:
Loading failed for the <script> with source “https://mysite.ddev.site:8443/wp-includes/js/jquery/jquery.min.js?ver=3.5.1”.
Note, the "mysite.ddev..." is the link to my local environment, So my guess is that this is to do with something regarding relative/abs urls, but I am unsure on how to fix this
I reffered to this post from 5 years ago which kind of touches on the subject.
I installed "Absolute Relative URLS" but that didnt solve the problem.
The problem with WordPress is that it embeds static URLs right into the database, so it's far harder to use in situations where you either change the hostname or do anything else. This is a significant problem with WordPress, and there are many workarounds, but not very satisfactory ones.
The article DDEV share: Sharing a DDEV-Local project with other collaborators in real time explains how to use a stable subdomain and do a search-replace.
WordPress only has the one base URL, but the wp command is built into DDEV-Local’s web container.
This set of steps assumes an ngrok subdomain of “wp23” and a starting URL of “https://wordpress.ddev.site“.
Configure .ddev/config.yaml to use a custom subdomain: ngrok_args: --subdomain wp23
Make a backup of your database with ddev export-db or ddev shapshot
Edit wp-config-ddev.php (or whatever your config is) to change WP_HOME, for example, define('WP_HOME', 'https://wp23.ngrok.io');
ddev ssh
wp search-replace https://wordpress.ddev.site https://wp23.ngrok.io
(assuming your project is configured for https://wordpress.ddev.site and your ngrok_args are configured for the wp23 subdomain)
Now ddev share
After a bit experimentation I've found a solution.
This post is a bit old thus DDEV has added some additional
upgrades to it's Wordpress Environment, this solution is tested on:
ddev -v:
ddev version v1.16.7
Solution:
Install and Activate Relative-Url Plugin
For good measures, restart the DDEV site ddev restart
Into the terminal Write:
ngrok http -host-header=rewrite .ddev.site
If you're not sure what your projects/site name is, use
ddev describe
and underneath the URLS the first link that will lead you to your
localhost site should be the URL you insert into your ngrok rewrite

Wordpress wp-admin Redirects to EC2 domain

I'm trying to install my wordpress to AWS EC2.
I created my EC2 instance and send files to that. (and instance domain has ben blablabla.eu-west-1.compute.amazonaws.com)
I used aws certificate manager for my domain.
I used cloudfront for using ssl certificate and; values are:
origin: blablabla.eu-west-1.compute.amazonaws.com
cnames: mysite.com
But when I connect to mysite.com/wp-admin it redirects me to blablabla.eu-west-1.compute.amazonaws.com.
Yes, I tried to change siteurl and home variables. And it doesnt make any changes.
And other hand; when I try to connect with "mysite.com" it converts all files to http (buy when I try to connect wit blabla.eu... all files are https)
What should I make?
Can be various things but I assume (based on previous experience) that some strings in Wordpress still contain mysite.com.
Before you go any further, it's worth to note that you can migrate your domain mysite.com to cloudfront/ec2/acm.
But if you want to just switch to another domain what I usually do is that I install wordpress CLI https://wp-cli.org/ and then I run wp-cli search-replace mysite.com blablabla.eu-west-1.compute.amazonaws.com --all-tables. It's good to have a backup just in case something went wrong, but this worked for me multiple times without any issues.

Migrating Site To Digital Ocean and having trouble with redirecting to HTTPS

I am migrating my site to digital ocean and I am having an issue with Https. I have moved the directory and the apache2 config file and mysql database. I believe I set everything up correctly but now I want to test it. I have edited my /etc/hosts file with my new ip and sitename.com. However when I try to go to my browser and look to see if the site works it keeps trying to redirect me to the https version of my site.
I have tried going to chrome://net-internals/#hsts and deleting the site but it still redirects to https. How can I test my site without being redirected to the still hosted version of my site?
Thanks!
Aside of the wp_options field, WordPress stores lot's of links 'hard-coded' which all will contain the https. You would need to do a full search and replace on the database, but be aware of serialized stuff. To to safely perform a search and replace you could use a program found on: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
Works like a charm.
Another way is by using wpcli if you have commandline access and wpcli is available. From the command line go to your root directory (containing the index.php) and type:
wp search-replace https://www.your-domain.example http://www.your-domain.example
Or type:
wp search-replace https://your-domain.example http://your-domain.example
Based on your setup up course.
Always make a full backup of your database before performing these actions, so you can restore if any problems occur.

Unable to successfully change wordpress site URL

I'm trying to set up Wordpress with Multisite, and the first thing I'm trying to do after getting the Bitnami AMI running on an EC2 host is assign an Elastic IP. However, as soon as I assign this, I'm unable to get to my Wordpress login page due to redirect issues.
When I try to go to my new URL of http://ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com, I get redirected to http://ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com/wp-signup.php?new=ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com, with a redirect loop error shown by my browser. (The IP address, noted with x's, is the same in all 3 cases).
Also, as expected, my apache access_log spits out 20 of the following lines when I try to access my site:
[05/Jun/2016:19:56:41 +0000] "GET /wp-signup.php?new=ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com HTTP/1.1" 302 -
Things that do work
Before I assign the Elastic IP, I can access the Wordpress site from http://ec2-yy-yy-yy-yy.us-west-2.compute.amazonaws.com, as long as I dont make any changes to the site URL after spinning up the EC2 instance with the Bitnami Wordpress AMI.
After assigning the Elastic IP, I can SSH into the EC2 instance with both the new IP and the corresponding *.compute.amazonaws.com hostname.
Things I tried
Following these steps, I've...
Updated DOMAIN_CURRENT_SITE in my wp-config.php, as well as updated site_url and home to match the new hostname.
Added WP_HOME and WP_SITEURL to my wp-config.php
Added the RELOCATE flag
None of those appear to fix the redirection issue.
Aha - I found another link that states migrating a Multisite setup is a bit more involved, and requires searching through all database tables for any references to the old hostname:
http://codex.wordpress.org/Moving_WordPress
Searching through all the tables in phpmyadmin... I did find some more references! After updating all of these, I can now get to my site using the new Elastic IP.
Bitnami stacks come with a tool to automatically configure the machine IP of the installation. In the case of WordPress, you just need to SSH into your machine and execute the following command:
sudo /opt/bitnami/apps/wordpress/bnconfig --machine_hostname NEW_DOMAIN
Hope it helps.

Https on Elastic Beanstalk - wordpress

I have an annoying issue with https on a wordpress website running on aws eb single instance.
I have the same website in a vps, https works fine, styles and css are served via https. Just to be sure (I've spent 2 days trying to figure out what's wrong) few minutes ago I deployed on eb a copy of the website - editing only the database settings.
So, the issue is that in eb if I go to https://mywebsite.com the page is "broken", styles and scripts are server through http.
In the vps if I go to https://mywebsite.com styles and scripts are https://mywebsite.com/styles/style.css, in eb styles and scripts are http://mywebsite.com/styles/style.css.
Why is this happening and how can I fix that?
I've tried edit the wp_options table and set siteurl and home to https://mywebsite.com (the same website in the vps has values set to http://mywebsite.com)
AWS Elasticbeanstalk single instance Force SSL Redirect loop
htaccess (to force https or to force only http) is simply ignored, I've tried so many solutions but no one worked. The only solution that works for me is a php redirect to http after checking if the server variable http_x_forwarded_server is set
I've read that all the https connections - in eb single instance - through port 443 are "proxied" to port 80 (that could be the problem?)
So, any solutions? I don't want to force https in the website, so I don't want to install plugins that forces https, I just want that the website doesn't broke when navigating the website through https
Just after adding the post, I've managed to solve this problem.
For future references, the solutions is to add this variable $_SERVER['HTTPS'] and set it to 'on'.
This is my code
if(isset($_SERVER['HTTP_X_FORWARDED_SERVER'])) {
$_SERVER['HTTPS'] = 'on';
}
You can add it to index.php, or as I did, in the header.php of your theme (in this case be aware that if you change theme that code will not executed)

Resources