I assume you have installed Ubuntu 24.04 LTS OS on your computer.
I installed and tested this repository for the Magento 2.4.7-p1 version.
I am a Magento 2 developer with 10+ years of experience in Magento 2, PHP, JavaScript, CSS, and MySQL. Please feel free to contact me, if you need Magento 2 development help.
- Email - [email protected]
- Skype - live:pandurang.babar
- First, we must install docker and docker-compose on your Ubuntu machine. If docker and docker-compose are not installed on your device, please use the steps below to install them.
- Update the apt package index and install packages to allow apt to use a repository over HTTPS
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
- Add Docker’s official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
- Use the following command to set the repository.
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$UBUNTU_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- Update the apt package index
sudo apt-get update
- Install docker-engine
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- Verify that the Docker Engine installation
sudo docker run hello-world
- For more information on how to install the Docker engine on Ubuntu use this link.
https://docs.docker.com/engine/install/ubuntu/
https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository
- Take a clone of the Magento 2 Docker repository from
https://github.com/pandurangbabar/magento2-docker
Use the below command to take a clone.
git clone https://github.com/pandurangbabar/magento2-docker.git
Important
Check the permission of folder “magento2-docker”. We need read-write permission for the folders dbdata and src.
- You can use the below commands to set permissions for the folder.
sudo chmod -R 777 magento2-docker
sudo chown -R $USER:$USER magento2-docker
- If you have installed apache2 and MySQL on your system, then we need to stop both services. We need to stop these services because there will be a port conflict when we run these services using a docker container. Please use the below commands to stop the apach2 and mysql service.
sudo service mysql stop
sudo service apache2 stop
sudo service nginx stop
- Make sure the docker service is started using the command.
sudo service docker status
If it is not started start the service using the command.
sudo service docker start
- Go to the repository magento2-docker and execute the below command
cd magento2-docker
sudo docker compose up --build -d
We can use
sudo docker compose down
Stops running containers without removing them. They can be started again with
sudo docker compose start
sudo docker compose down
Stop and remove all containers.
- We can make sure all the containers are running fine using the command
sudo docker ps
The Apache web server is running at http://localhost/
PHPMyAdmin is running at http://localhost:8080/
Opensearch is running at http://localhost:9200/
Note
If the opensearch search is not working, please check and set permissions using the below commands. You can use the below commands to set permissions for the folder.
sudo chmod -R 777 magento2-docker
sudo chown -R $USER:$USER magento2-docker
Now our Magento 2 development environment is ready. Now we will install Magento 2.
- Go to the web container using the below command
sudo docker exec -it web /bin/bash
sudo rm -rf src/index.php
- Get magento metapackage using the below command
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition:2.4.7-p1 .
- When prompted, enter your Magento authentication keys. For more information check this URL https://devdocs.magento.com/guides/v2.3/install-gde/.html
- Set file permissions using the below commands
cd /var/www/html
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
chown -R :www-data . # Ubuntu
chmod u+x bin/magento
php bin/magento config:set catalog/search/opensearch_server_hostname opensearch-node1
php bin/magento config:set catalog/search/opensearch_server_port 9200
php bin/magento cache:flush
SELECT * FROM `core_config_data` WHERE `path` LIKE '%base_url%';
UPDATE core_config_data SET value = 'http://localhost/' WHERE path = 'web/unsecure/base_url';
UPDATE core_config_data SET value = 'http://localhost/' WHERE path = 'web/secure/base_url';
- Install Magento using the below command
php bin/magento setup:install \
--base-url=http://localhost \
--db-host=db \
--db-name=magento \
--db-user=magento \
--db-password=magento \
--admin-firstname=pandurang \
--admin-lastname=babar \
[email protected] \
--admin-user=admin \
--admin-password=admin@123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1 \
--search-engine=opensearch \
--opensearch-host=opensearch-node1 \
--opensearch-port=9200 \
--opensearch-index-prefix=magento2 \
--opensearch-timeout=15
- Disable Two factor Authentication module in Magento
php bin/magento module:disable Magento_AdminAdobeImsTwoFactorAuth
php bin/magento module:disable Magento_TwoFactorAuth
php bin/magento cache:flush
- Run below commands.
php bin/magento cache:flush
php bin/magento deploy:mode:set developer
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex
Now magento installation is complete.
- Frontend URL - http://localhost/
- Backend URL - When installation complete copy backend url from screen
Thank You.