Skip to content

2. Installing

Jean J. de Jong edited this page Jul 11, 2024 · 38 revisions

The back-end for operating is a web server (Apache, PHP, MySQL, and a virtual host setup pointing to the public sub-folder...). You need MySQL version 8.0 or greater (or MariaDB 10.3 or greater), supporting virtual columns and window functions.

These instructions are provided for Ubuntu Server editions. They have been tested with Jammy (22.04). You may need to adapt them for other Linux distributions.

NOTE that the user interface has only been developed and tested with recent FireFox releases (60 is known to not work). There may be artifacts with other web browsers - share your issues with us.

0. Automated installation

A fully unattended installation script is available for a fresh install of a vanilla Ubuntu 20.04 server. Download it on your server, make it executable, and run it with sudo:

wget https://github.com/jjdejong/phpip/raw/master/doc/install-phpip-ubuntu.sh
chmod a+x install-phpip-ubuntu.sh
sudo ./install-phpip-ubuntu.sh 

You may then skip the rest of the below instructions up to the "Upgrading" section. If something doesn't work, check the below details.

You can only execute this script once, on a freshly installed Ubuntu system. If it fails, you need to finish the installation manually from the point at which it failed, using the instructions below.

1. Installing the required packages

Make sure your software is up to date and add the Universe repository. For Ubuntu 22.04 or below, add the ondrej/php repository to obtain the required version of PHP for Laravel. In a console, type:

sudo add-apt-repository universe -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt upgrade

1.1. Apache, PHP and MySQL

Install these and other needed dependencies (Git and Composer) as follows:

In a console, type:

sudo apt install apache2 apache2-utils mysql-server mysql-client php php-common libapache2-mod-php php-cli php-mysql php-json php-readline php-xml php-curl php-zip php-mbstring unzip git-core composer

Launch Apache and MySQL at startup:

sudo systemctl enable apache2
sudo systemctl enable mysql

Create the database phpip accessible with all privileges by user phpip with password phpip (change that in production!):

echo "CREATE DATABASE phpip DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER phpip@localhost IDENTIFIED BY 'phpIP2024!'; GRANT ALL PRIVILEGES ON phpip.* TO phpip@localhost; SET GLOBAL log_bin_trust_function_creators = 1;" | sudo mysql

(This command assumes that mysql has been freshly installed with default options, where no password is required for root when running mysql with sudo.)

The command SET GLOBAL log_bin_trust_function_creators = 1; is for MySQl >= 8, when binary logging is enabled. You probably also need to add the following to the my.cnf configuration file: log_bin_trust_function_creators = 1;

1.2. phpIP

The code can be installed anywhere with the virtual host approach, but it makes sense to install it in /var/www/phpip next to eventual other virtual servers. Note that, for security reasons, this is outside the /var/www/html folder, where the default Apache configuration points to. Create the folder and change its owner to yourself so that you don't need to use sudo to work there:

sudo mkdir /var/www/phpip
sudo chown <your login> /var/www/phpip

Clone the phpip Git repository to the folder /var/www/phpip:

git clone https://github.com/jjdejong/phpip.git /var/www/phpip

Install Laravel's dependencies:

cd /var/www/phpip
composer install

Create an .env file with your database credentials. You can copy the provided .env.example file (and tailor it later):

cp .env.example .env

Generate a fresh Laravel configuration:

php artisan key:generate
php artisan config:clear

Set some write permissions for the web server:

chmod -R g+rw storage
chmod -R g+rw bootstrap/cache
chgrp -R www-data storage
chgrp -R www-data bootstrap/cache

2. Configuring Apache and virtual host

This is maybe the most complex configuration section.

  • In the console, type:
sudo nano /etc/apache2/sites-enabled/phpip.conf
  • Paste the following in nano's edit window:
<VirtualHost *:80>
    ServerName phpip.local
    DocumentRoot /var/www/phpip/public
    ErrorLog /var/log/apache2/phpip-error.log
    CustomLog /var/log/apache2/phpip-access.log combined
</VirtualHost>
<Directory /var/www/phpip/public>
    AllowOverride All
</Directory>
  • Enable mod_rewrite in Apache:
sudo a2enmod rewrite
  • Save and reload Apache:
sudo systemctl restart apache2
  • You then need to create a DNS entry mapping name "phpip.local", i.e. the value of parameter ServerName in the above VirtualHost definition, to the IP address of your server. If this is obscure to you, the simplest is to add the following line in the "hosts" file of the workstations that will access phpIP:
<your server's IP address>    phpip.local

On Windows workstations, the "hosts" file is usually in: c:\windows\system32\drivers\etc\hosts

On Macs and Linux workstations, it is located in /etc/hosts.

Now point your browser to http://phpip.local.

You should see the welcome page and login link. You won't get past that, because you have no database yet.

  • If you are accessing phpIP on the Internet, you'll want to use HTTPS. The virtual host configuration file would then look something like this with Let's Encrypt certificates (change all occurrences of example.com to your domain).
<VirtualHost *:80>
  RedirectPermanent / https://phpip.example.com/
</VirtualHost>

<VirtualHost *:443>
  SetEnv HTTPS On
  ServerName phpip.example.com
  DocumentRoot /var/www/phpip/public
  SSLEngine on
  SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
  SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
  SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
  SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
  SSLProtocol All -SSLv2 -SSLv3
  ErrorLog /var/log/apache2/phpip.example.com-error.log
  CustomLog /var/log/apache2/phpip.example.com-access.log combined
  <IfModule mod_headers.c>
    Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
  </IfModule>
</VirtualHost>

<Directory /var/www/phpip/public>
  AllowOverride All
</Directory>

On Ubuntu, simply run certbot after setting up a virtual host on port 80 with a fully qualified domain name (in the phpip.conf file above change phpip.local to something like phpip.example.com). The HTTPS virtual host will be set up automatically on port 443, with a redirection of port 80 to 443.

To install the required certbot components:

sudo apt install certbot python3-certbot-apache

3. Database

3.1 Starting a new database

  • Run php artisan migrate --seed This creates a blank database with basic configuration. You're ready to go with the credentials phpipuser:changeme.

  • For playing around with sample data, further run

php artisan db:seed --class=SampleSeeder

3.2 Upgrading

The software is under continuous development and improvement, so a rolling release model is used. To stay up to date, regularly pull the new commits by running the following commands in the phpip installation folder (e.g. in /var/www/phpip):

  • git pull and
  • composer install (only required when you see the composer.json and composer.lock files updated)

The database structure may be updated too, so you need to apply the new migration scripts appearing in database/migrations. When you see such files being added, run the following in the installation folder, which will apply the latest scripts:

php artisan migrate

Upgrading to PHP 8.2 on Ubuntu 22.04 and earlier

Ubuntu 22.04 and earlier distributions do not provide PHP 8.2. Running composer install will fail. You need to run the following commands to upgrade PHP from a PPA repository:

sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt -y upgrade
sudo apt -y remove php7.4* php8.1* php-*
sudo apt -y install php php-common libapache2-mod-php php-cli php-mysql php-json php-readline php-xml php-curl php-zip php-mbstring composer
cd /var/www/html/phpip
rm -rf vendor/*
composer install

(Run the two last commands with the account that owns the phpip folder, or with sudo.)

3.4 Production

In production, you don't need all the packages used for development. Run the following to delete those:

composer install --optimize-autoloader --no-dev