Since 10 November our faculty has a new website! The old website will still be available at oldwww.fi.muni.cz for now. Something is broken? Please report it to webmaster@fi.muni.cz or use our webform.

translated by Google

Instructions for use on PHP on FI

First, go to our directory /home/xlogin/public_html create a file .htaccess (must have "r" access for others). Let's note that .php files are scripts and run as scripts:

DirectoryIndex index.php
AddHandler cgi-script .php
AddType application/x-httpd-php .php

In order for the PHP script to run, it must have "x" access for the owner (PHP scripts are triggered under your identity).

If you have a Web site management right on Aise, located elsewhere than below /home/xlogin/public_html/ , these PHP scripts need to allow "x" access for users apachefi , otherwise they will not work. Adding this right is ideally possible with the command

setfacl -m u:apachefi:x soubor.php

Furthermore, its first line must be a string #!/packages/run/php/bin/php . It is not necessary to insert this string into files that do not run directly, but are just inserted with include .

Coding

The default encoding is set for historical reasons on ISO8859-2 . New applications should be used UTF-8 , both for program code and for possible HTML files.

In PHP, set the encoding by adding this command to the beginning of the program:

ini_set('default_charset', 'UTF-8');

Set HTML encoding in a file .htaccess :

AddDefaultCharset utf-8

For more information, see Encoding of Czech in documents .

Example PHP script

#!/packages/run/php/bin/php
<?php ini_set('default_charset', 'UTF-8'); ?>
<html>
<?php
  echo strftime("%H:%M:%S\n");
?>
</html>

FastCGI

If you want to use FastCGI, edit v .htaccess directive AddHandler :

DirectoryIndex index.php
AddHandler fastcgi-script .php
AddType application/x-httpd-php .php

FastCGI scripts are not re-launched at each request, but serve them more. This may cause an accelerated response of the application, but on the other hand not all applications are ready for this mode of use.

How to deal with problems

A useful resource for more detailed error information is the Apache logs. They can be found on the Aisa server located in /var/log/httpd/ , specifically error.log , eventually suexec.apachefi.log .

When debugging errors, it is also preferable to use CGI instead of FastCGI. The error logs are then clearer, and running the script over the web is more responsive.

The PHP script should also be directly executable on the command line. Correct Output Example:

aisa:/home/xlogin/public_html>$ ./index.php
X-Powered-By: PHP/5.6.30
Content-type: text/html; charset=UTF-8

<html>
10:04:01
</html>

Examples of possible errors in case of unsuccessful startup index.php :

Security of error logs

Since error logs are accessible to all users for reading, logging of some PHP errors can pose a security risk. These are, for example, messages containing access data.

In this case, you can consider logging errors into your own file. This can be accomplished by creating your own PHP configuration file user.ini , which you place in the directory public_html . This file should have at least the "r" access right for the owner and should contain a line

error_log = /home/xlogin/php.log

Consequently, the error messages should be logged in the file. Of course, it is advisable to secure this file before accessing other users. Therefore, we recommend that you create this file manually with the appropriate permissions, otherwise you will be created with read permissions when writing the first error. At a minimum, the "w" right for the owner and the file path should be accessible to you - logging takes place again under your identity. Alternatively, if the directory in which you want to save this file is accessible only to you (right "x" for the owner), you can create the file automatically.