
Why am I installing Magento
My goal before the end of March 2023 is to get a magento2 certification just to add to my resume. So currently a complete beginner when it comes to the software.
Problems
Cannot connect to MYSQL
Checklist
- Right username and password ? : In my case, username is the default “root” and password is empty.
- Stop and restart mysql : I am on the ubuntu sub-system, so I simply type the following commands
sudo service mysql stop
sudo service mysql start
Error
ErroR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (13)
Connection is broken because of wrong password
I mistakenly changed the default password ( which is empty on installation ) and forgot what the new one was. So I had to remove mysql and re-install again. Do not be like me.
Error
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
This is why reading and not scrolling through the instructions is important
All I needed to do was READ this list and install the recommended versions of each software. Additionally, there are some php extensions listed below on the page, so do not forget to install those as well.
php, mysql, elastic search, composer and apache2
Error
Problem 1 - Root composer.json requires magento/product-community-edition 2.4.5-p1 -> satisfiable by magento/product-community-edition[2.4.5-p1].
Sometimes don’t be to perfect 😭
About what I said above, forget that, a bit. Apparently, according to this issue, the error below will appear because of wrong composer version. Although the list insists we install version 2.2 of composer, I had to downgrade to 2.1. Thus just run composer selfupdate -- 2.1.4
command, that is all.
Error
lugin initialization failed (require(app/etc/NonComposerComponentRegistration.php): Failed to open stream: No such file or directory), uninstalling plugin
- Removing laminas/laminas-dependency-plugin (2.5.0)
Install of laminas/laminas-dependency-plugin failed
[ErrorException]
require(app/etc/NonComposerComponentRegistration.php): Failed to open stream: No such file or directory
Create said database if it does not exist
So yea, check if your target database ( in my case “magento” ) exists before running the script below. If it does not exist, create it as shown in this post.
sudo bin/magento setup:install --base-url=http://localhost/magento2ee --db-host=localhost --db-name=magento --db-user=root --db-password= --admin-firstname=admin --admin-lastname=admin --admin-email=admin@admin.com --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --search-engine=elasticsearch7 --elasticsearch-host=es-host.example.com --elasticsearch-port=9200 --elasticsearch-index-prefix=magento2 --elasticsearch-timeout=15
Check if database exist
run SHOW DATABASES;
if not on the list, then run
CREATE DATABASE <database_name>
Error
SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost' (using password: YES)
Are you connecting to elasticsearch correctly?
So my elastic search is running locally on localhost:9200 not on es-host.example.com. So all I needed to do was change the value of key “–elasticsearch-host” to “localhost” or “127.0.01” as explained here.
Error
In SearchConfig.php line 81:
Could not validate a connection to Elasticsearch. Warning: A non-numeric value encountered in /var/www/html/example
/vendor/ezimuel/ringphp/src/Client/CurlFactory.php on line 424
Formatting ruins everything!!
Multiple copying and pasting can change the text, so be careful. In my case they value of “use-rewrite” wasn’t processed correctly so I had a so I re-arranged the keys and re-wrote the values for it to work.
sudo bin/magento setup:install --db-host="localhost" --db-name="magento" --db-user="root" --base-url="http://magento-dev.com" --admin-firstname="admin" --admin-lastname="admin" --admin-email="admin@admin.com" --admin-user="admin" --admin-password="admin123" --language="en_US" --currency="USD" --timezone="America/Chicago" --elasticsearch-host="localhost" --use-rewrites="1" --elasticsearch-port=9200 --elasticsearch-index-prefix=magento2 --elasticsearch-timeout=15
Error
Command option 'use-rewrites': Invalid value. Possible values (0|1).
Failed elastic connection again.
Error
Elasticsearch: Failed to connect to localhost port 9200 - Connection refused
Something wrong with ES nodes
Error
Could not validate a connection to Elasticsearch. No alive nodes found in your cluster
Magento 2.4 not loading in localhost
Please do not assume my solution is 100% correct. I just use it because it works. Nothing more 😀 .
Solution
sudo service apache2 start
Error
404
Result
Where do I find the error logs from Nginx
On my computer, it is located on
/var/log/nginx/error.logs
This helped me immensely in figuring if my bug was from Nginx or a browser problem.
Curl works but it shows an empty result.
This happened just now. I tested the domain www.magento-dev.com using the curl command, which showed nothing. So I checked the error logs and saw an error related to permissions. After reading some Stack Overflow answers, I realised that I had missed two steps, namely:
chown -R :www-data . # Ubuntu
chmod u+x bin/magento
Curl works but not browser ?
I had to add the domain not on in the /etc/hosts file within the ubuntu subsystem, but also in c:\Windows\System32\Drivers\etc\hosts file of my windows system. So two places to added the domain. I simply added the following line to the hosts file of windows :
127.0.0.1 magento-dev.com
Domain works, but static files are not loading.
On my network tabs all the /static/ files requests were showing 404. So I checked if the folder existed, nope it did not. After researching again, I had to run the following command for the folder static to be generated :
bin/magento setup:static-content:deploy -f
FINALLLY!!!! Took days but, it worked!
Cant enter admin area?
Because of 2FA right ? Simply run the following command to deactive the
bin/magento module:disable Magento_TwoFactorAuth
Editors notes
I kid you not this took forever to fix. But did it! So finally back to the Magento2 tutorial. Oh before you go, there are other errors I encountered but were solved via the explanations provided in the links below. See yall later!
Important links
Advanced on-premises installation
Quick start on-premises installation
How to Install Magento 2 on Windows 11 WSL
How to Fix Magento Admin 404 Error After Install
Magento’s setup:db:status fails with MySQL 8.0.29
How to view a new website using your hosts file
404 not found magento 2 static and media files not loading
You need to configure Two-Factor Authorization in order to proceed