Autonomía digital y tecnológica

Código e ideas para una internet distribuida

Linkoteca. PHP


I don’t use chroot, but the default setup for modern versions of FPM already compartmentalizes everything adequately for example, the private /tmp directory. I agree with others that chroot is an outdated way of doing things.

Also, I use SELinux…yet another way of achieving many of the same goals of chrooting. I’d highly recommend setting up SELinux if you are not already using it. If you’re concerned enough about security that you’d even think of chrooting php-fmp, you probably want to set up SELinux and have it on «Enforcing» (it’s useless on «Permissive» mode, that’s really only suitable for the configuration phase of test servers.) Not only will it provide security with PHP, but you get a whole bunch of other security benefits of it.

I have done some pretty sophisticated things with a web server under SELinux, requiring me to manually change a number of policies, and while I have had a few prolonged sessions of frustration, maybe 3-4 hours at a time of banging my head against the wall trying to get the permissions set up properly, it is totally worth it. It’s all up-front work, and once you learn how to do it it’s very easy.

# Install new PHP 8.3 packages
sudo apt install php8.3 php8.3-cli php8.3-{bz2,curl,mbstring,intl}# Install FPM OR Apache module
sudo apt install php8.3-fpm
# OR
# sudo apt install libapache2-mod-php8.2# On Apache: Enable PHP 8.3 FPM
sudo a2enconf php8.3-fpm
# When upgrading from an older PHP version:
sudo a2disconf php8.2-fpm## Remove old packages
sudo apt purge php8.2*

You can use the $options array to set the samesite value, for example:

setcookie($name, $value, [
‘expires’ => time() + 86400,
‘path’ => ‘/’,
‘domain’ => ‘domain.com’,
‘secure’ => true,
‘httponly’ => true,
‘samesite’ => ‘None’,
]);

The value of the samesite element should be either None, Lax or Strict.

function slugify($urlString) {
$search = array(‘Ș’, ‘Ț’, ‘ş’, ‘ţ’, ‘Ş’, ‘Ţ’, ‘ș’, ‘ț’, ‘î’, ‘â’, ‘ă’, ‘Î’, ‘ ‘, ‘Ă’, ‘ë’, ‘Ë’);
$replace = array(‘s’, ‘t’, ‘s’, ‘t’, ‘s’, ‘t’, ‘s’, ‘t’, ‘i’, ‘a’, ‘a’, ‘i’, ‘a’, ‘a’, ‘e’, ‘E’);
$str = str_ireplace($search, $replace, strtolower(trim($urlString)));
$str = preg_replace(‘/[^\w\d\-\ ]/’, », $str);
$str = str_replace(‘ ‘, ‘-‘, $str);
return preg_replace(‘/\-{2,}’, ‘-‘, $str);
}

Building a truly international application is not just about translating strings. Other issues to consider are date and time formats, currency symbols and pluralization. Programmers often underestimate the complexity of localization and get stuck with homemade code that is a pain to maintain. So, let’s talk about PHP Arrays, gettext, frameworks, and Intl.

Markdown Extra is an extension to PHP Markdown implementing some features currently not available with the plain Markdown syntax. Markdown Extra is available as a separate parser class in PHP Markdown Lib.