1 2 3 4 |
wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -O .ssh/authorized_keys chmod 700 .ssh chmod 600 .ssh/authorized_keys chown -R vagrant:vagrant .ssh |
Basic Magento 2 extension skeleton
What is necessary to create a very basic Magento 2 extension skeleton? Not that much. If you’re don’t have a patience to read the whole article – here is a link to download.
If you do – let’s start from basics.
1 |
php bin/magento deploy:mode:set developer |
Create module
In Magento 1 we have three code pool folders under app/code
directory: core
, community
and local
. It’s much simplified in Magento 2 – now all extensions located by their namespace in same directory: app/code
.
So to begin with module setup we need to create necessary files and folders. And here is a structure:
1 2 3 4 5 6 |
app/code |_ YourName |_ FooBar |_ etc |_ module.xml |_ registration.php |
Now, when we have module structure – let’s fill it with some code:
1. Add following to app/code/YourName/FooBar/registration.php
:
1 2 3 4 5 6 7 8 9 |
<?php /** * Basic Magento 2 extension skeleton */ \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'YourName_FooBar', __DIR__ ); |
2. And this to app/code/YourName/FooBar/etc/module.xml
:
1 2 3 4 5 6 7 8 9 10 11 |
<?xml version="1.0"?> <!-- /** * Basic Magento 2 extension skeleton */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="YourName_FooBar" setup_version="1.0.0"> </module> </config> |
Yes, that’s it – bare minimum to register new Magento 2 extension.
Module setup
Now when we have all necessary module files and folders in place – let’s register and enable it.
Navigate to your magento root folder and run following commands in terminal:
1 2 |
php bin/magento module:enable --clear-static-content YourName_FooBar php bin/magento setup:upgrade |
This will enable your module, flush some cache and register it with the database.
Now go to Admin -> Stores -> Configuration -> Advanced -> Advanced
in admin panel. You should be able to see your module available there.
That’s all – in my next articles I will extend this basic skeleton and add a controllers, blocks, etc.
Install Magento 2 via command line
Sometimes (especially on shared hosting) Magento 2 web install just isn’t work – there is a plenty of reasons, but this post will not cover this topic, it’s about how to install Magento 2 via command line. So here is a simple shell script and hints to add some tuning to your install.
Prerequisites
First of all you need to set correct file permissions. Per Magento recommendation change directory to you magento2 install root, then change ownership and file permissions:
1 |
chown -R :www-data . |
1 |
find . -type d -exec chmod 770 {} \; && find . -type f -exec chmod 660 {} \; && chmod u+x bin/magento |
Install
Now it’s time to install magento:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
php -f bin/magento setup:install \ --db-host=localhost \ --db-name=dbname \ --db-user=dbuser \ --db-password=dbpassword \ --backend-frontname=admin \ --admin-user=admin \ --admin-password=password \ --admin-email=admin@yourhost.com \ --admin-firstname=Firstname \ --admin-lastname=Lastname \ --base-url=http://youhost.com/ \ --base-url-secure=https://youhost.com/ \ --language=en_US \ --currency=USD \ --use-rewrites=1 \ --use-secure=0 \ --use-secure-admin=0 \ --timezone=America/Los_Angeles \ --cleanup-database |
Tune your installation
If you’re using xdebug there is a known issue, so you want to change installer first line just like this:
1 |
php -d xdebug.max_nesting_level=500 -f bin/magento setup:install \ |
If you have any special chars in db password – make sure to escape them:
1 |
--db-password=\!p4ssw0rd\! \ |
If you want to use secure URL on backend – just add next option:
1 |
--use-secure-admin=1 \ |
If you using a sample data just add this:
1 |
--use-sample-data \ |
Full list of install options could be found in Magento 2 devdocs. Hope that helps.
Create admin user in Magento via MySQL
Quick snippet on how to create admin user in Magento via MySQL query:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
LOCK TABLES `admin_role` WRITE , `admin_user` WRITE; SET @SALT = "rp"; SET @PASS = CONCAT(MD5(CONCAT( @SALT , "password") ), CONCAT(":", @SALT )); SELECT @EXTRA := MAX(extra) FROM admin_user WHERE extra IS NOT NULL; INSERT INTO `admin_user` (firstname,lastname,email,username,password,created,lognum,reload_acl_flag,is_active,extra,rp_token_created_at) VALUES ('Firstname','Lastname','user@email.com','username',@PASS,NOW(),0,0,1,@EXTRA,NOW()); INSERT INTO `admin_role` (parent_id,tree_level,sort_order,role_type,user_id,role_name) VALUES (1,2,0,'U',(SELECT user_id FROM admin_user WHERE username = 'username'),'Firstname'); UNLOCK TABLES; |
Multi Monitor Support for PHPStorm on MacOS Yosemite
I found very convenient to use a multi monitor support for PHPStorm on MacOS Yosemite to keep PHPStorm project tree, structure and debug windows on second monitor while developing. It’s pretty simple and well explained by JetBrains guys here. From benefits perspective it brings you more space to view project tree, easy to navigate and no need to switch windows to observe a real time debug.
But, of course, for MacOS, there is a bummer right out of the box. When I move floated windows to second screen, back to main project window and then click on any PHPStorm window on second monitor – it’s jump back to main window. This is quite annoying and kills the whole purpose of such a brilliant tool. If you struggle with the same issue – here is the fix for this:
Just open System Preferences > Mission Control
and uncheck Displays have separate Spaces
option. And that’s it! Happy coding.
If you find this article helpful – don’t hesitate to rate it below and share to help others.