Nginx 502 Bad Gateway error after updating Ubuntu 12.04

Today I updated my Ubuntu Server to 12.04.5 LTS (release 12.04, codename: precise), and got “502 Bad Gateway” on all my websites.

I checked Nginx log files and found that Nginx cannot open the socket created by PHP-FPM:

2014/09/11 19:01:03 [crit] 2741#0: *107 connect() to unix:/var/run/www-devnote.sock failed (13: Permission denied) while connecting to upstream, client: XXX.XX.X.XX, server: ~^(www\.)?(?<domain>.+)$, request: “GET /2014/04/using-a-wpf-control-in-a-mfc-application/ HTTP/1.1”, upstream: “fastcgi://unix:/var/run/www-devnote.sock:”, host: “developernote.com”

(more…)

Using a WPF control in a MFC application

I’ve been working on some MFC application and to apply my WPF knowledge I added a WPF control written in C# to my MFC CView with the following code:

int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CView::OnCreate(lpCreateStruct) == -1)
        return -1;

    try
    {
        gcroot<hwndsource ^> hwnd_source = gcnew HwndSource(0, WS_VISIBLE | WS_CHILD, 0, 0, 0, "HwndSource", IntPtr(m_hWnd));

        MyWpfControl ^ control = gcnew MyWpfControl();

        hwnd_source->RootVisual = control;
    }
    catch (Exception ^ ex)
    {
        String ^ msg = ex->Message;
    }

    return 0;
}

All that I needed to do is to follow the steps described in this post: How do I host WPF content in MFC Applications, fix VS2012 bug described here, and got rid of std::mutex and std::lock_guard replacing them with the following classes using typedefs:

(more…)

How to encrypt MySQL database in Ubuntu 12.04 LTS

encrypt MySQL databaseProbably, the easiest way to encrypt MySQL database in Ubuntu is by using ecryptfs-utils. Install ecryptfs-utils:

apt-get install ecryptfs-utils

Mount /usr/local/encrypted directory and create mdf directory for MySQL data files (you will be prompted for passphrase and other options):

mkdir /usr/local/encrypted
mount -t ecryptfs /usr/local/encrypted /usr/local/encrypted
cd /usr/local/encrypted
mkdir mdf
chug.sh mysql mdf
chmod og-rwx mdf

(more…)

Ubuntu VPS Performance Monitoring

I run several PHP websites in Jooma and WordPress on Ubuntu VPS using Nginx as the web server with PHP-FPM for processing PHP. In most cases all the sites work fast enough, but sometimes (probably once a couple days) I got a message from Yandex (Russian search engine like Google) telling that one of my websites did not respond within 5 seconds. I set up Nginx slowlog and detected that sometimes HTTP requests are processed for more than 5 seconds:

(more…)

Monitoring CPU Steal Time with command line in Ubuntu

Bash command that writes CPU Steal Time along with other CPU usage statistics from top command header once in a second to MySQL database:

top -b -d 1 | ts ‘%Y-%m-%d %H:%M:%S’ | sed -rn “s/(.{19} )Cpu\(s\):\s+([0-9]+\.[0-9]+)%us,\s+([0-9]+\.[0-9]+)%sy,\s+([0-9]+\.[0-9]+)%ni,\s+([0-9]+\.[0-9]+)%id,\s+([0-9]+\.[0-9]+)%wa,\s+([0-9]+\.[0-9]+)%hi,\s+([0-9]+\.[0-9]+)%si,\s+([0-9]+\.[0-9]+)%st(.*)/INSERT INTO m_perf_stat (CDate, cpu_us,  cpu_sy,  cpu_ni, cpu_id,  cpu_wa,  cpu_hi,  cpu_si,  cpu_st) VALUES (‘\1′, \2, \3, \4, \5, \6, \7, \8, \9);/p” | mysql -u <username> -p<password> <database>

that’s the longest bash command I ever written in my life Улыбка

(more…)

Configuring Firewall to enable FTP, SSH and HTTP on Ubuntu

FirewallCheck your currently implemented firewall rules with the following command:

iptables -L

Examine the output. On a clean Ubuntu installation you will see an empty ruleset:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

(more…)

How to encrypt swap on Ubuntu 12.04

Without going into particulars, it suffices to say that Ubuntu 12.04 has the following script that sets up encrypted swap:

ecryptfs-setup-swap

(more…)

How to debug a PHP script

It could be useful sometimes to know what variables are defined at particular point of PHP script in order to have a better understanding of the code you are debugging. In contrast with C++, PHP has a magic function get_defined_vars ( void ) that  returns an array of all defined variables with their values so we can output all variable names with the following line of code:

print_r(array_keys(get_defined_vars()));

(more…)

How to start Apache OFBiz demo under Ubuntu Server 12.04

Install JDK 6 with the following command:

apt-get install default-jdk

Download the latest OFBiz version, extract it in your home directory and do the following steps described in the README file.

Having apache-ofbiz-XX.XX.XX as the current directory execute the following command:

./ant load-demo

(more…)

How to install Apache Tomcat 7 on Ubuntu Server 12.4 LTS

Today I successfully installed Tomcat 7 on Ubuntu Server 12.4 LTS with the following commands (executed as root):

apt-get install default-jdk
apt-get install tomcat7
apt-get install tomcat7-admin
apt-get install tomcat7-examples

(more…)