Setup MySQL for local Wordpress development - martindubenet/Wordpress GitHub Wiki

Home  ][  Plugins  ][  Functions  ][  MySQL setup  ]

Create your local database

Mac MAMP Mac MAMP PRO Windows WAMP
default port :8888 demo:8889 :3308
phpmyadmin http://localhost:8888/phpmyadmin/ http://demo/phpmyadmin/ http://localhost:3308/phpmyadmin/

MySQL Workbench

A youtube tutorial on « How to install Workbench version 8.0.22 on macOS M1 ».

phpMyAdmin

  1. Create a new database. (Note: by default Wordpress is requirering that your database name starts with wp_ as a prefix)
  2. Once created you will be automatically redirect to « Structure » tab but you have nothing to fill there.
  3. Click on « Priviledges » from navigation tab.
  4. Click on the « Create a new user » link available down in the page.
    1. Fill in a User name (alphanumeric characters only),
    2. Enter a simple Password and Re-type it a second time,
    3. Global privileges ✅ Check all
    4. Click the « Go » button in the bottom right corner of the page.

Fill in your database infos

  1. Before launching it, copy/paste /wp-config-sample.php from the root directery of Wordpress.
  2. Rename that copied file to /wp-config.php.
  3. Open /wp-config.php to edit the following MySQL settings:

Since WAMPserver now install MariaDB by default, if you use the traditional MySQL database set-up, you need to add the Port defined for MySQL value that is defined on the localhost page. So far mine is 3308 but that can change.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );

/** MySQL database username */
define( 'DB_USER', 'root' );

/** MySQL database password */
define( 'DB_PASSWORD', 'root' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );      // default
define( 'DB_HOST', 'localhost:8889' ); // MAMP (macOS)
define( 'DB_HOST', 'localhost:3308' ); // WAMP (Windows)

Advance options for your « wp-config.php »

Set URL of the site landing page

Force the bloginfo( 'url' ) value that defines the home_url() function. PHP over-rules de database value without erasing it from mySql and maximise performance in the meantime. Now it is safer and faster to use <?php echo esc_url( home_url( '/' ) ); ?> in your theme header & footer templates.

define( 'WP_HOME', 'https://example.com' );

Set the path to the solution

https://wordpress.org/support/article/giving-wordpress-its-own-directory/

Force bloginfo( 'wpurl' ) value that defines the site_url() function. This allows you to move the solution within a sub-directory making the root of your site more zen.

define( 'WP_SITEURL', 'https://example.com/wordpress' );

If you get in trouble after follow these instructions to fix the issue using your theme's function.php file that you'll access via FTP.

Desable auto-updates

This is useful for professional developpers that prefers stability over « freedom to bug-and-break » that come free updates on old projects.

define( 'WP_AUTO_UPDATE_CORE', false );

Limit the amount of revisions

This helps keeping the database from inflating by flushing older backups that in real life are not used often.

define( 'WP_POST_REVISIONS', 4 );

 

Launch Worspress for the first time

  1. http://localhost/example.com/wp-admin/install.php
  2. The install.php will ask to choose the default language for the admin view.
  3. Fillin the basic informations for your Wordpress site: Site Title, Use name, Password, Your Email and, if your are developping a new site live on a server, make sure to check the option Search Engine Visibility ✅ so the <meta name="robots"> content value will display noindex,nofollow until you uncheck it from the Dashboard.
  4. Click Install Wordpress and you're done!