Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shahzadbuckstec's avatar

php artisan not working in Centos 7

This command is working in localhost(Windos 10): php artisan import:products then I uploaded to live centos server and go into my project root folder(client) and execute this command it works and after some time it shows me error memory limit exceeded then I edit php ini file from cPanel and increase memory limit to 128M after that I run this command again and it display nothing even I can't clear cache, config

php artisan cache:clear
php artisan config:clear
php artisan config:cache

After some searching, I run the command with sudo and it shows 500 Internal server error but no file pointed.

here is some output of my cli:

[root@cpanel client]# php artisan import:products
[root@cpanel client]# sudo php artisan import:products
Status: 500 Internal Server Error
Content-type: text/html; charset=UTF-8

[root@cpanel client]# php artisan cache:clear
[root@cpanel client]# php artisan config:clear
[root@cpanel client]# php artisan config:cache

[root@cpanel client]#

Please help! I have no idea what's going on, you can see all the above commands are not working.

Server log error


[30-Aug-2018 08:45:01 UTC] PHP Fatal error:  Allowed memory size of 2097152 bytes exhausted (tried to allocate 36864 bytes) in /home/exmpale/public_html/client/vendor/composer/autoload_static.php on line 4225

Here is my server detail

CentOS Linux release 7.5.1804 (Core)

PHP 7.2.9 

laravel/framework v5.6.35

Here is code:

<?php

namespace App\Console\CommandsImportData;

use Illuminate\Console\Command;
use DB;
use Mail;
use Storage;


/*
* How to run this command?
* Open a console window in project root folder
* php artisan import:products
*/

class ImportProducts extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'import:products';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Import bigbuy products';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {



        $totalInsert = $totalUpdated = 0;

        $languagesArr = array(
            'en',
            'da',
            'fr',
            'de',
            'it',
            'nl',
            'no',
            'pl',
            'ru',
            'es',
            'sv',
        );

        $countryIdsArr = array(
            'en'=>229,
            'da'=>56,
            'fr'=>72,
            'de'=>80,
            'it'=>106,
            'nl'=>155,
            'no'=>165,
            'pl'=>176,
            'ru'=>182,
            'es'=>202,
            'sv'=>210,
            
        );

        foreach($languagesArr as $lang){

            if($lang=='fr'){
                $filePathArr[$lang] = [
                    "csv-gnral-produits-2399-$lang.csv",
                    "csv-gnral-produits-2403-$lang.csv",
                    "csv-gnral-produits-2491-$lang.csv",
                    "csv-gnral-produits-2501-$lang.csv",
                    "csv-gnral-produits-2507-$lang.csv",
                    "csv-gnral-produits-2570-$lang.csv",
                    "csv-gnral-produits-2571-$lang.csv",
                    "csv-gnral-produits-2609-$lang.csv",
                    "csv-gnral-produits-2662-$lang.csv",
                    "csv-gnral-produits-2672-$lang.csv",
                    "csv-gnral-produits-2678-$lang.csv",
                    "csv-gnral-produits-3046-$lang.csv",
                ];
            }
            elseif($lang=='es'){
                $filePathArr[$lang] = [
                    "csv-de-productos-general-2399-$lang.csv",
                    "csv-de-productos-general-2403-$lang.csv",
                    "csv-de-productos-general-2491-$lang.csv",
                    "csv-de-productos-general-2501-$lang.csv",
                    "csv-de-productos-general-2507-$lang.csv",
                    "csv-de-productos-general-2570-$lang.csv",
                    "csv-de-productos-general-2571-$lang.csv",
                    "csv-de-productos-general-2609-$lang.csv",
                    "csv-de-productos-general-2662-$lang.csv",
                    "csv-de-productos-general-2672-$lang.csv",
                    "csv-de-productos-general-2678-$lang.csv",
                    "csv-de-productos-general-3046-$lang.csv",
                ];
            }
            else{
                $filePathArr[$lang] = [
                    "general-products-csv-2399-$lang.csv",
                    "general-products-csv-2403-$lang.csv",
                    "general-products-csv-2491-$lang.csv",
                    "general-products-csv-2501-$lang.csv",
                    "general-products-csv-2507-$lang.csv",
                    "general-products-csv-2570-$lang.csv",
                    "general-products-csv-2571-$lang.csv",
                    "general-products-csv-2609-$lang.csv",
                    "general-products-csv-2662-$lang.csv",
                    "general-products-csv-2672-$lang.csv",
                    "general-products-csv-2678-$lang.csv",
                    "general-products-csv-3046-$lang.csv",
                ];
            }

        }
        
        #Import products
        foreach($filePathArr as $lang=>$filesArr){
            
            foreach($filesArr as $key=>$fileName){

                echo "Importing file==> $fileName \n";

                $filePath = storage_path('app') . "/public/bigbuy/$fileName";

                if (!file_exists($filePath) || !is_readable($filePath)){
                    echo $fileName."\n";
                    die("File not exists or can not readable...");
                    //continue;
                }
                

                $delimiter = ';';
                $header = null;
                $data = array();

                if (($handle = fopen($filePath, 'r')) !== false){
                
                    while (($row = fgetcsv($handle, 100000, $delimiter)) !== false){
                 
                        #First line consider head and save into header array
                        if (!$header){
                            #This will clean each string from hidden characters.
                            $row = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $row);
                             $header = $row;
                        }else{
                            $data[] = array_combine($header, $row); 
                        }
                    }

                }

                //$jsonEncodedData = json_encode($data);
                //echo $jsonEncodedData;exit;
                
                foreach($data as $key=>$row){
                    //echo "inserting data";
                    try{
                        $slug = str_slug($row['NAME']);
                        if(empty($slug)){
                            //echo "slug is empty";
                            continue;
                        }
                        #Insert in shop products for en lang
                        if($lang == 'en'){  
                            //echo "Langue is en";
                                $exist = DB::table('shop_products')
                                              ->where('slug',$slug)->count();
                                if(!$exist){
                                    $catsArr = explode(',',$row['CATEGORY']);
                                    $parentCatId = $catsArr[0];
                                try{
                                    //echo "inserting query";
                                    DB::table('shop_products')->insert([
                                  
                                        'title'=>$row['NAME'],
                                        'slug'=>$slug,
                                        'description'=>$row['DESCRIPTION'],
                                        'short_description'=>substr(strip_tags(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $row['DESCRIPTION'])),0,50),
                                        'brand_id'=>$row['BRAND'],
                                        'price'=>$row['PRICE'],

                                    ]);
                                    $totalInsert++;
                                }catch(\Throwable | \Error | \Exception $e){
                                    die($e->getMessage());
                                }
                                    
                                }else{
                                    #update products
                                    
                                        DB::table('shop_products')->where('slug',$slug)->update([
                                  
                                        'description'=>$row['DESCRIPTION'],
                                        'price'=>$row['PRICE'],
                                    ]);
                                        $totalUpdated++;
                                }
                        }
                        else{
                            #Insert into translation
                            $countryId = $countryIdsArr[$lang];
                                $exist = DB::table('shop_products_translation')
                                    ->where('slug',$slug)
                                    ->where('country_id',$countryId)
                                    ->count();
                                if(!$exist){
                                        $productId = DB::table('shop_products')->where('provider_product_id',$row['ID'])->value('id');
                                    
                                    if($productId){
                                            DB::table('shop_products_translation')->insert([
                                        'product_id'=>$productId,
                                        'country_id'=>$countryId,
                                        'title'=>$row['NAME'],
                                        'slug'=>$slug,
                                        'description'=>$row['DESCRIPTION'],
                                        'short_description'=>substr(strip_tags( preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $row['DESCRIPTION'])),0,50)

                                            ]);
                                            $totalInsert++;
                                        }
                                }else{
                                    #update products
                                    
                                        DB::table('shop_products_translation')->where('slug',$slug)->update([
                                        'description'=>$row['DESCRIPTION'],
                                        ]);
                                        $totalUpdated++;
                                    
                                }

                        }
                    }catch(\Throwable | \Error | \Exception $e){
                        die($e->getMessage());
                    }

                }#End of data for loop

            }#End of filesArr

        }#End of productFilePathArr

        echo("Done... $totalInsert records inserted...$totalUpdated records updated");

        $this->info("ImportBigbuyProducts Cummand Run successfully!\n");
    }
    
}


0 likes
10 replies
aurawindsurfing's avatar

Maybe that is the error:

Content-type: text/html; charset=UTF-8

Do you use the same charset on your remote machine as on local? Should not matter but you never know.

Sirik's avatar

Would you post the code of 'import:products' running as root is not needed

shahzadbuckstec's avatar

I have updated my question with code. Also created a fresh test project and uploaded to the server and then run this command but it shows nothing.

[root@cpanel public_html]# cd testapi/
[root@cpanel testapi]# ls
app            composer.lock  phpunit.xml  routes      vendor
artisan        config         public       server.php  webpack.mix.js
bootstrap      database       readme.md    storage
composer.json  package.json   resources    tests
[root@cpanel testapi]# php artisan list
[root@cpanel testapi]#

PHP simple command output

[root@cpanel testapi]# php -v
ea-php-cli Copyright 2017 cPanel, Inc.
PHP 7.2.9 (cli) (built: Aug 28 2018 14:50:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
[root@cpanel testapi]#
shahzadbuckstec's avatar

I have installed and Configure CSF (Config Server Firewall) on CentOS 7, do you think that is creating the problem?

Even my cron job was working before but now that cron job also stopped working. /usr/local/bin/php /home/exmpale/public_html/client/artisan schedule:run

In serve error log i can see this error:

[30-Aug-2018 08:45:01 UTC] PHP Fatal error:  Allowed memory size of 2097152 bytes exhausted (tried to allocate 36864 bytes) in /home/exmpale/public_html/client/vendor/composer/autoload_static.php on line 4225

Guys any idea?

shahzadbuckstec's avatar

[30-Aug-2018 10:03:01 UTC] PHP Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 36864 bytes) in /home/example/public_html/client/vendor/composer/autoload_static.php on line 4225

The issue is at line number 4225

client/vendor/composer/autoload_static.php on line 4225

ohffs's avatar

Allowed memory size of 2097152 bytes is only 2mb of memory. Are you sure you are editing the right config file for your php (php --ini will show you the paths)? Or possibly your hosting company/cpanel is doing something weird... :-/

1 like
shahzadbuckstec's avatar

Thank you, everyone , It was "M" not "MB", I changed memory_limit from 128MB to 512M and now it is working.

Please or to participate in this conversation.