Just curious . Is it some how possible to create a database with php code? I am having only having access to public_html folder and i want to make a wordpress installation. Is there any method to make it work?

I have no cpanel access and SSH access.


  • Usually shared hosting providers allow the same FTP username, IP, password for database server as well. Upload a DB admin script like Adminer or PHPMyAdmin to public_html & then try to access the database using the same FTP credentials. If it works, then create the database from there and provide the info. to wp-config.php to start WordPress installation. – Fayaz Aug 26 '18 at 18:28
  • Tried it didn't work out – Latheesh V M Villa Aug 26 '18 at 20:10
  • 1
    Well, ask the hosting support about DB info. :) ... unless you use a different server for database, you'll have to have some sort of database access. There is no alternative. If they don't want to give full access of database server to you, then at least ask them to create a specific user/pass with only access to one database for WordPress installation. Also, having database to another server is slow unless both the server belongs to the same local network. – Fayaz Aug 26 '18 at 23:06

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', '' ); // 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.

  • Hello, Thank you . Planning to try this on. Will it slow down the website? – Latheesh V M Villa Aug 26 '18 at 17:04
  • Well, it depends on the server (location and kind of server) that is hosting the DB and the size of the DB, ideally, you want them to both (files and DB) to be on the same server but it should work ok. – Castiblanco Aug 26 '18 at 17:07
  • Hi,i tried it but getting this error : Error establishing a database connection- this is what i have tried. in godaddy i created a fresh installation of wordpress (domain is different). and edited the database to update the url and edited the wp-config file as per the above answer. I am having a shared hosting. Not sure where it went wrong – Latheesh V M Villa Aug 26 '18 at 22:16
  • 1
    Thank you .i think this is the only possible solution when there is no SSH and cpanel access. – Latheesh V M Villa Aug 27 '18 at 8:59

If the database and database user do not already exist, your only chance is to access the Linux shell, which you might be able to do via PHP, depending on the hosts security settings.

The PHP command is shell_exec()

IF you have the rights to do this, then you have to send the right series of commands to:

1) Create the database

2) Create the database user (with password)

3) Grant access of the database user to the database

They have done something similar here: https://stackoverflow.com/questions/33470753/create-mysql-database-and-user-in-bash-script

However, you won't have root access, and you don't even have cPanel account access, so it may not be possible.

  • Usually most of the hosting providers keeps it disabled initially and requires cpanel to enable them – Latheesh V M Villa Aug 26 '18 at 17:28
  • 1
    Yes, but he wanted to know if it were possible. And the answer is yes, IF – De Coder Aug 26 '18 at 18:25

Although you can create database with php code, an easier way to setup wordpress would be to use wp-cli and mysql commands. This link gives detailed tutorial on the same.

  • Hello, thanks. Will it be possible to explain a littlebit more? Doesn't cli access require cpanel access? – Latheesh V M Villa Aug 26 '18 at 17:02
  • Wordpress cli require SSH access. so i think this is also not going to work – Latheesh V M Villa Aug 26 '18 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.