Sunday, May 31, 2020
Domain serving SSL certificate of a subdomain
Today one of my sites was serving a SSL certificate of a subdomain instead of the domain's one, after configuring the SSL certificate for the subdomain with certbot for Apache.
It took me some hours of investigating and tries.
The problem is that certbot changed the domain.conf file in /etc/apache2/sites-available folder to serve the subdomain's SSL certificate. Editing the file and reloading Apache solved it.
Wednesday, January 8, 2020
Time adjustment for DigitalOcean droplets
I have some droplets on DigitalOcean, but I noted that the system time (in all of them) is not correctly synced with NTP servers.
The solution that worked for me is to include the following line at the end of /etc/crontab:
* * * * * root /sbin/hwclock -s
That command instructs the system to copy time from hardware (which is more precise) every minute. That solved my problem.
Friday, December 27, 2019
Troubleshooting Ruby 2.7 compiler errors
So Ruby 2.7 was released at Xmas'19 and I got some errors when compiling it in Linux Mint 19.1. Some libraries were not configured. The errors ocurred at the linking phase of make. Five libraries got errors, and I'll walk across their solutions:
- openssl:
sudo apt install libssl-dev - gdbm:
sudo apt install libgdbm-dev - dbm:
sudo apt install libqdbm-dev - readline:
sudo apt install libedit-dev - zlib:
sudo apt install libz-dev
cd /lib/x86_64-linux-gnu/
sudo ln -s libz.so.1 liblibz.so
Enjoy!
Saturday, October 27, 2018
Net::HTTP error sending GET request with parameters
For example (assuming that parameters is not empty), instead of
http = Net::HTTP.new('server.com')
http.send_request('GET', path, parameters, headers)
try:
http = Net::HTTP.new('server.com')
http.send_request('GET', path + '?' + parameters, '', headers)
Net::HTTP error 400 (bad request) with HTTPS
Yesterday I got stuck when trying to connect to an HTTPS site using Net::HTTP:
http = Net::HTTP.new('server.com', 443)
response = http.send_request('GET', path, parameters, headers)
I was getting error 400 in response.code.
What is not well documented is that when accessing a server via HTTPS protocol it's not enough to set port to 443. You must also set use_ssl to true:
http.use_ssl = true
response = http.send_request('GET', path, parameters, headers)
I found that by seeing code at http://www.rubyinside.com/nethttp-cheat-sheet-2940.html.
Wednesday, August 31, 2016
How to install mysql2 gem on Ubuntu
# apt-get install build-essential ruby-dev libmysqlclient-dev
Monday, April 21, 2014
Installing Ruby 2.1.1 in Ubuntu 14.04
./configure --with-readline-dir=/usr/lib/x86_64-linux-gnu/libreadline.so
make
make install
on the directory of the unpacked source of Ruby 2.1.1, as root. I suspect there is a more elegant solution out there, but this is enough for me at this time.
Friday, March 7, 2014
LOAD DATA INFILE tips
- copy the CSV file to the DB folder (/var/lib/mysql/DATABASE), and
- use the filename only, not the full path.
If you're having troubles with LOAD DATA LOCAL INFILE ("The used command is not allowed with this MySQL version"):
- temporary solution: mysql -uUSER -p --local-infile DATABASE
- permanent solution: sudo nano /etc/mysql/my.cnf and insert local-infile under [mysql]; save the file, close the editor and type sudo service mysql restart.
Note: LOAD DATA LOCAL INFILE uses IGNORE. If you want to know why some records were skipped, you must use LOAD DATA INFILE (without LOCAL). (Reference)
Tuesday, September 24, 2013
How to change the default mode for php files in Kate Editor
But you can set the default mode to PHP/PHP by changing its priority compared to PHP (HTML)'s.
That's how I did it:
- Go to Settings -> Configure Kate -> Open/Save -> Modes & Filetypes;
- Select Scripts/PHP (HTML) Filetype;
- Change Priority to 4;
- Select the File Extensions field and copy it;
- Select Scripts/PHP/PHP Filetype;
- Go to the File Extensions and paste the content copied;
- Hit Apply and Ok;
- Close and reopen Kate.
I was hard to find that solution (see reference); I hope this can be useful.
Wednesday, February 27, 2013
SQLite3 in Ruby 1.9: be sure your Ruby data is UTF-8
Text data in SQLite is UTF-8. Before Ruby 1.9, Strings had no encoding; so that was not a issue; all data get same handling. From Ruby 1.9, Strings must be encoded as UTF-8 to be compatible with SQLite data; otherwise your text will be considered binary content to SQLite, and binary content won't match plain-text content, even when they are the very same bytes.
Maybe the source of your text data encodes them as other than UTF-8. To make sure your data is UTF-8, try using String#encode or String#force_encoding before submit it to SQLite 3. Cheers!
Thursday, January 31, 2013
Sequel blocking SQLite3?
There are things to be investigated, but this tip can be useful to someone as a quick (temporary?) solution.
Monday, July 23, 2012
Problems with permission in Apache
Saturday, July 14, 2012
RVM + Apache + CGI Scripts
I've configured a new server on Ubuntu 12.04 and I started to use RVM, an excellent version manager which permits to have multiple versions of Ruby installed on a single server (and many versions of the gems - see gemsets), and it makes easy to switch among them.
I've installed RVM under my user (as myself, not as root with sudo) by following the Ryan Bigg's guide, with no previous system-wide installed Ruby. So, I didn't have any Ruby under /usr/bin. My first task then was to replace the shebang line of all my CGI scripts, from
!#/usr/bin/ruby
to
!#/usr/bin/env ruby # encoding: utf-8
(The second line is needed to define the encoding of the string literals in my code, for Ruby 1.9.)
However my scripts didn't run under Apache. In the terminal I could run them (by typing ./index.cgi, for example), but not over a browser. A relevant note: in both the user is the same, i.e., the Apache user is the same as the one logged on terminal. Through php tests, I've checked the RVM enviroment was not loaded under Apache. (If anyone can solve that, please let me know.)
I saw this tip for running CGI scripts with RVM, which suggests to put the complete path of specific version of Ruby in the shebang line. That can be useful if you have scripts which run on different versions of Ruby. But that solution doesn't work for me, because my scripts must run on different machines, with different users, different ruby versions and different paths.
The solution which works for me is to put a symlink of the desired Ruby version under /usr/bin:
sudo ln -s /home/sony/.rvm/rubies/ruby-1.8.7-p370/bin/ruby /usr/bin/ruby
(Notes: sony is my username and I chose 1.8.7 because by now my scripts aren't 1.9-compliant yet.)
Therefore I didn't need to have changed the shebang lines. :) But I guess that will be useful in the future.
Tuesday, May 22, 2012
How to UPDATE a table using data from another row
Here I'll assume the rows must be sorted by num, but it would be sorted by another field, like id or timestamp.
The solution in MySQL is to use a inline temporary table to get the num of next row and associate it with current id, and use that table in the UPDATE statement.
Here is the code. Enjoy!
-- the table used for test (MySQL syntax) CREATE TABLE `test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL, `num` int(11) NOT NULL, `diff` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ; -- some values to play on INSERT INTO `test` (`id`, `name`, `num`, `diff`) VALUES (1, 'a', 10, NULL), (2, 'b', 8, NULL), (3, 'a', 18, NULL), (4, 'a', 21, NULL), (5, 'b', 14, NULL), (6, 'a', 32, NULL), (7, 'b', 20, NULL), (8, 'b', 21, NULL); -- a select to test the ability to retrieve the desired diff value select id, name, num, (select min(num) from test where name = t1.name and num > t1.num)-num from test t1 where diff is null order by name, num; -- updating test with the calculated diff using another row on same table. update test t2, ( select id, (select min(num) from test where name = t1.name and num > t1.num)-num as diff from test t1 ) t3 set t2.diff = t3.diff where t2.id = t3.id and t2.diff is null
-- an alternative query to get more than one column from t2
select t1.id, t1.name, t1.num, t2.name, t2.num from test t1, test t2 where t2.id = (select id from test where name = t1.aome and num > t1.num order by num limit 1) order by t1.name, t1.num
See this post in portuguese.
Tuesday, March 6, 2012
How to install sqlite3-ruby gem on linux
In systems with apt-get:
# apt-get install libsqlite3-devIn systems with yum:
# yum install sqlite-devel
How to install bson_ext gem on linux
In ubuntu (10.04 32bit) I had to run:
# apt-get install ruby1.8-devIn systems with yum I had to run:
# yum install gcc
# yum install make
# yum install ruby-devel
Finally in both systems I could run, with no errors:
# gem install bson_ext
