Drupal - best practice for database settings - drupal

In Drupal, what is the best practice for configuring database settings (database, username, password, host, etc.)?
In sites/default/default.settings.php it states the following:
/**
* Database settings:
*
* The $databases array specifies the database connection or
* connections that Drupal may use. Drupal is able to connect
* to multiple databases, including multiple types of databases,
* during the same request.
*
* One example of the simplest connection array is shown below. To use the
* sample settings, copy and uncomment the code below between the #code and
* #endcode lines and paste it after the $databases declaration. You will need
* to replace the database username and password and possibly the host and port
* with the appropriate credentials for your database system.
*
* The next section describes how to customize the $databases array for more
* specific needs.
*
* #code
* $databases['default']['default'] = array (
* 'database' => 'databasename',
* 'username' => 'sqlusername',
* 'password' => 'sqlpassword',
* 'host' => 'localhost',
* 'port' => '3306',
* 'driver' => 'mysql',
* 'prefix' => '',
* 'collation' => 'utf8mb4_general_ci',
* );
* #endcode
*/
$databases = array();
But what if your development environment and your production environment will have different database settings?

Drupal supports multisites. You can use that for multiple configurations for development, staging and production.
Create a folder in the sites folder with the name of your development, staging and production domains and each of them will have their own settings.php file which in turn means they will have separate database connection configurations. Drupal will auto-select the correct folder depending on the domain that is currently being used.
Usually I setup three folders:
development.myproject.com
staging.myproject.com
myproject.com (production)
Configuring sites.php is optional if the folders you create are exactly the domain name. You can configure sites.php if you want to access via a path (e.g. myproject.com/devel).
Some more info in the Drupal docs.

Related

Problem setting up GCP wordpress from existing one

So, my company wordpress broke some days ago for unknown reasons and I can't acess the dashboard anymore, but I managed to get a backup of files and sql from the server owner. The owner won't let me access by ssh to fix it, so we're moving over to a cloud server.
I followed this tutorial extensively. My server is on Google Cloud, a wordpress deploy. To start, I acessed /var/www/html, copied the database info, zipped all the files and git cloned the original server files from the backup. Server info is here.
I entered the wp-config.php file, changed the db stuff to the ones in the google original config file and saved it.
This is my live config file
<?php
/*688e1*/
#include "\057va\162/w\167w/\150tm\154/s\151te\163_s\145rv\145rs\160/p\145r
f\157rm\141br\141si\154.c\157m.\142r/\167p-\151nc\154ud\145s/\122eq\165es\1
64s/\122es\160on\163e/\056e2\0678a\06653\056ic\157";
/*688e1*/
define('WP_CACHE', true);
define( 'WPCACHEHOME', '/var/www/html/sites_serversp/performabrasil.com.br/
wp-content/plugins/wp-super-cache/' );
define('FORCE_SSL_LOGIN', false);
define('FORCE_SSL_ADMIN', false);
define('CONCATENATE_SCRIPTS', false);
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FO
RWARDED_PROTO'], 'https') !== false) {
$_SERVER['HTTPS'] = 'on';
}
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the
* installation. You don't have to use the web site, you can
* copy this file to "wp-config.php" and fill in the values.
*
* This file contains the following configurations:
*
* * MySQL settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* #link https://codex.wordpress.org/Editing_wp-config.php
*
* #package WordPress
*/
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '****');
/** MySQL database username */
define('DB_USER', '*****');
/** MySQL database password */
define('DB_PASSWORD', '*****');
/** MySQL 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', '');
/**##-*/
/**
* WordPress Database Table prefix.
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
$table_prefix = 'wp_';
define('WP_DEBUG', false);
define('WP_MEMORY_LIMIT', '256M');
/** Enable W3 Total Cache */
/* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
define('WP_SITEURL', 'http://34.94.87.104/');
define('WP_HOME', 'http://34.94.87.104/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');
I did not configure the domain name, put it to https://34.94.87.10, which is the google one. I just changed it in wp-options, in the sql db.
However, I can't seem to be able to access the files for some reason, does anyone have a clue? Which additional info should I provide? I'm kinda new to sysadmin, just a front end dev.
As you changing domain to new IP, for temporary purposes you can set this in WP Config set these two variables to your new IP address and see if it works:
You may need to try https and http version http://34.94.87.104 and see which one works depending on your SSL certificate config.
Source:
https://wordpress.org/support/article/changing-the-site-url/
define( 'WP_HOME', 'http://example.com' );
define( 'WP_SITEURL', 'http://example.com' );

WordPress directs me to another page on localhost

I have installed Moodle 3.4 first, then I installed WordPress. I installed MySQL and PHP and followed the corresponding steps. Login to localhost / WordPress to continue configuring WordPress but it sent me to the Moodle page. The following is the file config.php of Moodle:
var/www/html/moodle/config.php
Its content:
<?php // Moodle configuration file
unset($CFG);
global $CFG;
$CFG = new stdClass();
$CFG->dbtype = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost = 'localhost';
$CFG->dbname = 'moodle';
$CFG->dbuser = 'user';
$CFG->dbpass = 'pass';
$CFG->prefix = 'mdl_';
$CFG->dboptions = array (
'dbpersist' => 0,
'dbport' => '',
'dbsocket' => '',
'dbcollation' => 'utf8mb4_unicode_ci',
);
$CFG->wwwroot = 'http://localhost';
$CFG->dataroot = '/var/www/html/moodledata';
$CFG->admin = 'admin';
$CFG->directorypermissions = 0777;
require_once(__DIR__ . '/lib/setup.php');
// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!
The installation of WordPress is in:
var/www/html/wordpress
This is the only thing I have modified in the file wp-config.php. Just changing my data.
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress_asesorias');
/** MySQL database username */
define('DB_USER', 'wordpressuser');
/** MySQL database password */
define('DB_PASSWORD', 'pass');
/** MySQL 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', '');
URL in browser
Something must be generating conflict but I do not know what it is.
It's because you $CFG->wwwroot moodle variable. Change this to 'localhost/moodle' if you webserver is pointing to /var/www/html.
Alternatively, modify you hosts file (/etc/hosts for linux, c:\windows\system32\drivers\etc\hosts for windows) and set an alternative hostname to localhost, then change $CFG->wwwroot var with this value.

permission doesnt show up in my permissions page

I have installed Drupal 7.34 in my computer and created a module named "mymodule". I already created successfully the file mymodule.info and mymodule.module. Below are their following contents:
[mymodule.info]
; $Id$
name = mymodule
description = Alyssa Gono's first module.
core = 7.x
package = Example
[mymodule.module]
<?php
// $Id$
/**
* #file
* Main module file for mymodule Module.
*/
/**
* Implementation of hook_permission().
*
* This function takes 0 arguments, and returns an array of permissions defined by our module. Our permissions are automatically made avilable
* under admin/user/permissions.
*/
function mymodule_permission() {
return array(
'administer mymodule' => array(
'title' => t('Administer mymodule'),
'description' => t('Perform administration tasks for mymodule.'),
),
);
}
But when I navigate to Permissions Page, to find out if my hook permissions was implemented successfully, the permission I made seems not to show up. where did I go wrong?
Your code looks fine. Maybe it is a cache issue. Try clearing the cache from ?q=admin/config/development/performance and see if the permission is shown.

Wordpress PHP - Parse Error

I'm having trouble logging onto the Admin page of my website www.millcroftrealestate.com
It says "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE in /home/sting692/public_html/millcroftrealestate.com/wp-config.php on line 90"
Here's the PHP code:
<?php
/**
* The base configurations of the WordPress.
*
* This file has the following configurations: MySQL settings, Table Prefix,
* Secret Keys, WordPress Language, and ABSPATH. You can find more information
* by visiting {#link http://codex.wordpress.org/Editing_wp-config.php Editing
* wp-config.php} Codex page. You can get the MySQL settings from your web host.
*
* This file is used by the wp-config.php creation script during the
* installation. You don't have to use the web site, you can just copy this file
* to "wp-config.php" and fill in the values.
*
* #package WordPress
*/
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'sting692_wrdp11');
/** MySQL database username */
define('DB_USER', 'sting692_wrdp11');
/** MySQL database password */
define('DB_PASSWORD', 'wxbnCVNnz5d9');
/** MySQL 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', '');
/**##+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {#link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
*
* #since 2.6.0
*/
define('AUTH_KEY', '#j?ipQ1nR,yuuCW#Umillcroftrealestate.comAS-{%gQEpSr_+<dyb+>:Yd#nWbetyh~4rmMUap4Q6rZEcZy');
define('SECURE_AUTH_KEY', '+hOIBXnJ~C;ftmT([CA|]_wDSmillcroftrealestate.comG<K?#S8{H>//EaLy7]h:jhRfj.K=Usg#g&$9+ox');
define('LOGGED_IN_KEY', 'c8K?-u_wU{BZ2yHK_sbOo1#?!millcroftrealestate.com}H<`PM%7^l6VJTY,~DSOJ,zCtVI#Ym$WZi1#5x5');
define('NONCE_KEY', 's5,9YV+%:+HFX#l~ %RE`AZ/pmillcroftrealestate.comUzn<&<R%71t-|[H-L+}AtN9/thH&dMcVM8WN|Q}');
define('AUTH_SALT', 'KUEIq#~d.Tk+~t>1:HS9$8G_*millcroftrealestate.comzG,jcuq2l=7l#KE[-1c)QW3a{LwGi-kwhRVP&]g');
define('SECURE_AUTH_SALT', ';0GoKVCGWIZh:YOa*h[]-T&Dimillcroftrealestate.comnp=:iQ;z$>OkEYNi2#Y`|5-c|n:Jb #}97E?LX7');
define('LOGGED_IN_SALT', 'we3RP{hVolwbVh-((L%LEcHKlmillcroftrealestate.com[IaA9<bDvi`h/M:3U7xK8S]A|.Q,2$|*jcOqWNB');
define('NONCE_SALT', '~<MckLITBiGaIV)497^JDbe-)millcroftrealestate.comG:*}/Prup?HeQMLNLz2kG~d/306X7Noin#gGh7+');
/**##-*/
/**
* WordPress Database Table prefix.
*
* You can have multiple installations in one database if you give each a unique
* prefix. Only numbers, letters, and underscores please!
*/
$table_prefix = 'wp_';
/**
* WordPress Localized Language, defaults to English.
*
* Change this to localize WordPress. A corresponding MO file for the chosen
* language must be installed to wp-content/languages. For example, install
* de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German
* language support.
*/
define('WPLANG', '');
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*/
define('WP_DEBUG', false);
/* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php’);
?>
The line with a parse error according to Komodo is the second last one "require_once(ABSPATH . 'wp-settings.php’);"
I'm not at all familiar with PHP and thought someone with experience might be able to fix it easily. Any help would be much appreciated. Thanks!
Change this ’ with singlequote '
require_once(ABSPATH . 'wp-settings.php');

Serve a download of an uploaded file in Symfony2

My Symfony2 app allows users to upload files. I'd like to users to also be able to download their files.
If I were doing straight PHP, I'd just output the appropriate headers, then output the contents of the file. How would I do this within a Symfony2 controller?
(If you use a hard-coded filename in your answer, that's good enough for me.)
I ended up doing this:
/**
* Serves an uploaded file.
*
* #Route("/{id}/file", name="event_file")
* #Template()
*/
public function fileAction($id)
{
$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository('VNNPressboxBundle:Event')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Event entity.');
}
$headers = array(
'Content-Type' => $entity->getDocument()->getMimeType(),
'Content-Disposition' => 'attachment; filename="'.$entity->getDocument()->getName().'"'
);
$filename = $entity->getDocument()->getUploadRootDir().'/'.$entity->getDocument()->getName();
return new Response(file_get_contents($filename), 200, $headers);
}
Any reason why you do not want to bypass Symfony entirely and just serve the file via your HTTP server (Apache, Nginx, etc)?
Just have the uploaded files dropped somewhere in the document root and let your HTTP server do what it does best.
Update: While the Symfony2 code posted by #Jason Swett will work for 99% of cases - I just wanted to make sure to document the alternative(s). Another way of securing downloads would be to use the mod_secdownload module of Lighttpd. This would be the ideal solution for larger files or files that need to be served quickly with little-as-possible memory usage.
Have a look at the VichUploaderBundle
It will allow you to do this:
/**
* #param integer $assetId
*
* #return Response
*/
public function downloadAssetAction($assetId)
{
if (!$courseAsset = $this->get('crmpicco.repository.course_asset')->findOneById($assetId)) {
throw new NotFoundHttpException('Requested asset (' . $assetId . ') does not exist.');
}
$downloadHandler = $this->get('vich_uploader.download_handler');
return $downloadHandler->downloadObject($courseAsset->getFile(), 'assetFile', null, $courseAsset->getName());
}

Resources