git clone with ssh vs https

Note that when you are using SSH, the address you clone begins with git@, and not with https://

If you are using bitbucket, you will get the error:

fatal: helper error (-1): Cannot access a disposed object.

And this is because you are not putting the right address to clone. As explained above, make sure you are using the one starting with git@

Host different domains with MAMP Free in Mac OSX

You would like to host several domains locally with MAMP in Mac OSX and you are wondering if this can be done with the free version, right?

Well, it is possible, you just need to configure a couple of files and you are done!

First of all, let’s remark that when you download MAMP and install it on Mac, it will create two separate apps within the Applications Folder:

MAMP

MAMP Pro

We are going to focus on the plain MAMP app, which is the one you can use with no cost.

You will notice than when you start up the app, you will see the content on http://localhost:8888. This content is hosted in folder:

/Applications/MAMP/htdocs

Note that this destination folder can be changed easily via GUI:

But let’s suppose you would like to host different webs locally. As an example, we will use mydomain.com Then you need to do this:

Edit /Applications/MAMP/conf/apache/httpd.conf in your favourite text editor or with command line:

sudo nano /Applications/MAMP/conf/apache/httpd.conf

At the bottom of the file, add the following

NameVirtualHost * 

<VirtualHost *> 
DocumentRoot "/Applications/MAMP/htdocs" 
ServerName localhost 
</VirtualHost> 

<VirtualHost *> 
DocumentRoot "/Users/YOURNAME/sites/mydomain.com" 
ServerName mydomain.com
</VirtualHost>

In DocumentRoot you may use the destination folder you wish

Additionally you have to add the domain to etc/hosts, you may do this:

sudo nano /etc/hosts

And just add your domain:

127.0.0.1 mydomain.com

Close the file.

Finally, add some content inside the destination folder,

sudo nano /Users/YOURNAME/sites/mydomain.com/index.html

<h1>Your domain mydomain.com is working!</h1>

And very importantly, restart the MAMP (click on Stop and then Start).

Thanks to evilReiko for this ServerFault solution

Hope it helped, thank you for reading!

Creating a Ruby on Rails 7 app on Heroku and Github

Creating the basic Ruby on Rails app and deploying to Heroku

I have restarted some development with Ruby on Rails. Since the v7 is now out I have tried to create a new app following the tutorial from Heroku here: https://devcenter.heroku.com/articles/getting-started-with-rails6. This tutorial is prepared for Ruby on Rails 6, but it has worked perfectly fine for me. BTW, I am using a MacBook M1, in case that helps you.

Adding the local git repo to your Github account

In order to add the repo to Github, you can follow this instructions: https://docs.github.com/en/get-started/importing-your-projects-to-github/importing-source-code-to-github/adding-locally-hosted-code-to-github. I followed the part “Adding a local repository to GitHub using Git” and it worked like a breeze.

The order of these two tasks is not critical, you may first create the repo, add a Github remote, and then follow the instructions to deploy it to Heroku.

The final result should look something like this, assuming you created an app locally in the myapp folder:

% git remote -v
heroku	https://git.heroku.com/your_heroku_app_name.git (fetch)
heroku	https://git.heroku.com/your_heroku_app_name.git (push)
origin	git@github.com:your_github_user_name/myapp.git (fetch)
origin	git@github.com:your_github_user_name/myapp.git (push)

Thank you Heroku for making it possible. And thank YOU for reading this blog

Problemas Autofirma con Mac OSX

Escribo este post en Abril de 2021.

La instalación de Autofirma para Mac OSX ha funcionado bien, pero cuando he ido a usarla en la web dgt.es me ha salido un error:

Error: No se ha podido comunicar con Autofirma

La solución al problema está en este documento: https://e-administracion.ulpgc.es/sites/default/files/AutoFirma_configuracion_manual_OSX.pdf

Básicamente hay que ir al Keychain y en cada una de las entradas para las siguientes firmas:

127.0.0.1

Autofirma Root

y tu firma digital

–> Hay que seleccionar Trust Always / Confiar siempre

Cannot update Ubuntu 12.04 to 14.04 in DigitalOcean

I recently faced the problem of not being able to update Ubuntu 12.04 to 14.04 in my DigitalOcean droplet.

Despite these great instructions: https://www.digitalocean.com/community/tutorials/how-to-upgrade-ubuntu-12-04-lts-to-ubuntu-14-04-lts

It did not work because there were missing files.

I had to manually edit the sources list

sudo nano /etc/apt/sources.list

And uncomment the original DEB package sources, and comment the Digital Ocean mirror packages.

Hope it helps!

Fixing a trailing slash problem in WordPress with Apache and Multisite Language Switch plugin

It has taken me a while to find this bug.

I was getting a “Too many redirect” problem in Apache, and went crazy to check where could be the origin of the problem. I got this error message from time to time, and this is very weird. Then there was a problem with the language multisite switcher, a great plugin that I highly recommend: https://wordpress.org/plugins/multisite-language-switcher/

Initially I thought it had to do with the “www” or canonical url, so I checked the DNS and so on. Then I thought it could be related to the WordPress multisite, since it has quite a complex url structure.

But finally I found the solution. The Multisite Language Switcher was generating urls of the type http://www.mysite.com/es (for exmample, for the Spanish version), and that causes a redirection error because it has to have the trailing slash “/” at the end, so the correct one would be http://www.mysite.com/es/

I went to the function that was generating the urls, the_msls (), and that led me to the file MslsOutput.php. In line 61 I added the slash:

$url = $mydata->get_permalink( $language )."/";

And now it works nicely!!!

I have to find out if there is a configuration in WordPress or Apache that automatically adds the “/” always. This was a random error, but it was provoking a toxic behaviour in Apache that is not acceptable.

Update: Apache documentation refers to this issue here: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

Trailing Slash Problem
Description:
Every webmaster can sing a song about the problem of the trailing slash on URLs referencing directories. If they are missing, the server dumps an error, because if you say /~quux/foo instead of /~quux/foo/ then the server searches for a file named foo. And because this file is a directory it complains. Actually it tries to fix it itself in most of the cases, but sometimes this mechanism need to be emulated by you. For instance after you have done a lot of complicated URL rewritings to CGI scripts etc.

Solution:
The solution to this subtle problem is to let the server add the trailing slash automatically. To do this correctly we have to use an external redirect, so the browser correctly requests subsequent images etc. If we only did a internal rewrite, this would only work for the directory page, but would go wrong when any images are included into this page with relative URLs, because the browser would request an in-lined object. For instance, a request for image.gif in /~quux/foo/index.html would become /~quux/image.gif without the external redirect!

So, to do this trick we write:

RewriteEngine on
RewriteBase /~quux/
RewriteRule ^foo$ foo/ [R]
The crazy and lazy can even do the following in the top-level .htaccess file of their homedir. But notice that this creates some processing overhead.

RewriteEngine on
RewriteBase /~quux/
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]