Tag: laravel

  • Laravel supported ciphers are AES-128-CBC and AES-256-CBC

    Laravel supported ciphers are AES-128-CBC and AES-256-CBC

    On a Laravel application, I get the following error message

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

    To fix the error, run the command

    php artisan key:generate

    This will generate a new key and add to the .env file.

    Back to Laravel

  • How to clear Laravel cache

    To clear the Laravel cache, run the command

    php artisan cache:clear

    You can also delete compiled files from

    rm -rf bootstrap/cache/*

    Back to Laravel

  • How to find Laravel Framework Version

    Laravel is a popular PHP framework. In this post, I will show how to check laravel version.

    To find the Laravel Framework version, run

    php artisan --version
    how to check laravel version

    Another way to find Laravel version is to check the file composer.lock present in the Laravel web root directory.

    cat composer.lock

    You will see something like the following

                "name": "laravel/framework",
                "version": "v6.1.0",
                "source": {
                    "type": "git",
                    "url": "https://github.com/laravel/framework.git",
                    "reference": "a365bea7ff0dea9a50f5904be9e41656def9af4b"
                },

    In this case, we are using Laravel version 6.1.0

    See Laravel

  • Nginx Config for Laravel Application in sub folder

    Nginx Config for Laravel Application in sub folder

    To run Laravel Application on a subfolder of a website, use the following configuration. If you run the Laravel application as the main site, see Nginx Config for Laravel Application

    # subFolderApp1
    
    location /subFolderApp1 {  
        alias /home/yorudomain.com/html/subFolderApp1/public;  
        try_files $uri $uri/ @subFolderApp1;
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_pass unix:/run/php/php7.2-fpm-torrentp.sock;
        }
    }  
    
    location @subFolderApp1 {
        rewrite /subFolderApp1/(.*)$ /subFolderApp1/index.php?/$1 last;
    }
    
    # end subFolderApp1

    Here you place the Laravel application in a subdirectory “subFolderApp1”.

    Example

    server {
        server_name serverok.in www.serverok.in;
        root /home/serverok.in/html/;
        index index.php index.html index.htm;
        client_max_body_size 1000M;
        proxy_read_timeout 600s;
        fastcgi_read_timeout 600s;
        fastcgi_send_timeout 600s;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
    
        # service
    
        location /service {  
            alias /home/serverok.in/html/service/public;  
            try_files $uri $uri/ @nested1;
            location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_param SCRIPT_FILENAME $request_filename;
                fastcgi_pass unix:/run/php/php7.2-fpm-torrentp.sock;
            }
        }  
    
        location @nested1 {
            rewrite /service/(.*)$ /service/index.php?/$1 last;
        }
    
        # end service
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_intercept_errors on;
            fastcgi_buffers 16 16k;
            fastcgi_buffer_size 32k;
            fastcgi_pass unix:/run/php/php7.2-fpm-torrentp.sock;
        }
    
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/serverok.in/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/serverok.in/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }
    
    server {
        if ($host = www.serverok.in) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    
        if ($host = serverok.in) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    
        listen 80;
        server_name serverok.in www.serverok.in;
        return 404; # managed by Certbot
    }

    Back to Nginx

  • Laravel

    Create a project using the latest Laravel

    composer create-project laravel/laravel blog

    Create a project using a specific version of Laravel.

    composer create-project laravel/laravel=5.1.33 --prefer-dist blog

    You can see available Laravel versions on the site

    https://packagist.org/packages/laravel/laravel

    Clear Laravel application cache

    rm -rf bootstrap/cache/*

    or

    php artisan cache:clear

    Back to PHP

  • Laravel Database Migration Error Key too long

    When doing a database migration on Laravel, I get the following error

    $ php artisan migrate
    
      [Illuminate\Database\QueryException]                                                                                                                                                 
      SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))  
    
      [PDOException]                                                                                                   
      SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes  
    $ 

    This is because MariaDB uses a different UTF8 format.

    To fix, edit file

    vi ./app/Providers/AppServiceProvider.php

    Inside, find

        public function boot()
        {
            //
        }

    Replace with

        public function boot()
        {
            Schema::defaultStringLength(191);
        }

    You will also need to add

    use Illuminate\Support\Facades\Schema;

    here is what my file looks like after editing.

    $ cat ./app/Providers/AppServiceProvider.php
    <?php
    
    namespace App\Providers;
    
    use Illuminate\Support\Facades\Schema;
    use Illuminate\Support\ServiceProvider;
    
    class AppServiceProvider extends ServiceProvider
    {
        /**
         * Bootstrap any application services.
         *
         * @return void
         */
        public function boot()
        {
            Schema::defaultStringLength(191);
        }
    
        /**
         * Register any application services.
         *
         * @return void
         */
        public function register()
        {
            //
        }
    }
    $ 

    Back to Laravel

  • Syntax error or access violation: 1071 Specified key was too long

    When running database migration in a new larvel project, i get following error

    boby@hon-pc-01:~/www/proxy (master)$ php artisan migrate

    In Connection.php line 664:

    SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))

    In Connection.php line 458:

    SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

    boby@hon-pc-01:~/www/proxy (master)$

    This is due to recent change in Lavral, that changed default charset to utf8mb4.

    To fix this error, open file

    vi app/Providers/AppServiceProvider.php
    

    Find

    use Illuminate\Support\ServiceProvider;
    

    Add below

    use Illuminate\Support\Facades\Schema;
    

    Find

        public function boot()
        {
            //
        }
    

    Replace with

        public function boot()
        {
            Schema::defaultStringlength(191);
        }