Category Archives: Code

Can’t connect to MySQL server on ‘127.0.0.1’ (61)

I downloaded the MySQL server and installed it on my Mac, but every time I tried to connect to it, I got the following error:

Can’t connect to MySQL server on ‘127.0.0.1’ (61)

There can be many reasons for this error, most of which are generously covered online, but in my case it was because MySQL was running on port 3307. I think the port was updated in a recent MySQL server update, because I’ve never had this issue with a previous MySQL server version. Here’s how to check if you have the same problem, and how to change it to port 3306 (unless you want to keep it running on port 3307).

Continue reading

Use Apache instead of built-in Nginx in GitLab CE

I installed GitLab CE using the Omnibus package on a new CentOS 6 server. Since I had nothing else on the server at that time, everything GitLab setup and configured was sufficient. Later, however, I wanted to setup additional sites on the server using Apache, but now port 80 was already bound to by GitLab’s built-in Nginx web server.

What I really wanted to do is disable the built-in Nginx server and just use my self-managed Apache installation. Here’s how to do just that.

Continue reading

Setup Mailtrap with WordPress

Mailtrap is a service that captures all mail sent by your site and prevents it from arriving at the intended recipient. It’s really useful for testing and debugging mail without having to write manual checks to ensure your users don’t get spammed with tests.

Setting up Mailtrap with WordPress is pretty straightforward, because all we need to do is overwrite the default SMTP server in the PHPMailer, which is what WordPress uses to send mail. It’s important to note that it will also trap mail sent from plugins like Contact Form 7.

Add the following hook in your theme’s functions.php file or throw this in a plugin:

1
2
3
4
5
6
7
8
9
10
function mailtrap($phpmailer) {
    $phpmailer->isSMTP();
    $phpmailer->Host = 'mailtrap.io';
    $phpmailer->SMTPAuth = true;
    $phpmailer->Port = 25;
    $phpmailer->Username = 'username';
    $phpmailer->Password = 'password';
}
 
add_action('phpmailer_init', 'mailtrap');
function mailtrap($phpmailer) {
    $phpmailer->isSMTP();
    $phpmailer->Host = 'mailtrap.io';
    $phpmailer->SMTPAuth = true;
    $phpmailer->Port = 25;
    $phpmailer->Username = 'username';
    $phpmailer->Password = 'password';
}

add_action('phpmailer_init', 'mailtrap');

Be sure to replace the username and password with your personal ones, which can be found by clicking on your inbox in Mailtrap. Look for the SMTP credentials.

Once the hook is in place, you’re done. Give it a go!

WordPress could not establish a secure connection to WordPress.org

I’m using Vagrant to work on a WordPress site and noticed the following error throughout several admin pages that attempt to connect to WordPress.org:

An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums. (WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)

Continue reading