Programming
32 articles
Execute a local bash script through SSH
Before this blessed day, I lost my time copying my bash scripts on the remote machines where I wanted to execute them through the ssh command. Until now, when I discovered that it is not necessary, thanks to the bash -s flag.
$ ssh user@remote 'bash -s'
Linux/Windows: generate a SSH key for the http (Apache) user
I recently added a feature to a PHP web application, requiring to run an independent bash script, which connects remotely to another machine through SSH.
When I tested the bash script in command line, it was running with my credentials and used my ~/.ssh/id_rsa.pub to authenticate itself to the remote machine. But when the script was launched by PHP, itself launched by Apache, those credentials were not available. I tried ssh -i but obviously (everything seems logical afterwards ;-) it couldn't use my private key.
The solution is to have Apache create its own private/public key pair:
$ sudo -u http ssh-keygen -t rsa
$ sudo -u http ssh-copy-id username@servername
We use sudo -u to execute ssh-keygen as http user. On Arch Linux, this is the "name" of Apache. It may be different on your system.
On Windows Server, Apache runs by default as NT_AUTHORITY/SYSTEM. The trick here is to run it under another existing user account. To set that option, open Administrative Tools > Services. In the Services window, select Apache2.x > right click > Properties > Log On tab > check "This account" and enter/browse the account of your choice (or create one first) > Apply and restart the service:
Git: edit a tag
Beware that this command change the original tag's date. To edit a tag called tagName:
$ git tag tagName tagName -f -m "new message"
CSS: make a container wrap around its floating children
When an element contains floating elements, its height does not include the height of the floating elements because they are outside the natural flow of the document. To make the container aware of all the heights inside it, we can use the overflow property:
HTML:
<p>
<a class="floatRight">I am floating!</a>
</p>
CSS:
p {
overflow:auto;
}
a.floatRight {
float:right;
}
Apache 2.4 upgrade on Arch Linux
Update: Here is the follow-up, using Apache 2.4.9
This article has been written from memory afterwards, so it may be imprecise and/or incomplete but contains the main steps to a successful migration. I plan to complete it when I'll upgrade another machine. You should be able to find the missing instructions by following this thread on the Arch Linux forum.
After the upgrade from 2.2.x to 2.4.x, Apache throws an error because the current PHP package is not thread-safe. An option is to recompile it (not tested), another is to use the PHP FastCGI Process Manager:
$ yaourt -S php-fpm
and the already included Apache module mod_proxy_fcgi. Uncomment the following lines in /etc/httpd/conf/httpd.conf:
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
then comment this one:
#LoadModule mpm_event_module modules/mod_mpm_event.so
and add the mod_proxy_handler module:
LoadModule proxy_handler_module modules/mod_proxy_handler.so
We need to write proxy rules to avoid bad request or file not found errors. The path must be adapted to your configuration:
ProxyPassMatch ^/(.*.php(/.*)?)$ fcgi://127.0.0.1:9000/srv/http/www/$1
ProxyPassMatch ^/$ fcgi://127.0.0.1:9000/srv/http/www/index.php$1
In /etc/php/php-fpm.conf, change the listen directive:
listen = 127.0.0.1:9000
;listen = /run/php-fpm/php-fpm.sock
Activate the php-fpm service:
$ sudo systemctl enable php-fpm.service
Replace "enable" with "start" if you do not want/need it to start automatically at each boot; but you will have to start it manually whenever you need it to avoid Apache throwing a 503 "service unavailable" error.
