Server Setup - Gimle/phpFramework GitHub Wiki

Server Setup

This document describes how to setup a Gimle project, and some of the design choises that is made. This document assumes the setup is done on the latest version of ubuntu os. Although is is not required by any means, it is recommended to create a virtual machine and install a fresh copy of ubuntu server there. Set the vm up as you like, disk size, network config, etc. For the OS install, default settings will work just fine. You might end up installing more packages than you will need for your project. All is included here for convenience.

Replace yourusername with your actual username in the code below.

Why so complicated to install, most other sites will run on basically anything! Well there is a coupple of reasons for that. There is so much good stuff out there that people have made, so utilizing them sounds like a good idea. The design choice was made to use these libraries instead for trying to reimplement this in php. If there is better packages out there, or if new stuff comes to exist, these dependencies will probably change. For the server setup parts of it, there is many different ways to set it up, and the system should support a wide variety of setups. The one way documented here is just a default to make development easy.

Dependencies

Repositories

The latest version of ubuntu is shipped with php 7.0 and since Gimle requires php 7.1 a new repository needs to be added:

sudo add-apt-repository ppa:ondrej/php
sudo apt update

Optional setup

Install the packages

sudo apt install ssh samba vim curl sshfs git postfix mailutils

Set your default locale. The example below uses Norway as default locale, so change accordingly.

locale-gen nb_NO.UTF-8
dpkg-reconfigure locales -f noninteractive

When the system needs you to edit a file, eg when editing a git message, the default set editor will be used. To use your own preferred editor, make sure it is installed, and then set that as default.

sudo apt install vim
update-alternatives --config editor

Setup samba to preserve file attributes when accessing files in your home folder: editor /home/yourusername/.smbconfig

[yourusername]
path = /home/yourusername
valid users = yourusername
read only = no
create mask = 664
force create mode = 664
security mask = 664
force security mode = 664
directory mask = 0775
force directory mode = 0775
directory security mask = 0775
force directory security mode = 0775
map archive = no

Then edit editor /etc/samba/smb.conf and add include = /home/yourusername/.smbconfig to the end of that file. Set a password for your samba user: smbpasswd.

If you are planning to use sshfs to do mounting that the webserver should have access to, then enable this:

sudo sed -i s/#user_allow_other/user_allow_other/g /etc/fuse.conf

Give yourself a membership to the users group. The webserver can then later be set up as a member of the same group, and you will have access to edit the same files as the webserver for convenience.

sudo usermod -a -G users yourusername

To setup a git friendly prompt:

echo $'\n'PS1='\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$(__git_ps1 " [\[\033[00;33m\]%s\[\033[00m\]] ")\\\$ '$'\n' >> /home/yourusername/.bashrc

Create a folder for web development

mkdir -p ~/gimle/sites

Install Oracle Java

Some of the other dependencies are written in Java, so a java install is required for them to work.

add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java8-installer

Install php7.1 and dependencies

sudo apt install imagemagick mysql-server libyaml-dev php7.1, php7.1-common, php7.1-gd, php7.1-sqlite3, php7.1-mbstring php7.1-ldap php7.1-intl php7.1-cli php7.1-xsl php7.1-curl php7.1-mysql libav-tools webp ufraw-batch inkscape normalize-audio sox gnuplot-x11 timidity fontforge blender fop libsaxon-java libsaxonb-java cpulimit poppler-utils opensp	php7.1-dev php-pear

Once installed use pecl to install the rest

sudo pecl install zip
sudo pecl install yaml-2.0.0

Add these extensions to the php config:

echo "extension=zip.so" >> /etc/php/7.1/cli/php.ini
echo "extension=yaml.so" >> /etc/php/7.1/cli/php.ini

Install a webserver

Choosing Apache

Install the apache packages:

sudo apt install libapache2-mod-php7.1, libapache2-mpm-itk, apache2, libwww-perl

Add an apache config file: editor etc/apache2/conf-available/gimle.conf

<Directory ~ "/home/yourusername/gimle/sites/.*/public">
	Options Indexes FollowSymLinks
	AllowOverride All
	Require all granted
</Directory>

<VirtualHost *:80>
	ServerName localhost
	DocumentRoot /var/www/html

	<IfModule mpm_itk_module>
		AssignUserId www-data users
	</IfModule>

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

	php_flag display_startup_errors On
	php_flag display_errors On
	php_value error_reporting 2147483647
	php_flag track_errors On
	php_flag html_errors On
	php_value post_max_size 128M
	php_value upload_max_filesize 112M

	RewriteEngine On

	RewriteCond "/home/yourusername/gimle/sites/$1/public" -d
	RewriteRule "^/gimle/([^/]+)(.*)$" "/home/yourusername/gimle/sites/$1/public$2" [QSA,L]

	<Directory ~ "/home/yourusername/gimle/sites">
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		Allow from all

		RewriteEngine On
		RewriteCond %{REQUEST_FILENAME} !-f
		RewriteCond %{REQUEST_FILENAME} !-d
		RewriteRule ^([^/]+/)([^/]+/)(.*)$ /gimle/$1index.php/$3 [QSA,L]
	</Directory>

</VirtualHost>

Add the newly available config file to enabled config, enable some mods and restart apache:

echo "extension=zip.so" >> /etc/php/7.1/apache2/php.ini
echo "extension=yaml.so" >> /etc/php/7.1/apache2/php.ini
sudo a2enconf gimle
sudo a2enmod proxy_http
sudo a2enmod rewrite
⚠️ **GitHub.com Fallback** ⚠️