• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

laravel

Laravel 5.4 Install

March 16, 2017

This is the installation of Laravel 5.4 on an Ubuntu Server 16.04 LTS. Laravel requires that you run Apache, MySQL and PHP. In this installation, I’m using the following versions: Apache 2.4.18, MySQL 5.7.17 and PHP 7.0.15. The installation of Laravel has changed over the years. I wished the installation was simpler. You can try Forge, but it’s not free. It also requires that you have an account at Linode, Digital Ocean or AWS. Forge costs $15 per month and Forge Plus is $30 per month. If you don’t want to pay, I’m afraid you are going to have to install Laravel yourself. Laravel installation may vary based on the distro you’re using. These instructions are for the Ubuntu Server 16.04 LTS.

Run Update

sudo apt-get update
sudo apt-get upgrade

sudo apt-get update sudo apt-get upgrade

Install Apache

sudo apt-get install apache2
sudo a2enmod rewrite
sudo service apache2 restart

sudo apt-get install apache2 sudo a2enmod rewrite sudo service apache2 restart

Install MySQL

sudo apt-get install mysql-server
sudo mysql_secure_installation

sudo apt-get install mysql-server sudo mysql_secure_installation

Install PHP

sudo apt-get install php libapache2-mod-php php-mbstring php-zip php-xml php-mysql

sudo apt-get install php libapache2-mod-php php-mbstring php-zip php-xml php-mysql

Install Composer

sudo curl -sS https://getcomposer.org/installer | sudo php — —install-dir=/usr/local/bin —filename=composer
# you may have to move composer manually if it doesn't work
sudo mv composer.phar /usr/local/bin/composer
# check if composer is accessible globally
composer -V

sudo curl -sS https://getcomposer.org/installer | sudo php — —install-dir=/usr/local/bin —filename=composer # you may have to move composer manually if it doesn't work sudo mv composer.phar /usr/local/bin/composer # check if composer is accessible globally composer -V

Install Laravel Installer

composer global require "laravel/installer"
# Using alias instead of $PATH
echo 'alias laravel="~/.composer/vendor/bin/laravel"' >> ~/.bashrc
source ~/.bashrc
# add source ~/.bashrc to .profile to load automatically
echo 'source ~/.bashrc' >> ~/.profile
# restart apache
sudo service apache2 restart
# check if laravel is accessible globally
laravel

composer global require "laravel/installer" # Using alias instead of $PATH echo 'alias laravel="~/.composer/vendor/bin/laravel"' >> ~/.bashrc source ~/.bashrc # add source ~/.bashrc to .profile to load automatically echo 'source ~/.bashrc' >> ~/.profile # restart apache sudo service apache2 restart # check if laravel is accessible globally laravel

Install New Laravel Project

# set permissions
cd /var/www/
sudo chown -R ubuntu:ubuntu /var/www/html
sudo chmod -R 755 /var/www/html
# install new project
cd /var/www/html
laravel new project
# give apache permissions 
sudo chgrp -R www-data /var/www/html/project/storage
sudo chgrp -R www-data /var/www/html/project/bootstrap/cache

# set permissions cd /var/www/ sudo chown -R ubuntu:ubuntu /var/www/html sudo chmod -R 755 /var/www/html # install new project cd /var/www/html laravel new project # give apache permissions sudo chgrp -R www-data /var/www/html/project/storage sudo chgrp -R www-data /var/www/html/project/bootstrap/cache

Configure Apache

cd /etc/apache2/sites-available
sudo cp 000-default.conf project.conf
sudo nano project.conf
#
<VirtualHost *:80>
  ServerName local.project.com
  ServerAdmin admin@project.com
  DocumentRoot /var/www/html/project/public
  <Directory "/var/www/html/project">
    AllowOverride All
  </Directory>
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
#
sudo a2ensite project.conf
sudo a2dissite 000-default.conf
sudo service apache2 restart

cd /etc/apache2/sites-available sudo cp 000-default.conf project.conf sudo nano project.conf # <VirtualHost *:80> ServerName local.project.com ServerAdmin admin@project.com DocumentRoot /var/www/html/project/public <Directory "/var/www/html/project"> AllowOverride All </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> # sudo a2ensite project.conf sudo a2dissite 000-default.conf sudo service apache2 restart

Finally, you can now access Laravel from the browser from the server IP address or domain.

Filed Under: Linux, PHP Tagged With: 5.4, install, laravel

Laravel Forge Edit .env

July 2, 2015

Laravel Forge was recently upgraded with several new features. You can now edit your .env file directly from within Forge. It’s easier and faster than adding each environmental variable. In addition, you can also create and manage Nginx load balancing servers to balance your application load. With Forge, you can now deploy a new server in just minutes from any of the three cloud hosting service providers: Linode, Digital Ocean and now Amazon Web Services.

Filed Under: Linux, PHP Tagged With: aws, digital ocean, forge, laravel, linode, nginx

Migrations in Laravel

June 23, 2015

Migrations in Laravel is like having version control of your database. It gives you the ability to create, modify and share a schema, as well as drop tables. Since it has version control, you can migrate and rollback your database changes with just a couple of CLI commands. Here’s a couple of examples.

To migrate:

$ php artisan migrate

$ php artisan migrate

To rollback:

$ php artisan migrate:rollback

$ php artisan migrate:rollback

In addition, you can also create a new migration table.

$ php artisan make:migration create_users_table --create="users"

$ php artisan make:migration create_users_table --create="users"

It will create a file similar to this:

app/database/migrations/2015_01_01_213247_create_articles_table.php

which you can modify and add fields.

Filed Under: PHP Tagged With: laravel, migrations

PSR-2 Coding Style Guide

June 15, 2015

Laravel recently started using the PSR-2 style guide. PSR-2 is a coding style agreed upon by many PHP framework developers. It’s an extension of the original PSR-1, which basically has 3 main conventions.

  1. Classes are upper Camel case.
  2. Methods are lower Camel case.
  3. Constants are written in caps like VERSION_NUMBER.

PSR-2 expands this by using these standards

  1. Indents are 4 spaces instead of tabs.
  2. Keep line lengths at 80 characters. Soft limit of 120 characters.
  3. Use one blank line after a namespace declaration. Use a blank line after a group of declarations.
  4. Opening braces for classes MUST go on the next line. Closing brace must be on its own line.
  5. Opening braces for methods must go on the next line, and a separate line for the closing brace.
  6. Closures must have a space after the function keyword.
  7. Never use the var keyword, this is used with  JavaScript and would cause some confusion.
  8. Control structures, like IF, WHICH, FOR, and FOREACH must have one space before the condition parenthesis.
  9. The case keywords should be indented from the switch keyword.
  10. Keywords, like true, false, and null show be in lower case.

See examples.

Filed Under: PHP Tagged With: laravel, psr-2

Laravel 5.1 with Forge

June 14, 2015

Laravel 5.1 was released in June 9, 2015. So, I updated my development environment with version 5.1 and updated it to GitHub. From there, I spun a server via Forge at Digital Ocean. Then, I deployed my development repository via GitHub.

However, I faced two issues:

  1. I was getting an error saying that there is not enough memory. The simple fix is to do a composer update in your dev environment and then upload your changes to GitHub. If you have automatic deploy turned on, then the changes will be updated on the server.
  2. The other error was a missing app key. You can fix this by simply running artisan key:generate on the server. You must have a .env file on the Laravel directory. I believe it’s under /home/forge/default. You can create one or copy the .env.example.

Hopefully, I save you some time with troubleshooting if you run into these issues.

Filed Under: PHP Tagged With: app key, artisan, forge, laravel

Generate a Controller in Laravel

June 3, 2015

Laravel comes with several generators by way of Artisan CLI or Command Line Interface. To generate a controller, you simply run the following command from the Terminal. This is assuming you’re in the Laravel project folder.

// generate a standard Controller
$ php artisan make:controller HomeController
 
// generate a plain Controller with no methods
$ php artisan make:controller HomeController --plain

// generate a standard Controller $ php artisan make:controller HomeController // generate a plain Controller with no methods $ php artisan make:controller HomeController --plain

The first example is the standard way of generating a controller with resourceful routing in mind.

The second example is plain way of generating a controller. It does not contain any method.

Filed Under: PHP Tagged With: artisan, cli, controller, generate, laravel

Laravel Eloquent ORM

June 3, 2015

Eloquent ORM is a simple and yet powerful Active Record implementation included in Laravel, a PHP framework. This video at Laracasts is a great introduction to Eloquent. However, this article is everything you ever needed to know about Eloquent. If you’re new to Laravel, read the article. Get to know how to use Eloquent effectively.

Filed Under: PHP Tagged With: eloquent, laravel

Laracasts Black Friday Sale

November 27, 2014

If you’re a PHP developer, Laravel is all the rage. If you’re new to Laravel and you want to learn how to code, I recommend that you check out Laracasts, a video tutorial website about Laravel. You’ll find a number of free lessons, as well as some paid content.

Since it’s Thanksgiving Day, Laracasts currently has a fire sale. Well, a Black Friday sale to be exact. Laracasts is offering 40% off any type of subscription. You can apply it to a yearly subscription. What a bargain!

Better act soon. The offer will expire November 28 at 11:59pm EST.

Laracasts Black Friday Sale – 40% off any subscription

Filed Under: PHP Tagged With: laracasts, laravel

  • Go to page 1
  • Go to page 2
  • Go to Next Page »
  • Home
  • About
  • Archives

Copyright © 2023