Posts tagged: php

Using Font Awesome with Laravel

2017-04-09 12:00:04 ][ Tags: hacking php laravel

For some reason there is a whole thread on this seemingly simple tasks. In a bootstrapped Laravel 5.4 instance the following worked for me.

Install Font Awesome with NPM

npm install font-awesome

Import font-awesome in your app.scss file

// resources/assets/sass/app.scss // Font Awesome @import "node_modules/font-awesome/scss/font-awesome";

Copy the fonts to public directory

Adding the following to your elixir config in the gulpfile

.copy('node_modules/font-awesome/fonts', 'public/fonts')

My complete gulpfile looks like this:

const elixir = require('laravel-elixir'); require('laravel-elixir-vue-2'); /* |-------------------------------------------------------------------------- | Elixir Asset Management |-------------------------------------------------------------------------- | | Elixir provides a clean, fluent API for defining some basic Gulp tasks | for your Laravel application. By default, we are compiling the Sass | file for your application as well as publishing vendor resources. | */ elixir((mix) => { mix.sass('app.scss') .copy('node_modules/font-awesome/fonts', 'public/fonts') .webpack('app.js'); });

Run Gulp

If you run gulp you should be able to now start using font-awesome everywhere in your app.

Dockerized Laravel and MySQL for local development

2017-04-08 17:49:15 ][ Tags: hacking php laravel docker

Docker is awesome. Its also quite useful for local development. The following Dockerfile and docker-compose.yml will be helpful if you want to do laravel development inside of docker. I am using Ubuntu as a base, but you can probably use the official PHP image as well. Dockerfile

FROM ubuntu:16.04

RUN apt update
RUN apt install -y php7.0 php7.0-zip php7.0-mbstring phpunit curl php7.0-mysql

RUN curl -sS https://getcomposer.org/installer | php 
RUN mv composer.phar /usr/local/bin/composer

RUN composer global require "laravel/installer"

RUN export PATH=$HOME/.config/composer/vendor/bin:$PATH


version: '2'
    build: .
      - "8000:8000"
      - .:/code
    env_file: .env
    working_dir: /code
    command: bash -c 'php artisan migrate && php artisan serve --host'
      - db
    image: "mysql:5.7"
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_DATABASE=$your_db
      - MYSQL_USER=$your_db_user
      - MYSQL_PASSWORD=$your_db_password
      - ./data/:/var/lib/mysql
      - "3306:3306"

.env file Your .env file is what Laravel uses when it starts up set up various things. The only real thing to change is your DB connection info. A full sample is shown below:








  1. In order to do stuff with the database you should add the following record to your local /etc/hosts file

    # /etc/hosts db
  2. You should still install npm and run npm install from your local machine so that you can do frontend stuff.

  3. Since we define - .:/code as a volume, this means that all of your local changes are immediately visible in the dockerized app.
  4. If you need to access the running app or db container you can do so with docker-compose run app bash or docker-compose run db bash

Getting Started with Laravel on Ubuntu

2016-11-30 09:00:56 ][ Tags: hacking php laravel

I've really been digging Laravel lately. Especially due to the wonderful documentation and amazing resources provided by Laracasts. Below are some notes on getting going on a local Ubuntu install. I am running Ubuntu 16.10 and these notes assume a fresh install.

Install PHP 7.0 and additional dependencies

sudo apt install php7.0 php7.0-zip php7.0-mbstring phpunit

Install Composer (Globally)

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Install the Laravel CLI (Globally)

composer global require "laravel/installer"

Add globally installed composer commands to the PATH

Add the following to the end of your ~/.bashrc file

# Add Composer to the PATH
export PATH=$HOME/.config/composer/vendor/bin:$PATH

You can either source the ~/.bashrc file or open a new terminal window.

Verify everything works

You can do this by running laravel new test_project. Then go to the directory where the new test_project is created with cd test_project. Once you are in the new project directory install all local dependencies with composer install and then run it with php artisan serve. I ran into an issue right away that had to do with the APP_KEY. The error manifested itself as:

The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.

A great explanation is shown here but the steps to get a fully functional base install going are:

# Copy the .env.example file to .env
cp .env.example .env

# Generate App Key
php artisan key:generate

Now if you run php artisan serve you will see a fully running Laravel app. Happy Hacking!

Laravel Homestead on Ubuntu 16.04

2016-11-15 18:23:37 ][ Tags: hacking php laravel

Yesterday I wrote about my first steps with Laravel and Homestead and complained about how I had some trouble getting started. It turns out this has nothing to do with Laravel and instead has to do with a Vagrant bug in the version that is shipped by default with Ubuntu 16.04 LTS.

vagrant up throws The following SSH command responded with a non-zero exit status error for Laravel Homestead

Source: 16.04 - vagrant up throws The following SSH command responded with a non-zero exit status error for Laravel Homestead - Ask Ubuntu

Installing Vagrant manually did the trick and everything worked like a charm. I am so impressed so far, the bootstrapped Laravel project is elegant, well structured, and beautiful by default. I am almost afraid to write any code because I will probably ruin it.

First Steps with Laravel and Homestead

2016-11-14 21:50:20 ][ Tags: hacking php laravel

I'm checking out Laravel for the first time. I think they have a very nice web site, but slightly confusing documentation. First I tried to get composer working but the whole experience felt weird. Once I got it sorted out, I had some other issues with my local environment so then I went ahead and started to read about Homestead.

Laravel strives to make the entire PHP development experience delightful, including your local development environment. Vagrant provides a simple, elegant way to manage and provision Virtual Machines.

Source: Laravel Homestead - Laravel - The PHP Framework For Web Artisans

This was a bit more promising, since Vagrant makes everything dead simple. I was a bit surprised that the docs suggested creating a single Homestead box and sharing it across all of your Laravel projects since this is a practice that I have not seen before.

I went ahead and did what I usually do and create a Vagrant box for my specific project. It's been many years since I have written any "real" PHP, looking forward to seeing what Laravel has to offer.