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:

  1. Switch folder to /var/www/virtual/<username>.
  2. composer global require "laravel/installer" to install the Laravel Installer.
  3. Create a new Laravel project: laravel new <projectname>.
  4. Delete /var/www/virtual/<username>/html (make sure it is empty, or just rename it maybe) and replace it with a symlink from html to <projectname>/public.
  5. 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:

  1. Get your generated MySQL password from ~/.my.cnf.
  2. 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.
  3. 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!)

  4. 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:

  1. use $collection->filter() and then count the result
  2. hack $collection->contains() +$collection->find() to accept a field name as a parameter
  3. 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.

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

Obscure / Ancient / Dead

Sources

 

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

Ausgangssituation

Erste Beobachtungen und Auswertung

Optimierung

Anwendbare Regeln aus High Performance Website Sites:

Rule 1 – Make Fewer HTTP Requests

Folgende Bilder können zusammengefasst werden:

Schritte:

Ergebnis

Rule 3 – Add an Expires Header

Mit W3 Total Cache lässt sich sich das wunderbar erschlagen.

Ergebnis

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

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

Dann zum Abschluss noch ein bisschen serverseitiges Caching um DB-Anfragen und so weiter zu minimieren mit W3 Total Cache.

End-Ergebnis

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

Hochschule: Array

Immer wieder lustig…

(Array)

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…

22 queries. 0,348 seconds.