Blog

  1. laravel csrf_token() is empty in l5-swagger

    csrf_token() is empty in l5-swagger and couldn't do any request.

    I have tried to request it from the postman and it works. but in swagger, it didn't. I have taken a look from this link (Laravel 5 csrf_token value is Empty) but I still have no idea how to solve my problem.

    How can I get the csrf_token inside my l5-swagger view?

    Answer

     You should try to add this in /routes/web.php

    Route::group(['middleware' => 'web'], function () { Route::get('api/documentation', '\L5Swagger\Http\Controllers\SwaggerController@api')->name('l5swagger.api'); });


    Read more »
  2. In Laravel 5, How to disable VerifycsrfToken middleware for specific route?

    In Laravel 5 this has changed a bit. Now you can simply add the routes you want to exclude from csrftoken verification, in $except an array of the class 'VerifyCsrfToken' (\app\Http\Middleware\VerifyCsrfToken.php):

    class VerifyCsrfToken extends BaseVerifier { protected $except = [ // Place your URIs here ]; }

    Examples:

    1. If you are using a route group:

    Route::group(array('prefix' => 'api/v2'), function() { Route::post('users/valid','UsersController@valid'); });

    Your $except the array looks like:

    protected $except = ['api/v2/users/valid'];

    2. If you are using a simple route

    Route::post('users/valid','UsersController@valid');

    Your $except the array looks like:

    protected $except = ['users/valid'];

    3. If you want to exclude all routes under the main route (users in this case)

    Your $except the array looks like:

    protected $except = ['users/*'];

    see: http://laravel.com/docs/master/routing#csrf-excluding-uris


    Read more »
  3. Upgrading to PHP 7 on Amazon Linux EC2 Instance

    By now you may know that PHP 7 has been available for quite some time now coming with a number of improvements over version 5. It may be wise to upgrade to PHP7 when running for instance a WordPress using Amazon AWS where you are responsible for any upgrades.

    Also as of July 2016, Amazon officially added PHP7 to its repository so you can install it using yum. So first thing I did was create a backup image of my EC2 instance before I went on with the upgrade. Once I had my backups done and proceeded with the PHP 7 upgrade.

    Here are the steps I took in order to upgrade from PHP 5.x to 7.

    Login to your Linux instance and perform the regular system updates first

    $ sudo yum update
    

    Stop the running webserver

    $ sudo service httpd stop
    

    Remove any existing PHP packages

    $ sudo yum remove php*
    

    Remove old web server installs

    $ sudo yum remove httpd*
    

    Update yum package repository

    $ sudo yum clean all
    $ sudo yum upgrade -y
    

    Install Apache 2.4

    $ sudo yum install httpd24
    

    Install PHP 7 packages

    $ sudo yum install php70 php70-mysqlnd php70-imap php70-pecl-memcache php70-pecl-apcu php70-gd
    

    Install a new version of mod_ssl

    $ sudo yum install mod24_ssl
    

    I also needed to reconfigure /etc/httpd/conf/httpd.conf and /etc/httpd/conf.d/ssl.conf.

    Finally, all I needed to do is start my webserver

    $ service httpd start
    Read more »
  4. Solving out of memory errors with PHP and Composer on EC2s free tier

    For one of my recent projects, I wanted to make use of the free allowance that AWS gives for SES.

    One of the conditions of the SES allowance was that your calling app needs to be hosted on EC2.

    I’ve not used EC2 before so I figured this would be a good way to dive into it.

    Whilst I would never usually install software like a composer on a production server, this was pure to test things out.

    So after signing up for AWS and creating a local ubuntu server on an EC2 t2micro instance then cloning down the project I ran composer install to come across the following message:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    composer install
    Loading composer repositories with package information
    Updating dependencies (including require-dev)

    mmap() failed: [12] Cannot allocate memory

    mmap() failed: [12] Cannot allocate memory
    PHP Fatal error: Out of memory (allocated 822091776) (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223

    Fatal error: Out of memory (allocated 822091776) (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223

    822091776bytes is over 800mb of memory being consumed by the composer.

    Whilst php-fpm has a 128mb max memory limit per script by default,
    php-cli has a value of -1 which means use unlimited memory.

    In this instance attempting to allocate over 800mb of memory on a server with 1gb was not going to end well.

    The solution was to create a swap file on the disk.

    A swap file or partition is space on disk allocated that can be used when the physical memory allocation is exhausted. Once the allocation is exhausted, older items in memory get offloaded to the swap partition.

    The actual solution for this I found over on this GitHub issue.

    The following code will create a 1gb swap file in /var/swap.1 for our instance to use

    1
    2
    3
    sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
    sudo /sbin/mkswap /var/swap.1
    sudo /sbin/swapon /var/swap.1
    Read more »
  5. An error has happened during application run

    The topic today is one of the popular errors you will meet. As if the error message shows “An error has happened during application run. See exception log for details” in Magento 2 when you have uploaded Magento CE latest version and want to install it on your server, so what should you do? Here is the right solution for you.

    How to resolve: “An error has happened during application run. See exception log for details”

    Please open the .htaccess from the root and comment out the first line:

    SetEnv MAGE_MODE developer


    Read more »
  6. magento 2 Please re-run Magento compile command

    Depending on your configuration it may also be unecessary. If you are in default or dev mode you do not need it.

    You just need it on production mode

    From command line and from your Magento root path:

     

    php bin/magento setup:di:compile

    P.S: After installing your module make sure you ran:

    php bin/magento setup:upgrade
    Read more »
  7. steps to Uninstall Module Manually for Magento 2

    • Delete the Module folder from {folder path}\app\code
    • Remove module entry from below tables core_config_data & setup_module
    • Run command

      {magento project root path}>{php path}\php bin/magento setup:upgrade => Setup Upgrade

      {magento project root path}>{php path}\php bin/magento cache:flush => Clear Cache

    Read more »
  8. Integrity constraint violation: 1062 Duplicate entry ‘4-Images’ for key – Magento 2

    Integrity constraint violation: 1062 Duplicate entry ‘4-Images’ for key ‘EAV_ATTRIBUTE_GROUP_ATTRIBUTE_SET_ID_ATTRIBUTE_GROUP_NAME’, query was: UPDATE `eav_attribute_group` SET `attribute_group_name` = ? WHERE (`attribute_group_id`=10)

    This particular error presented itself while upgrading from Magento 2.0.2 to Magento 2.1.x and stops the upgrade process. We’ve discovered the issue is related to old data from the previous Magento 1.9.x installation. In order to over come this error, you’ll need to delete a row from the database.

    Run the following MySQL query to find and delete the offending attribute.

    1
    delete from eav_attribute_group WHERE attribute_group_name = 'Images';

    After that then you can attempt to run the upgrade command again and the issue should be resolved.

    We understand not everyone can be a MySQL / Magento 2 expert so if you’re faced with a similar issue and stuck between an upgrade feel free to contact us to assist with your problem.

     

    Read more »
  9. How to install phpunit on Ubuntu 16.04 (Xenial Xerus)

    Install phpunit

    Installing phpunit package on Ubuntu 16.04 (Xenial Xerus) is as easy as running the following command on terminal:

    sudo apt-get update
    sudo apt-get install phpunit
     
    Read more »
  10. The mbstring extension is missing.

    If you are installing new Ubuntu 16.04 LTS or upgrading/Downgrade from your older Ubuntu installation then you will get an error like “phpMyAdmin – Error – The mbstring extension is missing. Please check your PHP configuration”. This error can happen on browser for your phpmyadmin access after installation or upgrade to Ubuntu 16.04.

    just run these command

    sudo apt-get install phpmyadmin php-mbstring php-gettext

    sudo service apache2 restart

    Read more »
Page
Copyright © 2016 Samdoit Infotech. All rights reserved.