Programming
33 articles
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.
Turn PHP_SESSID off on an OVH shared server
In a .htaccess file, add:
SetEnv SESSION_USE_TRANS_SID 0
In your PHP code:
ini_set('session.use_cookies', '1');
ini_set('session.use_only_cookies', '1'); // PHP >= 4.3
ini_set('session.use_trans_sid', '0');
ini_set('url_rewriter.tags', '');
MySQL: dump the encoding hell
I have encountered this issue in MySQL version 5.1.x, but not in 5.5 (I have not tested other versions): generating a dump of a UTF-8 encoded database (Collation: utf8_general_ci) resulted on non-ASCII characters (like "éà ç") being garbled.
I am used to backup databases with this mysqldump command:
$ mysqldump -h hostname -u username -p databaseName > backup.sql
I never had to worry about encoding since I use UTF-8 everywhere. But when I tried to import a dump file from 5.1 to 5.5, there were weird symbols like àƒ© àƒ§ all over the place! A workaround is to dump the database using the latin1 charset:
$ mysqldump -h hostname -u username -p --default-character-set=latin1 --databases databaseName -r backup.sql
The -r option outputs the data directly into backup.sql, avoiding risks of additional encoding interferences while passing through the underlying system.
Before importing the data, edit the dump file to replace the line
/*!40101 SET NAMES latin1 */;
with
/*!40101 SET NAMES utf8 */;
Finally import the dump file:
$ mysql -u username -p --default-character-set=utf8 databaseName
MariaDB (MySQL): retrieve database collation
In the MySQL prompt:
> SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'databaseName' LIMIT 1;
+------------------------+
| DEFAULT_COLLATION_NAME |
+------------------------+
| utf8_general_ci |
+------------------------+
Git: push a tag when the remote is up-to-date
I started using tags a few weeks ago, after reading "A successful Git branching model".
Update: tags are not pushed along without the --tags option. Tags are simply pushed along with the usual git push command. However, if a tag is created after pushing the latest commit, another git push just ignores it. To explicitly tell Git to push a tag called tagName:
$ git push origin tagName
The following command push all the tags:
$ git push --tags