Articles on: Troubleshooting (WebPro)

How to use Astra Website Protection with a MySQL database

This article will help you configure Astra Website Protection with a MySQL database, instead of the default SQLite database.

Step 1 - Select/Create MySQL database



You can either use an existing MySQL database, or create a new database (recommended) for use with Astra. You can refer to one of these guides to create the new database:

cPanel - HostGator, GoDaddy, Namecheap, Hostinger etc.
Plesk - Vultr, A2, Liquid Web etc.
Self-hosted MySQL

Once you've created a new database & user, we will need to set the following environment variables:

ParameterEnvironment VariableDescription
Database DriverASTRA_DB_CONNECTIONmysql
Database HostnameASTRA_DB_HOSTlocalhost is the default hostname used by cPanel
Database PortASTRA_DB_PORT3306 is the default MySQL post
Database NameASTRA_DB_DATABASEastra_security is the recommended for easy identification
Table PrefixASTRA_DB_PREFIXastra_gk_ is the default table prefix
Database UsernameASTRA_DB_USERNAMEEnter the value generated
Database PasswordASTRA_DB_PASSWORDEnter the value generated


Step 2 - Update the environment variables



We need to set the database connection details in the environment variables, so that the Astra Website Protection plugin can use them. There are multiple ways to set the environment variables on your server as shown below.




This is the easies way to set environment variables. Open the config file of your CMS such as wp-config.php or config.php and add the following PHP code to it (after setting the correct database credentials):

//Begin Astra Security

putenv('ASTRA_DB_CONNECTION=mysql');
putenv('ASTRA_DB_PORT=3306');
putenv('ASTRA_DB_PREFIX=astra_gk_');
putenv('ASTRA_DB_DATABASE=astra_security');
putenv('ASTRA_DB_HOST=localhost');
putenv('ASTRA_DB_USERNAME=astra_security');
putenv('ASTRA_DB_PASSWORD=<database_password>');

//END Astra Security

Some of the common paths of the config file:

CMSConfig File Location
WordPresswp-config.php
OpenCartconfig.php



Method 2 - Update your existing .env file



If you're using a framework such as Laravel, Symfony etc. and already use an environment file, you can simply add these variables to it. Add the following code to the .env file after updating the values:

ASTRA_DB_CONNECTION=mysql
ASTRA_DB_PORT=3306
ASTRA_DB_PREFIX=astra_gk_
ASTRA_DB_DATABASE=astra_security
ASTRA_DB_HOST=localhost
ASTRA_DB_USERNAME=astra_security
ASTRA_DB_PASSWORD=<database_password>



Method 3 - Set environment variables via server config



If you are using Apache, you can add the following code to your .htaccess file set the environment variables. Before making any changes in your live server, please make a copy of the .htaccess file.

SetEnv ASTRA_DB_CONNECTION mysql
SetEnv ASTRA_DB_PORT 3306
SetEnv ASTRA_DB_PREFIX astra_gk_
SetEnv ASTRA_DB_DATABASE astra_security
SetEnv ASTRA_DB_HOST localhost
SetEnv ASTRA_DB_USERNAME astra_security
SetEnv ASTRA_DB_PASSWORD <database_password>


Step 3 - Verify Changes



Once the above changes are made, you can click on Verify Installation in the Getting Started screen, or simply run a new Malware Scan to verify that these changes have taken effect. If you face any issues with this process, please feel free to reach out to us by creating a support ticket from the Astra Dashboard.

Updated on: 08/08/2022

Was this article helpful?

Share your feedback

Cancel

Thank you!