Ubuntu: How To Create Virtual Host

1. create a directory using the following command.

sudo mkdir -p /var/www/example.com/public_html

2. Grant Permission to your newly directory

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com/public_html

3. Create a new config file using default config file

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf

4. Edit example.com.conf file

a) Run

sudo nano /etc/apache2/sites-available/example.com.conf

b) Paste the below code and save the file

ServerAdmin admin@example.com
ServerName example.com
ServerAlias http://www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

5. Enable site using following command

sudo a2ensite example.com.conf

6. Restart Apache server

sudo service apache2 restart

7. Set ip in host file
a) Run

sudo nano /etc/hosts

b) Add IP e.g xxx.xxx.xxx.xxx example.com

8) Create index.html file

sudo nano /var/www/example.com/public_html/index.html

add any html here like

Hello World!

9. Now run http://www.example.com on browser.

Advertisements

Ubuntu: Share folder using user account details

1. Install samba:

sudo apt-get install samba

2. Create new account for share:

sudo smbpasswd -a desired_user_name

3.it will ask for password give your desired password.

4. Share the folder you want to share.

Ubuntu: Zip folder content to another directory

zip -r destination_folder /source_folder

For Ex: zip -r  /home/offvgod-admin/temp/media.zip /home/offvgod-admin/public_html/media

Magento 2 : How to Override Model

Configuration of Module:

Create module.xml in
app/code/Techievolve/Product/etc and add the following code to it:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Techievolve_Product" setup_version="1.0.1">
    </module>
</config>

Module Registration:

Create registration.php in
app/code/Techievolve/Product and add the following code to it:

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Techievolve_Product',
__DIR__
);

Override di.xml

Create di.xml in app/code/Techievolve/Product/etc in order to specify which model to override by using and .

Add the following code to the di.xml file:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Catalog\Model\Product" type="Techievolve\Product\Model\Catalog\Product" />
</config>

Override Product.php

<?php

namespace Techievolve\Product\Model\Catalog;

class Product extends \Magento\Catalog\Model\Product {

    public function getName() {
       return $this->_getData(self::NAME) . ' + Test Text';
    }

    public function getSku() {
    
        return "Test-Demo";
    }
}

Run the following commands using ssh or terminal:

php bin/magento module:enable Techievolve_Product
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush

Magento2: After install run the following commands

Magento Fresh install 2 No Css Js After Install

cd /var/www/html/magento2/

sudo chmod 777 -R /var/www/html/magento2/

php bin/magento cache:flush

php bin/magento indexer:reindex

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento setup:static-content:deploy -f

php bin/magento cache:flush

For Remove version from css url:

We can disable it in Admin:
Stores > Configuration > Advanced > Developer > Sign Static Files

Or we can change directly the value in core_config_data:
insert into core_config_data (config_id, scope, scope_id, path, value) values (null, ‘default’, 0, ‘dev/static/sign’, 0);

Enable Apache mod rewrite:

sudo a2enmod rewrite

sudo nano /etc/apache2/sites-available/000-default.conf

Add the following code at the botom of file:

AllowOverride All

sudo systemctl restart apache2

Ubuntu: Apache switch Php Version

Switch From PHP 5.6 => PHP 7.2

sudo a2dismod php5.6
sudo a2enmod php7.2
sudo service apache2 restart

Command Line:-

sudo update-alternatives --set php /usr/bin/php7.2
sudo update-alternatives --set phar /usr/bin/phar7.2
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.2
sudo update-alternatives --set phpize /usr/bin/phpize7.2
sudo update-alternatives --set php-config /usr/bin/php-config7.2

Switch From PHP 7.2 => PHP 5.6

sudo a2dismod php7.2
sudo a2enmod php5.6
sudo service apache2 restart

Command Line:-

sudo update-alternatives --set php /usr/bin/php5.6
sudo update-alternatives --set phar /usr/bin/phar5.6
sudo update-alternatives --set phar.phar /usr/bin/phar.phar5.6 
sudo update-alternatives --set phpize /usr/bin/phpize5.6
sudo update-alternatives --set php-config /usr/bin/php-config5.6

Git :: status shows files as changed even though contents are the same

I have resolved this problem using following stpes

1) Remove every file from Git’s index.

git rm --cached -r

2) Rewrite the Git index to pick up all the new line endings.

git reset --hard