Is it possible to create a wordpress database with php code?

As you know if you go to wordpress.org, you can download the latest version of WordPress. You can unzip this, and upload those files to get started.

However, WordPress requires a MySQL database. So you will need access to a database before you can install WordPress. This isn’t something you can do over FTP.

If you already have the database information, then yes it’s possible. But creating the database like that is not possible.


On a second thought, you may want to try to host WordPress database on another server, which won’t ok for your clients since they will depend on that other server to function.

As long as the MySQL server allows the database to be accessed by external servers. When you set up WP, instead of “localhost”, you’ll put in the SQL server.

Instead of “localhost” (in the wp-config.php) you will put the IP address of the server and then the config.php will connect

// wp-config.php

define ( 'DB_NAME', 'yourdbname' );
define ( 'DB_USER', 'yourusername' );
define ( 'DB_PASSWORD', 'yourpassword' );
define ( 'DB_HOST', '111.222.0.1' ); // IP address of the server where MySQL is running 

// make sure MySQL server will listen to the request from your WP server IP !

Host WP DB in other server.