Generate .htaccess config file using tee shell command

If you are using Docker setup for Yii2 Advanced application template to build REST API as I do, you could be interested in the command below:

tee /app/api/web/.htaccess <<EOF
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

it is generating .htaccess configuration file for Apache web server to redirect all requests from not existing files or directories to index.php file in API web application inside Docker container.

Multiple lines below starting < and closing EOF are the configuration file content. Such multiple lines syntax is called heredoc. You could choose any other identifier (one word in upper case letters) instead of EOF if you want.

Web server Apache Mod_rewrite module should be installed and enabled to make it work.

Docker network declared as external could not be found

I’ve faced the following error running CoreShop 3.0.2 demo in a Docker running command:

docker-compose up -d

I’ve got the following error:

network cors_dev declared as external, but could not be found

To fix it run the commands below:

docker network create "cors_dev"
docker-compose up -d

I hope this will save several minutes of your time.

Error 500: Attempted to load class “Twig_Function” from the global namespace. Did you forget a “use” statement?

During the Pimcore update from older versions to the most recent 10.5 at this time I’ve got the following errpr:

Attempted to load class "Twig_Function" from the global namespace. Did you forget a "use" statement?

To fix it add the following use statement to your class:

use Twig\TwigFunction;

And replace all Twig_Function to TwigFunction in your php class file code.

Git: search commits by author

To search commits by the author you can use the following command:

# git log --author="Taras Shkodenko"

where Taras Shkodenko example author name.

To get the list of all authors in a current Git repository use the useful command below:

# git shortlog -sne --all

Git: how to stash / unstash not commited changes

Git has a useful feature. You can stash not committed changes and then re-apply them. It helps you to restore the working directory and the index, to a clean working directory as it was before your not commited changes.

To stash your changes run a command below:

# git stash

To apply (unstash) your changes run a command below:

# git stash apply

To view list of stashes run a following command:

# git stash list

Read more about git stash on a documentation page.

Apache 2.4 virtual host config for a WordPress CMS

Example of a virtual host for web server Apache version 2.4 config to run a development copy of WordPress CMS:

<VirtualHost *:81>
    ServerName wpdev.test
    ServerAlias *.wpdev.test
    # Indexes + Directory Root.
    DirectoryIndex index.php index.html
    DocumentRoot "/Users/taras/wpdev/public_html"
    ErrorLog "/usr/local/var/log/httpd/wpdev.test/error.log"
    CustomLog "/usr/local/var/log/httpd/wpdev.test/access.log" common
    <FilesMatch \.php$>
        SetHandler "proxy:fcgi://"

    Options FollowSymLinks