Establishing a Secure Connection between PHP Server and Amazon AWS MySQL Server

Currently, I have set up two servers on Amazon AWS. One server is dedicated to running PHP while the other handles MySQL. Accessing the MySQL database through my terminal and MySQL Query Browser has proven successful.

However, I am facing challenges in establishing a connection between the PHP and MySQL servers.

The following PHP code represents my attempts so far (which only work for "localhost" databases).

$dbbase = 'mydb';               
$dbuser = 'myuser';         // Your MySQL username
$dbpass = 'mypassword';     // ...and password
$dbhost = 'localhost:3306';  // Internal IP for MYSQL Server

// connect to database
$dblink = mysql_connect($dbhost, $dbuser, $dbpass) 
    or die ("System Down");

mysql_select_db($dbbase, $dblink) 
    or die ("Database Down");

I believe that I should be able to reroute this code through internal AWS traffic, but I am open to any solution that works at this point. This will serve as my starting point.

This is what I have already attempted:

  • Included the IP of the PHP server in the Security Group for MySQL(3306) permissions

  • Attempted to use the internal, external, and private IPs/DNSs of the MySQL Server as the $dbhost variable

  • Created a wildcard entry (myuser@%) on the MySQL server

If you have any ideas or tips, they would be greatly appreciated.

Answer №1

I encountered a similar problem - it seems that the MySQL extension for PHP is no longer included in PHP5!

According to the official PHP documentation, starting from PHP 5.0.4, there have been some changes. The following modules are now built into PHP: DOM, LibXML, Iconv, SimpleXML, SPL, and SQLite. However, the MySQL and Overload extensions are no longer included.

You can find more information about this change on http://php.net/manual/en/install.windows.extensions.php.

Answer №2

I've successfully resolved the issue.

The key solution was to include this specific rule in the Security Group:

Category: MySQL

Origin: 10.0.0.0/8

From my understanding, the network range 10.0.0.0/8 encompasses all internal Amazon IPs. It is possible to tighten this restriction, but it becomes important to manage potential changes in the internal IP addresses of your servers.

Furthermore, within my PHP script, I utilized the Private DNS of my MySQL Server. The format would resemble something like this:

ip-10-10-100-100.ec2.internal:3306

In conclusion, these steps summed up everything that I implemented.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

PHP code coverage collection remotely

For our current project, we have set up a system where we run PHPUnit tests using Selenium and Curl on a separate development server. Server B hosts an Apache server which serves the website. To begin the testing process, server A synchronizes the project ...

Braintree Payments - Verifying the status of a transaction

I am in the process of setting up my first online store and have opted to use Braintree Payments as the payment gateway. Following the instructions provided in this tutorial video, I have successfully configured Braintree to accept payments and update my ...

Implementing search functionality, what could be causing this error message: "Warning: Division by zero in /path/test.php on line 29 Query was empty"?

I am working on a basic search function that checks the "desc" column in a MySQL table called "products". Here's the code I have for displaying the results, where $find is the user input string converted to uppercase: $dataQuery = 'SELECT * FR ...

Transforming accent marks from UTF-8 to ASCII characters

I've come across various discussions on this topic and have found some solutions, but I'm still struggling to solve the accent issue. In my Italian text, I have letters with accents (à, è, é, ì, ò, and ù). This text needs to be sent in a f ...

What is the quickest way to redirect a URL in WordPress?

Is it possible to redirect a URL instantly in WordPress using this script code? JavaScript Code: jQuery(document).ready(function() { var x = window.location.href; if (x == 'http://example.com/') { window.location.hr ...

Troubleshooting NetBeans debug functionality with PHPUnit tests in PHP

After following a helpful article by Rafael Dohms on debugging PHPUnit tests in NetBeans with Xdebug, I encountered some issues. When trying to debug in NetBeans and running tests using the command line, NetBeans would switch from "waiting for connection" ...

When using SQL Server, Windows Authentication is successful when connecting through Management Studio but not when using Apache

My PHP application built with Codeigniter is attempting to connect to SQL Server 2016 using Windows Authentication. Encountering the following error message: Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 1 ...

Preserving information throughout an online browsing session

Is there a way to save the data about which buttons a user clicked on while visiting our website without using a database? The issue is that any array I use gets reset every time the user is redirected from the page. Note: I'm still learning PHP ...

How to pass PHP echo to success parameter in jQuery AJAX commands

As I delved into learning ajax, I came across some code snippets online but struggled with passing values from PHP. Here is the snippet from my email.php file: $conn = mysqli_connect($servername, $username, $password, $db); $email = $_POST['email&apo ...

Using Angular and Laravel to display JSON data extracted from a MySQL database

I am currently retrieving data from MySQL using Laravel query builder, converting it to JSON format as per the suggestion of W3schools. However, when trying to display the fetched data using AngularJS, I end up with a blank page. Laravel route Route::ge ...

What is the best way to retrieve time from a MySQL timestamp in ActionScript 3?

I need help displaying an ActionScript 3.0 Timer, based on a timestamp retrieved from MySQL. Imagine that PHP returns a string like $my_birthday="2013-05-22 12:30:45". I fetched it in ActionScript using a URLLoader, and now I want to present the timer in ...

The functionality of php.js is compromised

I've been attempting to integrate php.js into my scripts, but have encountered a problem. I debugged a function and loaded it onto a single page containing only jQuery and php.js, yet it is still not functioning properly. <script src="http://code. ...

When a form input is submitted, the webpage will refresh with a new

I have a form embedded on my WordPress page. I want to identify users without referrers so that I can set the referrer for them automatically (the referrer part is handled by a plugin). The registration form URL looks like this: The code provided below w ...

Understanding the `readfile()` function jargon

When a function's result is sent to the output buffer, it means that the result will not be visible until echoed. For functions that output directly, we use ob_start to direct the result to the output buffer before it reaches the browser as plain html ...

Using jQuery Datepicker Beforeshowday to dynamically retrieve an array of unavailable dates through Ajax

Currently, I am working on implementing a datepicker that will update an array of unavailable dates. While it successfully works with a PHP variable being passed, the challenge lies in properly returning the data for the option (as it is throwing a console ...

unable to access submitted data

I am working with some PHP code where I am retrieving post values from a form- <?php $file="data.xml"; $test= new SimpleXMLElement($file, null, true); echo $_POST['question1']; echo $test->easy->question[0]->key; echo $test->easy- ...

I am eager to retrieve and showcase the images stored in the database

When I execute the code below, it displays encrypted symbols in the output like this [[�ѥ����1}j�i�Ƥ�^i�췼ܨ5���l�r�Ejק�r:��}=��""]�Q[n�C6���ZVv{����!���Y�j��>|�2��o��#\ ...

Show the json data on a PHP table

I've been attempting to showcase JSON content in a PHP table, but I keep encountering errors. It seems like there are some syntax issues that I can't quite pinpoint. Any suggestions on what needs to be modified? PS. I'm using the Slim frame ...

Uploading files to a local server using PHP

Currently, I am utilizing an Apache Server that operates in localhost. However, since I am not well-versed in PHP, I attempted to utilize code from the W3Schools website without success. Below is the HTML code : <!DOCTYPE html> <html> <bod ...

Adding nested JSON data to MySQL using NodeJS

My current challenge involves using Node.js to INSERT JSON data into a MySQL database. Everything runs smoothly until I encounter nested values within the JSON structure. Here is an example snippet of my JSON data: var result2 = [{ "id": 89304, "employe ...