19. Install Magento 2 on Localhost Like XAMPP
coming soon
This step-by-step tutorial will help you install Magento quickly and easily on localhost.
To get started, make sure that you have all the required components downloaded and set up: XAMPP (PHP 7.3 or 7.4.), composer, elasticsearch, Magento installation( 2.4.1 )
*review Magento 2.x System Requirements before you proceed with the installation
Once you completed XAMP and Composer installation, please follow the below steps:
Start Apache and MySQL from XAMPP Control Panel.
Navigate to \htdocs folder inside the XAMPP installation directory.
Create a new folder for elasticsearch under the \htdocs and unzip the downloaded Elasticsearch zip file inside. In order to start the elasticsearch cluster navigate to /bin folder, and double click on elasticsearch.bat
Make sure that the elasticsearch is setup correctly in browser
Now open the localhost/phpmyadmin in the browser and create a new database - magento
Create a new folder magento under the \htdocs directory and extract the installation files there
Now, go to your \magento directory and find there the G2d.php under the vendor\magento\framework\Image\Adapter. Open the file and find there the validateURLScheme and replace the method with the following code
private function validateURLScheme(string $filename) : bool
{
$allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
$url = parse_url($filename);
if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename))
{
return false;
}
return true;
}
find the Validator.php file at vendor\magento\framework\View\Element\Template\File
find the 138 line and insert the following code
$realPath = str_replace('\\', '/',$this->fileDriver->getRealPath($path));
open the PluginListGenerator.php file at vendor\magento\framework\Interception and replace the 158 line with the following code:
$cacheId = implode(‘-’, $this->scopePriorityScheme) . “-” . $this->cacheId;
Now go to your XAMPP installation directory, open the php.ini under the /xampp/php to enable the extensions (simply remove the ';')
intl
soap
sockets
xsl
After that, restart XAMP.
go to your /magento directory, open cmd, and run the following commands
php bin/magento setup:install --base-url=”http://localhost/magento" --db-host=”localhost” --db-name=”magento" --db-user=”root” --db-password=”” --admin-firstname=”admin” --admin-lastname=”admin” --admin-email=”user@example.com” --admin-user=”admin” --admin-password=”adminpass" --use-rewrites=”1" --backend-frontname=”admin”
php bin/magento setup:di:compile
php bin/magento indexer:reindex
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy –f
php bin/magento deploy:mode:set developer
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento module:disable Magento_Csp
php bin/magento module:disable Magento_TwoFactorAuth
Now return to localhost/phpmyadmin and select the magento database and run the following query under the SQL Query tab
INSERT INTO `core_config_data`(`path`, `value`) VALUES (‘dev/static/sign’, 0) ON DUPLICATE KEY UPDATE `value`=0
Now Magento 2.4 is successfully installed on your localhost. You can open your admin - go to localhost/magento/admin and use the defined access details. In our case, it is admin and adminpass.
Check the detailed Magento installation instructions here