How to install Laravel (5.6) on Uberspace (7)
Published 2018-07-16, 12:57
Laravel is a great PHP framework, and Uberspace is a great and nice PHP host. Why not mix both?
Installing Laravel on shared hosting – which Uberspace still is despite the shell access etc. – can be difficult, especially because of public
folder that is used to respond to requests instead of the project root.
Here are the basic instructions for getting a new Laravel project to respond to calls of your <username>.uber.space
domain:
- Switch folder to
/var/www/virtual/<username>
. composer global require "laravel/installer"
to install the Laravel Installer.- Create a new Laravel project:
laravel new <projectname>
. - Delete
/var/www/virtual/<username>/html
(make sure it is empty, or just rename it maybe) and replace it with a symlink fromhtml
to<projectname>/public
. - The default Laravel start page should now be available at your
<username>.uber.space
.
To be able to use the database in the project, you have to make some changes:
- Get your generated MySQL password from
~/.my.cnf
. - Update the
.env
file in your Laravel project:
Username and database should be changed to your username, the password to the one you just retrieved. - Caution: At the time of writing Uberspaces uses MariaDB 10.1.34 (find out by using the command
mysql -v
). Laravel needs some tiny changes if you work with MariaDB <10.2.2:- Edit the
app/providers/AppServiceProvider.php
file and add the following:use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); }
(Add both the method call and the import!)
- Edit the
- Now you can run
php artisan migrate
in your Laravel project to create the default tables.
Of course you probably don’t want to host your project at your uber.space
domain, not create a new project but check out your already developed project from git, and also not use the default database – but I am sure you can find your way from here.
Laravel Homestead: Run phpunit with another PHP version
Published 2018-06-22, 13:09
Laravel Homestead is a nice development environment/server, that comes with multiple PHP versions installed. You can configure each project you are running through it for its own PHP version, and use e.g. php5.6
on the command line to execute code with a specific PHP version. Unfortunately phpunit
always uses the default PHP version. What if the PHPUnit you installed in a project needs a specific PHP version to work and execute your tests (for example because the whole project only works with PHP 5.6)?
You can run phpunit with a specific PHP version by using this command:
php5.6 vendor/phpunit/phpunit/phpunit
Laravel 4, Eloquent: Check if there is a Model with certain key-value pair in a Collection
Published 2013-10-17, 16:47
I wanted to find out if there already is a Model with a certain value for a certain column in a Collection that I retrieved realier in my code, e.g. is there already a User with name = Müller in my $users Collection?
$users->contains() can only check if there is a model with a certain primary key, and there also is no method to trivially search through all Models. Of course this all could be hacked together somehow*, but after a bit of searching I found this nice way to solve my question:
$value = 'Müller'; $key = 'name'; if(in_array($value, $users->lists($key))) { ... }
Collection->lists() gets an array with all the values of the Model for the requested key. Checking if our new value is in there, is super simple.
*Of course I first tried it this way:
- use $collection->filter() and then count the result
- hack $collection->contains() +$collection->find() to accept a field name as a parameter
- see 2, but copy the methods as private methods to my controller instead of tinkering with the framework code directly
All 3 solutions worked, but needed lots of ugly code.
PHP Frameworks
Published 2013-10-02, 11:16
As I’m getting back into working with PHP more hands-on I spent some time to look around to build this small overview of PHP frameworks. I seperated them into 3 groups: Most popular, Others and Obscure / Ancient / Dead.
Most popular
- http://framework.zend.com/
- http://symfony.com/
- http://cakephp.org/
- http://ellislab.com/codeigniter
- http://kohanaframework.org/
- http://www.yiiframework.com/ + https://github.com/yiisoft/yii
- http://fuelphp.com/
- http://laravel.com/ + https://github.com/laravel/laravel
Google Trends graphes
To be able to assess the popularity, these simple Google Trend charts may help:
The „old guys“
(WTH happened in October 2009?)
The „new guys“ (+ ZF for comparison)
Please note, that many people probably only search for „Zend“ to find Zend Framework.
Others
- http://flow.typo3.org/
- http://silex.sensiolabs.org/ (Micro Framework)
- http://phalconphp.com/en/ (Speed!)
- http://www.slimframework.com/ (Micro Framework)
- http://www.yafdev.com/+ https://github.com/laruence/php-yaf (Speed!)
- http://lithify.me/
- http://zetacomponents.org/ + https://github.com/zetacomponents
- http://www.pradosoft.com/ + https://github.com/pradosoft/prado (founder left, now creates yii – team still active!)
- http://www.hazaarmvc.com/
- http://auraphp.com/
- http://www.agavi.org/
- http://fatfreeframework.com/home
Obscure / Ancient / Dead
- http://www.recessframework.org/ (last updated 2010)
- http://solarphp.com/ (replaced by Aura)
- http://jelix.org/
- http://www.phpontrax.com/
- http://www.phpdevshell.org/
- http://www.openbiz.me/developer/framework.php
- http://www.phpwact.org/
- https://github.com/akelos
- http://sourceforge.net/projects/cgiapp/
- http://xyster.libreworks.com/
- https://github.com/appflower
- http://www.qcodo.com/
- http://adventure-php-framework.org/Seite/001-Startseite
- http://zikula.org/
- http://www.redsparkframework.de/ (CMS framework)
- http://www.doophp.com/
- http://seagullproject.org/
- http://nette.org/
- http://alloyframework.org/
- http://www.banshee-php.org/
- http://www.dingoframework.com/
- https://burnercms.com/
- http://phpixie.com/
- http://code.google.com/p/kata/
Sources
- http://www.phpframeworks.com/
- http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#PHP
- Google „php framework“
Performance-Optimierung am Beispiel: betamode.de
Published 2012-03-22, 20:07
Ich habe mich ein wenig mit Performance Optimierung von Webseiten beschäftigt. In den nächsten Tagen und Wochen werde ich einige Beiträge dazu veröffentlichen. Den Anfang macht diese Beschreibung des Optimierungsvorgangs von betamode.de:
Beispielseiten für Optimierung
- http://betamode.de
- http://betamode.de/2011/07/31/server-data-monitoring-graphing/
Ausgangssituation
- http://www.webpagetest.org/result/120318_NC_3MJ57/
- http://www.webpagetest.org/result/120318_GB_3MJ59/
Erste Beobachtungen und Auswertung
- urchin.js – uralter Google Analytics Code?
- Mehrere kleine GIFs, sollten sich einfach spriten lassen
- First Byte Time ist sehr hoch
- Kein Caching der statischen Ressourcen
- Kein CDN
Optimierung
Anwendbare Regeln aus High Performance Website Sites:
Rule 1 – Make Fewer HTTP Requests
Folgende Bilder können zusammengefasst werden:
- http://betamode.de/wp-content/themes/betamode/images/suche.gif
- http://betamode.de/wp-content/themes/betamode/images/clock.gif
- http://betamode.de/wp-content/themes/betamode/images/comments.gif
- http://betamode.de/wp-content/themes/betamode/images/xml.gif
Schritte:
- Bilder von <img> auf background-images umbauen
- Bilder als Sprite zusammenfassen: http://betamode.de/wp-content/themes/betamode/images/sprite.gif
- Sprite als background-image einbauen
- Da sich bg.gif nicht mitspriten lässt wird es als data-base64 direkt ins CSS eingebunden
Ergebnis
- http://www.webpagetest.org/result/120318_NM_3MJST/
- http://www.webpagetest.org/result/120318_C2_3MJSV/
Rule 3 – Add an Expires Header
Mit W3 Total Cache lässt sich sich das wunderbar erschlagen.
Ergebnis
- http://www.webpagetest.org/result/120318_0K_3MJY7/
- http://www.webpagetest.org/result/120318_4C_3MJZ0/
Rule 6 – Put Scripts at the Bottom
Das Analytics-Script ist zwar schon ganz unten, aber noch das alte synchrone. Also mal das neue besorgen und einbauen.
Ergebnis
- http://www.webpagetest.org/result/120318_B3_3MJZY/
- http://www.webpagetest.org/result/120318_TS_3MJZZ/
Rule 10 – Minify JavaScript (+ HTML + CSS)
Javascript gibt es keines, aber für Minify von HTML und CSS kann einfach W3 Total Cache konfiguriert werden, fertig.
Ergebnis
- http://www.webpagetest.org/result/120318_C4_3MK1C/
- http://www.webpagetest.org/result/120318_6G_3MK1D/
Dann zum Abschluss noch ein bisschen serverseitiges Caching um DB-Anfragen und so weiter zu minimieren mit W3 Total Cache.
End-Ergebnis
- http://www.webpagetest.org/result/120318_57_3MK1Z/
- http://www.webpagetest.org/result/120318_XM_3MK22/
Tadaa, schnell.
Google-Wunsch-Funktion: Timestamp-Umrechnung
Published 2007-03-07, 17:52
Ich gebe einen Timestamp ein, Google gibt mir ein korrektes Datum zurück.
Ich gebe Google „timestamp:“ und Datum, Google gibt mir den Timestamp zurück.
Das wäre doch mal ein nützliches Feature.
Know your enemy: XSS, SQL Injection etc.
Published 2007-02-27, 01:51
Auch wenn Betamode nun wohl absolut zum Linkblog verkommt:
http://www.honeynet.org/papers/webapp/
Automatisierte MySQL-Backups auf mehreren Servern: phpMyBackupPro
Published 2007-02-25, 16:11
http://www.phpmybackuppro.net/
wordwrap
Published 2006-12-17, 14:38
PHP-Funktion, die man kennen muss: wordwrap()
StudiVZ: Ich studiere an der Array
Published 2006-11-08, 18:20
Immer wieder lustig…
Nachtrag: Da mittlerweile von einigen Blogs auf diesen Beitrag verlinkt wird möchte ich doch gerne klarstellen, dass ich hier keineswegs nur auf StudiVZ draufhauen möchte und diesen Beitrag als Fehlerreport an die Jungs hinter StudiVZ gesendet habe. Konstruktive Kritik statt Neid-Blabla…