May 6, 2021

php howto

PHP is really versatile, but mostly used in websites where you want to use dynamic data, like from a mysql database and then display it as html in a browser. Nowadays most people use php5, which you can install like:

apt-get install php5

if you want to know what options are enabled after that (in your /etc/php5/apache2/php.ini) from command line do:

php -i | less

If you want to code php on your computer, you can use something like Eclipse, which is really great and free, but can be pretty confusing, and you still may have to upload it to a server to get it run, usually with FTP, so hopefully that’s installed on your server where your website is uploaded to.

Php has to be enabled on your webserver too, usually with apache2 (or nginx). You can make sure it’s enabled by installing:

apt-get install libapache2-mod-php5

php7

Php7.x is probably the way to go nowadays, but you have to migrate old code to it to make it work sometimes.

php5 > php7 migration

There is a tool that tells you what code in 5 won’t work in 7 called php7mar, which you can get on github

git clone https://github.com/Alexia/php7mar.git
cd php7mar
php mar.php -f="/var/www/infrastructure.php"
root@host:/usr/src/php7mar > php mar.php -f="/var/www/infrastructure.php"
Report located at: /usr/src/php7mar/reports/2020-07-20 08.43.00 infrastructure.md
root@host:/usr/src/php7mar > cd reports/
root@host:/usr/src/php7mar/reports > cat 2020-07-20\ 08.43.00\ infrastructure.md
2020-07-20T08:43:00-07:00
Scanning /var/www/infrastructure.php
Including file extensions: php
Processed 879 lines contained in 1 files.
Processing took 0.10804390907288 seconds.
 
# critical
#### /var/www/infrastructure.php
* deprecatedFunctions
 * Line 18: `@mysql_select_db($database) or die( "Unable to select database");`
 * Line 30: `$result = mysql_query($query);`
 * Line 31: `$result1 = mysql_query($query1);`
 * Line 32: `$result2 = mysql_query($query2);`
 * Line 33: `$result3 = mysql_query($query3);`
 * Line 34: `$result4 = mysql_query($query4);`
 * Line 35: `$result5 = mysql_query($query5);`
 * Line 36: `$result6 = mysql_query($query6);`
 * Line 37: `$result7 = mysql_query($query7);`
 * Line 38: `$result8 = mysql_query($query8);`
 * Line 39: `$result9 = mysql_query($query9);`
 * Line 40: `mysql_close();`
 * Line 344: `	while ($row1 = mysql_fetch_array($result1))`
 * Line 367: `	while ($row = mysql_fetch_array($result))`
 * Line 396: `	while ($row = mysql_fetch_array($result2))`
 * Line 698: `        while ($row = mysql_fetch_array($result9))`
 * Line 727: `        while ($row = mysql_fetch_array($result3))`
 * Line 754: `        while ($row = mysql_fetch_array($result4))`
 * Line 781: `        while ($row = mysql_fetch_array($result7))`
 * Line 811: `        while ($row = mysql_fetch_array($result8))`
 * Line 838: `        while ($row = mysql_fetch_array($result5))`
 * Line 865: `        while ($row = mysql_fetch_array($result6))`

This tells you some mysql function (which would now be mariadb anyway) isn’t working, so you can google to find the answer.