setup LAMP

Linux Apache2 MariaDB PHP7.3

su - root; # become root
apt update; # update system to latest
apt upgrade;

# database first
apt install mariadb-server mariadb-client

# set root pwd for database (can be root on dev test server)
mysql_secure_installation

# install webserver
apt install apache2

# install php
apt install php7.3 libapache2-mod-php7.3

# restart webserver
service apache2 restart

# make sure php works
vim /var/www/html/info.php
# fill with
<?php
phpinfo()

# then point browser to
http://localhost/info.php

one should see something like this:

this just means php works with apache2.

congratulations!

time for one’s first celebration dance!

install more stuff: (might be optional)

apt install php7.3-mysql php7.3-curl php7.3-gd php7.3-intl php-pear php-imagick php7.3-imap php-memcache php7.3-pspell php7.3-recode php7.3-sqlite3 php7.3-tidy php7.3-xmlrpc php7.3-xsl

service apache2 restart

# phpmyadmin is still a pretty nice web based
# mysql-mariadb management gui
# based on https://phoenixnap.com/kb/how-to-install-phpmyadmin-on-debian-10
cd /var/www/html
wget https://files.phpmyadmin.net/phpMyAdmin/5.1.0/phpMyAdmin-5.1.0-all-languages.zi
(sha512sum ded55db84f54e51429cf6463a5ade5b5b1859d6b917d340ccf265e6860381d80f6d62eacc29672280574c21f95d77cb14c649b1f8e000d34cd9a85514d06765e)
unzip phpMyAdmin-5.1.0-all-languages.zi
mv phpMyAdmin-5.1.0-all-languages phpmyadmin
cd phpmyadmin
config.sample.inc.php config.inc.php
# setup config
vim php config.inc.php
# search for this line and change this value
cfg['blowfish_secret'] = 'root'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
chmod 660 /var/www/html/phpmyadmin/config.inc.php
chown -R www-data:www-data /var/www/html/phpmyadmin
systemctl restart apache
# point browser at http://localhost/phpmyadmin, should be greeted with this login:

# btw did the dev-user know, one can create user+database in "one go" like this:



# or try the alternative: "adminer"
cd /var/www/html
wget https://github.com/vrana/adminer/releases/download/v4.7.6/adminer-4.7.6
mv adminer-4.7.6.php adminer.php

# before one can login as root:root
# creditz for this go to https://websiteforstudents.com/manage-mariadb-mysql-databases-with-adminer-and-apache2/

# login into mariadb
# the "new" mysql (that's why it is still called mysql)
mysql -u root
# if that fails try (and give root pwd)
mysql -u root -p

# copy and paste those commands:
use mysql;
update user set plugin='' where User='root';
flush privileges;
exit

# restart mariadb
systemctl restart mariadb.service

xdebug + pdt eclipse for php:

mkdir /software
# download eclipse
wget https://mirrors.dotsrc.org/eclipse//technology/epp/downloads/release/2020-03/R/eclipse-php-2020-03-R-linux-gtk-x86_64.tar.gz;

cd /software
tar fxvz eclipse-php-2020-03-R-linux-gtk-x86_64.tar.gz;

# install xdebug
apt install php-xdebug

# probably optional:
# alternative compile from latest source way of installing xdebug
apt install php-dev
pecl install xdebug

would replace firefox-esr with firefox

mkdir /software
cd /software
wget https://download-installer.cdn.mozilla.net/pub/firefox/releases/76.0/linux-x86_64/en-US/firefox-76.0.tar.bz2
tar fxv firefox-76.0.tar.bz2

cd /usr/bin
# unlink firefox-esr (default debian 10 firefox version)
unlink firefox
# create new link to latest manual download firefox 76
ln -sv /software/firefox/firefox

start and config eclipse:

eclipse is a bit complex. one has been warned X-D

# start eclipse pdt
/software/eclipse/eclipse

let eclipse know where php (go to terminal and type: which php) and php.ini (can be found in info.php) is:

and it shall use xdebug as default debugger:

xdebug settings:

enabling Xdebug:

this is absolutely essential (or eclipse will hang with “waiting for xdebug session…” forever and ever…)

enabling Xdebug in Debian 10: add the following to /etc/php/7.3/mods-available/xdebug.ini:

cat /etc/php/7.3/mods-available/xdebug.ini 
zend_extension=xdebug.so
xdebug.profiler_enable_trigger = 1
xdebug.profiler_enable = 0
xdebug.remote_enable = 1
xdebug.profiler_output_dir = "/tmp"

Restart Apache:

service apache2 restart;

creditz: https://drupaland.eu/article/installing-and-enabling-xdebug-debian-9

pray! and run! X-D

if everything works as planned one can start a debug session like this:

eclipse start firefox with url problem:

if one wants to use external browser firefox, there might be a problem: firefox should launch one’s whateverfilename.php with the ?XDEBUG_SESSION_START parameter…

if not and xdebug “hangs” with “waiting for xdebug session…”

then open a terminal and check if firefox was not starting correctly (starts in background than crashes X-D)

ps uax|grep firefox

(eclipse tries to open firefox via: -openURL(%URL%) but does not seem to work (anymore?), guess it is a eclipse specific problem, eclipse could just start /usr/bin/firefox %URL% should work)

# example, firefox 78.7.0esr (64-bit) does not seem to like to start like this anymore
firefox-esr -remote openURL(http://localhost/project/index.php?XDEBUG_SESSION_START=ECLIPSE_DBGP&KEY=16136735518102)

workaround: use the default settings (eclipse’s internal browser)

so instead of: tell eclipse to use firefox external browser

just go with the eclipse internal browser:

in the vm: have added firefox to external tools or manually opening firefox with XDEBUG_DESSION_START=KEY works too.

expected result:

… eclipse should “pause” / report that a debug session has started and freeze at the first line of php code: 🙂 (F5 -> step step, F8 -> keep running)

CONGRATULATIONS! ONE MADE IT!

XDEBUG IS WORKING! 🙂

one can no very very nicely debug all sorts of php requests DIRECTLY on the server.

imho xdebug is ABSOLUTELY FANTASTIC! THANKS ALL INVOLVED! GREAT GREAT JOB!

have nothing seen like this anywhere else! (although it is said that c programs could be remote debugged with gdb, but that is an art in itself X-D)

CELEBRATE!

CELEBRATE!

CELEBRATE!

one can download the whole vm here:

once it runs: get meaningful php debug error warning output

it is not always “clear” where php will output the errors & warnings…

for example: the function split is DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0

and needs to be replaced with “explode” (this is kind of the annoying stuff about php updates… they keep changing function names, but usually only minor changes to “has worked before” php code have to be made)

the file.php simply “quits” without warning or error when split is called

so there is per default no error output in the browser unless…

# put this on the very top of file.php to enable errors & warnings in browser
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
  1. the developer puts at the very top of the file.php
  2. the developer modifies php.ini
    • but then still… it does not output in browser but in log file! (this script is very helpful in finding that log file)
    • so… if the developer runs GNU Linux Debian 10 + apache2 + PHP7 the /var/log/apache2/error.log is the file where errors and warnings are written to/logged
    • a simple tail -f /var/log/apache2/error.log does the job too 🙂

      • (but it is usually more convenient having development & errors displayed all in the same window… not having to switch back and forth… okay here come two-monitor solution in to play (have browser on right monitor, and eclipse dev environment on left monitor)

improving handling: shortcuts & hotkeys

when tasks have to be repeated very often… clicking around in menus and sub-menus costs a lot of time (every millisecond counts 🙂

to start debug session:

to stop debug session:

note: want to work with firefox?

the developer does not need to restart (Ctrl+F2, wait, complicated hotkey) the debug session, after code changes, just hit F5 in firefox (it is basically a “hot reload”)

Downloads:

Oracle Virtualbox VM: Debian10 + LAMP + PHP7.3 + XDebug + MariaDB + Adminer + Eclipse PDT

1) install https://www.virtualbox.org/

download:

https://dwaves.de/software/php/devphp_xdebug_Debian10_.tar.xz (right now 404… will upload soon…)

https://dwaves.de/software/php/devphp_xdebug_Debian10_.tar.xz.sha512sum.txt (right now 404… will upload soon…)

2) simply double click the devphp_xdebug_Debian10_.vbox should import the vm and user should be able to run immediately

so filesize wise xz compresses better than bzip2 which compresses better than gzip, so xz (J) was used:

# archive was created like this
tar fcvJ devphp_xdebug_Debian10_.tar.xz devphp_xdebug_Debian10_;
sha512sum devphp_xdebug_Debian10_.tar.xz > devphp_xdebug_Debian10_.tar.xz.sha512sum.txt;

# check integrity
sha512sum -c devphp_xdebug_Debian10_.tar.xz.sha512sum.txt
# unpack
tar fxvJ devphp_xdebug_Debian10_.tar.xz

project management:

===== project management
all projects are stored on host (directly on hardware) in folder /projects or /home/user/projects

host will do git management (commit)

vm will mount the host’s project folder (it’s a bit complicated, because of access-rights permission problems (webroot default user www-data)

=== project access on vm

1) configure “shared folder” to share host-folder “projects” (where projects shall be stored on host) with vm

2) bindfs to /var/www (default web root apache & xdebug workspace)

two scripts are used (on startup, activate rc.local)

/scripts/batchBindProjects.sh

#!/bin/bash
# bind projects into workspace
/scripts/bindfsProject.sh projectName1
/scripts/bindfsProject.sh projectName2

/scripts/bindfsProject.sh

#!/bin/bash
# mounts PROJECTNAME into apache2 default web root/user's workspace /var/www/html
PROJECT=$1; # specify projectname
# create mountpoint
mkdir -p /var/www/html/$PROJECT;
# bind-mount project as www-data:www-data
bindfs -u 33 -g 33 /media/sf_projects/$PROJECT /var/www/html/$PROJECT/;

Links:

https://xdebug.org/

https://github.com/xdebug/xdebug

buy him many cups of coffee!-> https://derickrethans.nl/

inspiration was also taken from: https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/

and: https://websiteforstudents.com/manage-mariadb-mysql-databases-with-adminer-and-apache2/

thanks all involved! GREAT JOB!

admin