I'm developing at my local computer. Therefore I exchange files between the localhost and server.
In wp-config I'd like to check if I'm on the server or not.
Depending on the result I'd change DB_USER and DB_PASSWORD.
Right now I do it manually.
wp-config.php
define( 'DB_USER', 'root' );
// define( 'DB_USER', 'gr_academ' );
define( 'DB_PASSWORD', '' );
// define( 'DB_PASSWORD', 'secret' );
Could you help me?
This is a common problem.
Is local site on port 80?
if ($_SERVER['SERVER_PORT'] == 80) { define( 'DB_USER', 'root' ); }
Are sites using different versions of PHP?
if (PHP_VERSION_ID == 70424) { define( 'DB_USER', 'root' ); }
Or detect by host.
if ($_SERVER['HTTP_HOST'] == 'something.local') { define( 'DB_USER', 'root' ); }
Or check server directory
if (strstr($_SERVER['DOCUMENT_ROOT'], '/Volumes/')) { define( 'DB_USER', 'root' ); }
Note: PHP Version is best, if you use WP-CLI.
Related
Here is my docker compose file code
version: "3.9" # optional since v1.27.0
services:
web:
ports:
- "80:80"
build:
context: ./code
mysql:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: 'testdb'
# So you don't have to use root, but you can if you like
MYSQL_USER: 'user'
# You can use whatever password you like
MYSQL_PASSWORD: 'password'
# Password for root access
MYSQL_ROOT_PASSWORD: 'password'
ports:
# <Port exposed> : < MySQL Port running inside container>
- '3306:3306
Here is my wordpress config file code
define( 'DB_NAME', 'testdb' );
/** Database username */
define( 'DB_USER', 'user' );
/** Database password */
define( 'DB_PASSWORD', 'password' );
/** Database hostname */
define( 'DB_HOST', 'localhost' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
and i got this error
enter image description here
I am new on docker your help will be appreciate able.Thanks in advance
Change define( 'DB_HOST', 'localhost' ); to define( 'DB_HOST', 'mysql' );
localhost will resolve to within the docker and not the server hosting the dockers.
Instead of the Wordpress contact form sending to an email, is it possible to have it sent to a custom backend server?
Such as http://localhost:3000 where my nodejs express server is being hosted?
in wp-config.php add following settings - As a result wp_mail() will work.
define( 'SMTP_HOST', 'server.a2hosting.com' ); // Check your hosting company
define( 'SMTP_AUTH', true );
define( 'SMTP_PORT', '465' );
define( 'SMTP_SECURE', 'ssl' );
define( 'SMTP_USERNAME', 'user#yourdomain.com' ); // Username for SMTP authentication
define( 'SMTP_PASSWORD', 'password' ); // Password for SMTP authentication
define( 'SMTP_FROM', 'user#yourdomain.com' ); // SMTP From address
define( 'SMTP_FROMNAME', 'Yourfirstname YourLastname' ); // SMTP From name
use following code in your form template or function.php , you may need custom function to pull each field data
wp_mail("recipient#example.com", "Subject", "Message");
To facilitate my localhost -> live server migrations, I would like my local Wordpress site (powered by wamp) to work with the exact same wp-config.php file than the one I have online:
//Define new directory path
define ('WP_CONTENT_DIR', ABSPATH . WP_CONTENT_FOLDERNAME);
//Define new directory URL
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_CONTENT_URL', WP_SITEURL . WP_CONTENT_FOLDERNAME);
So far this is not working, so I have to use this other configuration:
define( 'WP_CONTENT_DIR', 'C:\wamp64\www\domain.dev\content' );
define( 'WP_CONTENT_URL', 'http://localhost/domain.dev/content' );
What should I do to be able to use the first configuration?
You could use the php $_SERVER array to get the host $_SERVER['HTTP_HOST'] and compare if it is the dev or the live environment.
So, your wp-config.php file will looks something like this:
$cur_env = $_SERVER['HTTP_HOST'];
if($cur_env == 'localhost'){ //Or could be '127.0.0.1' - Or whatever your wamp base url is set.
define( 'WP_CONTENT_DIR', 'C:\wamp64\www\domain.dev\content' );
define( 'WP_CONTENT_URL', 'http://localhost/domain.dev/content' );
}else{
define('WP_CONTENT_DIR', ABSPATH . WP_CONTENT_FOLDERNAME);
define('WP_CONTENT_URL', WP_SITEURL . WP_CONTENT_FOLDERNAME);
}
Hi I am trying to do a custom install for wordpress and I need to change wp-content and plugin-directories.
I tried to add this to the wp-config.php after I installed wordpress
define( 'WP_CONTENT_DIR', dirname( FILE ) . 'wp-content' );
define( 'WP_CONTENT_URL', 'myurl/wp-content' );
but I still see the defaults plugins I did the same for WP_PLUGIN_DIR and WP_PLUGIN_URL.
Can anyone help me. Thanks in advance.
Use this for Plugin folder
define( 'WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/somedir' );
Use this for WP-content folder
define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/somedir' );
Use this code...
define( 'WP_CONTENT_DIR', dirname(__FILE__) . 'path/to/wp-content' );
define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/path/to/wp-content' );
I have a WordPress site that I am moving to a Media Temple Grid Server from another provider. I have WordPress in its own 'wp' directory so I can update it independent of the rest of my codebase.
After uploading all the files, I went to my site's URL, expecting that WordPress would start its install process, but instead, it redirects from http://example.com to http://example.com/wp-admin/install.php, and the browser gives me a "too many redirects" error message.
Other things:
The database is created
The .htaccess file has all the WordPress rules
Here's my wp-config.php:
<?php
// ===================================================
// Load database info and local development parameters
// ===================================================
if ( file_exists( dirname( __FILE__ ) . '/wp-config-local.php' ) ) {
define( 'WP_LOCAL_DEV', true );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
require( 'wp-config-local.php' );
} elseif ( file_exists( dirname( __FILE__ ) . '/wp-config-staging.php' ) ) {
define( 'WP_LOCAL_DEV', false );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
require( 'wp-config-staging.php' );
} elseif ( file_exists( dirname( __FILE__ ) . '/wp-config-production.php' ) ) {
define( 'WP_LOCAL_DEV', false );
define( 'WP_DEBUG', false );
require( 'wp-config-production.php' );
}
// ========================
// Custom Content Directory
// ========================
define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/content' );
define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/content' );
// ================================================
// You almost certainly do not want to change these
// ================================================
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );
// ==============================================================
// Salts, for security
// Grab these from: https://api.wordpress.org/secret-key/1.1/salt
// ==============================================================
define('AUTH_KEY', '+jw|C|KUKW4.&062<MjcDr/a95AOdg$tH5N^7-arnWXWD$V=5+RUUe-#YNW<~INo');
define('SECURE_AUTH_KEY', 'Tu?%#u{.<-9^8Qi+wtB-X;5`-b!(4U)#:B`4?~-R,.,H~kTyCRX#b[Rf#V9m/,DW');
define('LOGGED_IN_KEY', 'Kf_!-|N|kII`+:j7x2~QBQR_nVQ/ uvCPif/$|wk})lm YR{Y^8qji/X![jljpE]');
define('NONCE_KEY', 'YA+GiHY&N<)Gh`f-KR 0+BF4I]jP-Tn.b+V-Z1+}/P!B+:Lfr~(qB(u$_QCaUFM6');
define('AUTH_SALT', 'U96${|%&HN-l)aP.*.#ZK2&nIp#l~3X0-{Rx$Fgll4oY&-YM/UVw9bf<Tyk=S#v>');
define('SECURE_AUTH_SALT', '>f-^11d$V|M#bm2K.Rzk1i=H+Ykpv`9lVgsBd+}W5&#rS_!k=EZsy0-]&S3!sNk[');
define('LOGGED_IN_SALT', '#2iH05hI2h87P:a!}`jsqH3>E#q0g)|Ns9g{T;($S%,n>+dP)W-l9{#whhnib:1Q');
define('NONCE_SALT', '_I90W[ST<|bmKC<i*J.-tq+R+wqyAkUd-~33*E?k!:%O3)rRZ~yc-PpVA<R+OcTR');
// ==============================================================
// Table prefix
// Change this if you have multiple installs in the same database
// ==============================================================
$table_prefix = 'wp_';
// ================================
// Language
// Leave blank for American English
// ================================
define( 'WPLANG', '' );
// ===========
// Hide errors
// ===========
ini_set( 'display_errors', 0 );
define( 'WP_DEBUG_DISPLAY', false );
// =================================================================
// Debug mode
// Debugging? Enable these. Can also enable them in local-config.php
// =================================================================
// define( 'SAVEQUERIES', true );
// define( 'WP_DEBUG', true );
// ======================================
// Load a Memcached config if we have one
// ======================================
if ( file_exists( dirname( __FILE__ ) . '/memcached.php' ) )
$memcached_servers = include( dirname( __FILE__ ) . '/memcached.php' );
// ===========================================================================================
// This can be used to programatically set the stage when deploying (e.g. production, staging)
// ===========================================================================================
define( 'WP_STAGE', '%%WP_STAGE%%' );
define( 'STAGING_DOMAIN', '%%WP_STAGING_DOMAIN%%' ); // Does magic in WP Stack to handle staging domain rewriting
// ===================
// Bootstrap WordPress
// ===================
if ( !defined( 'ABSPATH' ) )
define( 'ABSPATH', dirname( __FILE__ ) . '/wp/' );
require_once( ABSPATH . 'wp-settings.php' );
And here's wp-config-production.php:
<?php
/*
This is a sample local-config.php file
In it, you *must* include the four main database defines
You may include other settings here that you only want enabled on your local development checkouts
*/
define( 'DB_NAME', 'db000000_wordpress' );
define( 'DB_USER', 'db000000' );
define( 'DB_PASSWORD', 'some_password' );
define( 'DB_HOST', 'internal-db.s000000.gridserver.com' ); // Probably 'localhost'
Any thoughts on what I'm doing wrong?
Solved this--turns out I had uploaded an .htaccess file from my previous install, and this file was doing some rewriting that was causing the redirect issue.