Please re-run Magento compile command message that displays whenever there’s a change in the Magento 2 source. Every time the upgrade command is completed, you’ll see this message. In this tutorial, Magesolution will talk about this command and how to properly execute compile command in Magento 2 site
What is Magento Compilation?
The Magento Compilation is a function that permits you to compile all Magento installation files (source code, including plugins) into a single folder in order to generate a single included path. This function is designed to enhance the performance of your Magento 2 website. Also, it helps to improve about 25% to 50% of your web load speed. Moreover, if the compilation is turned in your site, whenever there’s a change of source in the root folder, you have to re-run the compilation process for that change to be performed in your Magento 2 website
“Please re-run Magento compile command” message
This is a system message that displays whenever there’s a change in the Magento source. Every time the upgrade command is completed, you’ll see this message.

There are some cases where you will see this message in Magento 2 CLI
- Install a new Magento 2 instance
- Install a new Magento 2 module or theme
- Upgrade a new Magento 2 extension or theme
- Upgrade Magento 2 version
- Migrate Magento 2 website to another hosting
However, if you have already disabled compilation or are working in dev-mode in Magento 2, you can ignore this message.
How to run Magento compile command
If you have ssh access to the server where you host your site, then it ought to be easy to run the Magento Compile command right in your ssh interface. However, there’re many people who are running Magento 2 stores on shared hosting and don’t have ssh access. Thus, we will give 2 methods to run Magento 2 compile commands for those who have ssh access and those who don’t.
Method 1. Run compile command with ssh access
Connect to your Magento 2 server using ssh protocol and run the below command to start the compilation process.
php bin/magento setup:di:compile
Sample output

The compilation process will take about 8 minutes for a fresh Magento 2 website and time will increase according to the number of modules installed on your site. When the compilation process is finished, you will see the below message in the CLI interface.
C:\xampp\htdocs\magento2>php bin/magento setup:di:compile
Compilation was started.
App action list generation... 8/8 [============================] 100% 4 mins 352.0 MiB
Generated code and dependency injection configuration successfully
Make sure that you put php
before bin/magento setup:di:compile
so that you can use the command from any folder.
Method 2: Run compile command without ssh access
If you are running Magento 2 on shared hosting without ssh access, we will have to generate a PHP file to apply the command by using system()
function.
Navigate to your Magento 2 root folder and generate a PHP file and name it: compile.php.
Next step, you use a text editor and put the following code inside this PHP file
<?php
echo "<pre>";
system('php bin/magento setup:di:compile');
echo "</pre>";
After that, you need to save changes and type the URL to this file in your browser like this: localhost/compile.php
Lastly, you need to wait for the compilation process, when it’s done the webpage will print out the result like this:

How to run setup:di: compile for a specific module
Follow these steps to run setup:di: compile for a specific module.
- Go/var/www/html/yourMagento/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
- After that, you open the file and locate the below-mentioned line:
$modulePaths = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE);
- replace the below-mentioned line and add the path of the module that you want to compile as shown below:
$modulePaths = ['CompanyName_ModuleName' => '/var/www/html/yourMagento/app/code/CompanyName/ModuleName'];
Before you execute the command for a specific module, remember that the module registers with this CompanyName_ModuleName in registration.php file. Besides, it’s a temporary way for DI to compile for a specific module. So, remember to remove the di created module folder and refresh the cache.
Conclusion
That’s all about the Please re-run Magento compile command message and how to properly execute compile command for your Magento 2 website. We hope you find it helpful and in case you face any difficulties, Contact us and we will definitely support you! Magesolution is one of the leading Magento and web development services in the world. With experienced Magento developers, we commit to providing the best products and services to help your business achieve success.