カテゴリー: 技術系

  • Magento2.3.5のインストール後に管理ページが404エラーになる

    Ubuntuに、Magento 2.3.5をインストールした後に、管理ページにアクセスしたところ、ページが404エラーになった。他にも、いくつかのページが404エラーになった。

    原因は、Apacheのmod_rewriteの設定がMagentoのディレクトリで有効になっていないからだった。

    Apacheには、mod_rewriteを入れているし、読み込ませてもいるが、肝心のMagentoのディレクトリで使うように設定されていなかったのが原因。

    • .htaccess がMagentoのフォルダになかった
    • apache.confで、.htaccessによる設定の上書きができないようになっていた

    対処としては、後述の参考ページの設定をいれただけだ。

    まずMagentoのインストールディレクトリに下記の .htaccessを保存する。

    ###############################################
    ## overrides deployment configuration mode value
    ## use command bin/magento deploy:mode:set to switch modes
    #   SetEnv MAGE_MODE developer
    ############################################
    ## uncomment these lines for CGI mode
    ## make sure to specify the correct cgi php binary file name
    ## it might be /cgi-bin/php-cgi
    #    Action php5-cgi /cgi-bin/php5-cgi
    #    AddHandler php5-cgi .php
    ############################################
    ## GoDaddy specific options
    #   Options -MultiViews
    ## you might also need to add this line to php.ini
    ##     cgi.fix_pathinfo = 1
    ## if it still doesn't work, rename php.ini to php5.ini
    ############################################
    ## this line is specific for 1and1 hosting
        #AddType x-mapp-php5 .php
        #AddHandler x-mapp-php5 .php
    ############################################
    ## default index file
        DirectoryIndex index.php
    <IfModule mod_php5.c>
    ############################################
    ## adjust memory limit
        php_value memory_limit 768M
        php_value max_execution_time 18000
    ############################################
    ## disable automatic session start
    ## before autoload was initialized
        php_flag session.auto_start off
    ############################################
    ## enable resulting html compression
        #php_flag zlib.output_compression on
    ###########################################
    ## disable user agent verification to not break multiple image upload
        php_flag suhosin.session.cryptua off
    </IfModule>
    <IfModule mod_php7.c>
    ############################################
    ## adjust memory limit
        php_value memory_limit 768M
        php_value max_execution_time 18000
    ############################################
    ## disable automatic session start
    ## before autoload was initialized
        php_flag session.auto_start off
    ############################################
    ## enable resulting html compression
        #php_flag zlib.output_compression on
    ###########################################
    ## disable user agent verification to not break multiple image upload
        php_flag suhosin.session.cryptua off
    </IfModule>
    <IfModule mod_security.c>
    ###########################################
    ## disable POST processing to not break multiple image upload
        SecFilterEngine Off
        SecFilterScanPOST Off
    </IfModule>
    <IfModule mod_deflate.c>
    ############################################
    ## enable apache served files compression
    ## http://developer.yahoo.com/performance/rules.html#gzip
        # Insert filter on all content
        ###SetOutputFilter DEFLATE
        # Insert filter on selected content types only
        #AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
        # Netscape 4.x has some problems...
        #BrowserMatch ^Mozilla/4 gzip-only-text/html
        # Netscape 4.06-4.08 have some more problems
        #BrowserMatch ^Mozilla/4\.0[678] no-gzip
        # MSIE masquerades as Netscape, but it is fine
        #BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
        # Don't compress images
        #SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
        # Make sure proxies don't deliver the wrong content
        #Header append Vary User-Agent env=!dont-vary
    </IfModule>
    <IfModule mod_ssl.c>
    ############################################
    ## make HTTPS env vars available for CGI mode
        SSLOptions StdEnvVars
    </IfModule>
    ############################################
    ## workaround for Apache 2.4.6 CentOS build when working via ProxyPassMatch with HHVM (or any other)
    ## Please, set it on virtual host configuration level
    ##    SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
    ############################################
    <IfModule mod_rewrite.c>
    ############################################
    ## enable rewrites
        Options +FollowSymLinks
        RewriteEngine on
    ############################################
    ## you can put here your magento root folder
    ## path relative to web root
        #RewriteBase /magento/
    ############################################
    ## workaround for HTTP authorization
    ## in CGI environment
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    ############################################
    ## TRACE and TRACK HTTP methods disabled to prevent XSS attacks
        RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
        RewriteRule .* - [L,R=405]
    ############################################
    ## redirect for mobile user agents
        #RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
        #RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
        #RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]
    ############################################
    ## never rewrite for existing files, directories and links
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-l
    ############################################
    ## rewrite everything else to index.php
        RewriteRule .* index.php [L]
    </IfModule>
    ############################################
    ## Prevent character encoding issues from server overrides
    ## If you still have problems, use the second line instead
        AddDefaultCharset Off
        #AddDefaultCharset UTF-8
    <IfModule mod_expires.c>
    ############################################
    ## Add default Expires header
    ## http://developer.yahoo.com/performance/rules.html#expires
        ExpiresDefault "access plus 1 year"
        ExpiresByType text/html A0
        ExpiresByType text/plain A0
    </IfModule>
    ###########################################
    ## Deny access to root files to hide sensitive application information
        RedirectMatch 404 /\.git
        <Files composer.json>
            order allow,deny
            deny from all
        </Files>
        <Files composer.lock>
            order allow,deny
            deny from all
        </Files>
        <Files .gitignore>
            order allow,deny
            deny from all
        </Files>
        <Files .htaccess>
            order allow,deny
            deny from all
        </Files>
        <Files .htaccess.sample>
            order allow,deny
            deny from all
        </Files>
        <Files .php_cs>
            order allow,deny
            deny from all
        </Files>
        <Files .travis.yml>
            order allow,deny
            deny from all
        </Files>
        <Files CHANGELOG.md>
            order allow,deny
            deny from all
        </Files>
        <Files CONTRIBUTING.md>
            order allow,deny
            deny from all
        </Files>
        <Files CONTRIBUTOR_LICENSE_AGREEMENT.html>
            order allow,deny
            deny from all
        </Files>
        <Files COPYING.txt>
            order allow,deny
            deny from all
        </Files>
        <Files Gruntfile.js>
            order allow,deny
            deny from all
        </Files>
        <Files LICENSE.txt>
            order allow,deny
            deny from all
        </Files>
        <Files LICENSE_AFL.txt>
            order allow,deny
            deny from all
        </Files>
        <Files nginx.conf.sample>
            order allow,deny
            deny from all
        </Files>
        <Files package.json>
            order allow,deny
            deny from all
        </Files>
        <Files php.ini.sample>
            order allow,deny
            deny from all
        </Files>
        <Files README.md>
            order allow,deny
            deny from all
        </Files>
    ################################
    ## If running in cluster environment, uncomment this
    ## http://developer.yahoo.com/performance/rules.html#etags
        #FileETag none
    ############################################
    ## Add custom headers
    <IfModule mod_headers.c>
        Header set X-Content-Type-Options "nosniff"
        Header set X-XSS-Protection "1; mode=block"
    </IfModule>

    次に、/etc/apache/の中のconfファイル(vhosts.confやapache.confなどから適切なものを書き換え)に下記を追加する。ディレクトリは、Magentoをインストールしたディレクトリに変える。

    <Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                allow from all
     </Directory>

    最後に、Apacheの再起動を行う。

    参考: https://qastack.jp/magento/89125/how-to-fix-magento-2-2-0-0-rc-admin-page-not-found-after-installation

  • ASP.NETのプログラムを新環境にデプロイしたら「有効な Win32 アプリケーション」とエラーがでる

    古いASP.NETのプログラムを、新しい環境でコンパイルして、アプリケーションサーバ(IIS)にデプロイして、テストしたら、下記のエラーが表示された。Visual Studio 2019上では動作している。

    ファイルまたはアセンブリ 'xxxxxxxx.DLL'、またはその依存関係の 1 つが読み込めませんでした。 は有効な Win32 アプリケーションではありません。 (HRESULT からの例外:0x800700C1) 

    問題は、アプリケーションサーバであるIISの設定だった。Windows Server 2019のIIS10は、デフォルトでは64ビットのアプリケーションサーバとして動作する。そのため、32ビットのDLLが混じったアプリケーションを実行するためには、IISの設定で、32ビットのアプリケーションを動作するようにしないといけなかった。

    32ビットのアプリケーションを動作するようにするIISの設定方法は下記。

    1. IISマネージャー(インターネットインフォメーションサーバーマネージャー)を開く。
    2. アプリケーションプールを選択する。
    3. 右クリックして、「詳細設定」を開く。
    4. 全般にある「32ビット アプリケーションの有効化」のプルダウンで、「True」を選択する。
    5. OKをクリックする
    6. アプリケーションタスクで、「停止」して「開始」する(たぶん、リサイクルでもOK)

    これで、32ビットのアプリケーションも動作するようになる。

  • GASのGoogle ChatのChat Botを作成して公開する手順

    久しぶりにGASで書いたChatbotのテストをしようとしたら、デプロイ方法が変わっていたので、書き直し。

    作成フェーズ

    1. Chat Bot のサンプルプロジェクトのファイルを開く
    2. プロジェクト名をつけて保存する
    3. GASのコードを書く

    デプロイ1(スクリプトエディタ側)

    1. GASのスクリプトエディタで、「公開」→「マニフェストから配置」の順にクリックする。
    2. どのバージョンをデプロイするのかを聞かれるので、「最新」を選び「Get ID」をクリックする。
    3. 表示された「Deployment ID」の値をコピーしておく(テキストに張り付けておくとよい)。
    4. 「Close」をクリックして閉じる。

    デプロイ2(Google Cloud Platform側)

    1. GASのスクリプトエディタとは別のタブで、Cloud Platformを開く。( https://console.cloud.google.com/ )
    2. Cloud Platformにログインする。
    3. 上部のメニュー部分のプロジェクト選択の部分をクリックして、ポップアップされた画面で、「新しいプロジェクト」を選択する。
    4. プロジェクト名などを入力して作成する。
    5. 左上のナビゲーションメニュから「APIとサービス」を選択する。
    6. 「+APIとサービスの有効化」をクリックする。
    7. 検索で、「chat」を入力する。
    8. 「Hangouts Chat API」を選択する(ここは、まだ古い名称のままだった)。
    9. 「有効にする」をクリックする。
    10. 左のメニューから「認証情報」をクリックする。
    11. 「+認証情報を作成」をクリックする。
    12. 「サービスアカウント」を選択する。
    13. サービスアカウントの名前などを入力して、作成する。
    14. 権限をクリックする。
    15. 「アクセスを許可」をクリックし、作成したサービスアカウントに「Project」の「オーナー」の権限をつける。
    16. (IAMの画面になっている場合は)左上のナビゲーションメニュから「APIとサービス」を選択する。
    17. 表示されているAPIの中から「Hangouts Chat API」をクリックする。
    18. 左のメニューから「設定」をクリックする。
    19. ボットの名前を入力する
    20. アバターのURLを入力する(https://goo.gl/yKKjbw)
    21. 説明を入力する。
    22. 機能を選択する(用途に合わせて選択する)
    23. 接続設定で、「Apps script project」を選択する。
    24. デプロイIDに、上記で取得した「Deployment ID」の値を入れる。
    25. 権限を選択する。
    26. 保存をクリックする。

    以上で、公開は完了。

    あとは、Google Chatからボットを検索して利用する。

  • PowerShell 7.1をインストールした

    PowerShell 7.1がMicrosoft Storeから入手できるようになったので、インストールした。Microsoft Storeで、PowerShellと検索して、Microsoft Corporationが公開しているものを選択して、入手をクリックするだけ。Powershell 7.0が自分でインストーラーをダウンロードしてインストールしていたのに比べるとかなり便利。これで、新しいバージョンの配布もされるだろうから、先々を考えると、ストアからの配信はありがたい。

    Microsoft StoreからPowerShell 7.1をインストールしたところ、Windows 10上には、最初からインストールされていたWindows PowerShell、手動でインストールしたPowerShell 7.0、ストアからインストールしたPowerShell 7.1の3つが混在するようになった。使うときに間違えないようにしないといけない。

    あと、どこかでPowerShell 7.0のアンインストールをしないと穴になってしまう。

  • VS2008のアプリをVS2019で開いて、デバック実行したら「Assembly.csが見つかりません」が表示された

    VS2008のアプリをVS2019で開いて、デバック実行したら「Assembly.csが見つかりません」が表示された。「Assembly.cs」を探したが見つからず。元のプロジェクトはVB.NETで書かれている。

    VS2019上には、逆コンパイルで作成も選択できたので、実行してみたが失敗した。

    失敗したので、今度は、Assenbly情報を再作成した。

    1. ソリューションエクスプローラーでプロジェクトを選び、右クリックからプロパティを開く。
    2. 「アプリケーション」を選択する。
    3. 「アセンブリ情報(Y)」をクリックする。
    4. ウィンドウが立ち上がるので、確認してOKをクリックする(なにも変更しなくてもよい)
    5. プロジェクトのリビルドを行う。
    6. デバック実行して、同じエラーにならないかを確認する。

    これでエラーが出なくなった。

  • GASからJDBCでCloud SQLに接続しようとすると接続が確立できない

    GAS(Google Apps Script)から、Cloud SQLに接続をJDBCから行ったのだが、下記のエラーが出て接続できない。

    Exception: データベース接続を確立できませんでした。接続文字列、ユーザー名、パスワードを確認してください。

    接続先の環境は、Cloud SQL(Google Cloud Platform SQL)上で新しく作ったインスタンスで、第2世代で、MySQL8.0のインスタンス。

    GASのソースコードとしては、下記。

    function dbConn() {
      var dbConnectName = "プロジェクト名:us-central1:インスタンス名"; // GCP上で表示される接続名
      var user = "ユーザ名";
      var password = "パスワード";
      var dbName = "DB名";
      
      var conURL = "jdbc:google:mysql://" + dbConnectName + "/" + dbName;
      Logger.log(conURL);
      
      var dbCon = Jdbc.getCloudSqlConnection(conURL, user, password);
      Logger.log(dbCon.getCatalog());
      
      return dbCon;
    }

    いろいろと調べて、JDBCの`Jdbc.getConnection`でも試したが、接続できず。

    原因として、わかったことは、GASから呼び出されるJDBCは、MySQL8.0へのインスタンスへの接続に対応していないということ。MySQL5.7で新しくインスタンスを作り直して、`Jdbc.getCloudSqlConnection`を行ったところ、あっさりと接続できた。

    まさか、JDBCが対応していないとは。

  • VS2008のソリューションをVS2019に変更したら、Request.ServerVariables(“LOGON_USER”)で値がとれなくなったら

    Visual Studio 2008のソリューションを、Visual Studio 2019の形式に変換した。.NET Frameworkも3.5から4.8に変更した。Visual Studio 2019でデバック実行したところ、ログインユーザの値が「Request.ServerVariables(“LOGON_USER”)」でとれなくなった。

    言語のバージョンか、.NET Frameworkのバージョン違いか、調べたが、ちゃんと残っていた。

    変わっていたのは、Visual Studio 2019上での開発サーバー(IIS)の設定値だった。プロジェクトのプロパティを開いたところ、開発サーバーの設定があり、そこの設定では、「Windows認証」が無効で、「匿名認証」が有効になっていた。これだと、LOGONしたことになっていないので、「LOGON_USER」の値は、空になる。

    開発サーバーの設定を、「Windows 認証」を有効にし、「匿名認証」を無効にした。その後、デバック実行して確認したところ、正常にログオンユーザが取れた。

  • Cisco ASAで現在のコネクション数を確認する

    リモートワークでほぼ使っていないはずのネットワークで、外部アクセスが遅いという。ウェブ会議などで、コネクション数が異常にふえていないかどうかを確認してみる。

    Cisco ASAにCLIで接続して、現在のコネクション数をカウントする。enableモードで、show conn count すると、現在の接続数がわかる。これは、そのからのVPN接続も、内部からのウェブなどのアクセスも含めたコネクション数になる。

    show conn count
    

    ■実行してみたところ

    ciscoasa# show conn count
    994 in use, 1701 most used
    ciscoasa#
    

    最大のコネクション数などを確認したい場合は、show resource usageで確認する。これで、最大数やピーク時の接続数などを一覧で確認できる。

    show resource usage
    

    ■実行してみたところ

    ciscoasa# show resource usage
    Resource                 Current        Peak      Limit        Denied Context
    Telnet                         1           1          5             0 System
    SSH Server                     0           1          5             0 System
    Syslogs [rate]                93        1137        N/A             0 System
    Conns                        983        1701     100000             0 System
    Xlates                      1016        2301        N/A             0 System
    Hosts                        427         720        N/A             0 System
    Conns [rate]                  27         478        N/A             0 System
    Inspects [rate]               12         477        N/A             0 System
    Routes                        56          69  unlimited             0 System
    ciscoasa#
    

    コネクション生成レートは、show perfmonコマンドで確認できる。

    ■実行してみたところ

    ciscoasa# show perfmon
    
    PERFMON STATS:                     Current      Average
    Xlates                                8/s          0/s
    Connections                          18/s          1/s
    TCP Conns                             7/s          1/s
    UDP Conns                            10/s          2/s
    URL Access                            0/s          0/s
    URL Server Req                        0/s          0/s
    TCP Fixup                             0/s          0/s
    TCP Intercept Established Conns       0/s          0/s
    TCP Intercept Attempts                0/s          0/s
    TCP Embryonic Conns Timeout           0/s          0/s
    HTTP Fixup                            0/s          0/s
    FTP Fixup                             0/s          0/s
    AAA Authen                            0/s          0/s
    AAA Author                            0/s          0/s
    AAA Account                           0/s          0/s
    
    VALID CONNS RATE in TCP INTERCEPT:    Current      Average
                                           100.00%         100.00%
    ciscoasa#
    

    参考
    https://community.cisco.com/t5/%E3%82%BB%E3%82%AD%E3%83%A5%E3%83%AA%E3%83%86%E3%82%A3-%E3%83%89%E3%82%AD%E3%83%A5%E3%83%A1%E3%83%B3%E3%83%88/asa-%E3%82%B3%E3%83%8D%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E6%95%B0%E3%81%AE%E7%A2%BA%E8%AA%8D%E3%81%A8-%E8%86%A8%E5%A4%A7%E3%81%AA%E3%82%B3%E3%83%8D%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E7%99%BA%E7%94%9F%E6%99%82%E3%81%AEip%E3%82%A2%E3%83%89%E3%83%AC%E3%82%B9%E7%A2%BA%E8%AA%8D%E6%96%B9%E6%B3%95/ta-p/4082463

  • GitLab CEのデフォルトのブランチ名を変える

    GitLabo CEでデフォルト設定を変えないと、プロジェクトを作った時のGitリポジトリのイニシャルブランチ名が「master」のままになってしまう。SVNなどから移行するときに、ブランチ名が「Main」だと別ブランチになってしまうので、今後に備えて、デフォルトのブランチ名を変えておく。

    1. GitLaboの管理画面に入る
    2. 設定からリポジトリを選択する(Settings からRepositoriesを選択する)
    3. 「Default initial branch name」を展開する
    4. ブランチ名を入力して、変更を保存する
  • git svn initを実行したらエラーになった

    Windows10で、git svn initを実行して、SVNのリポジトリをGitのリポジトリに変換しようとしたところ、perlでエラーになった。

    C:\Users\hoge\Documents\SVN>git svn init -T http://svn.xenos.jp/svn/app1/Trunk/ -t http://svn.xenos.jp/svn/app1/Tags/ --username=hoge
    svn: E235000: In file 'subversion/bindings/swig/perl/libsvn_swig_perl/swigutil_pl.c' line 1666: assertion failed (get_current_pool_cb != NULL)
          1 [main] perl 1052 cygwin_exception::open_stackdumpfile: Dumping stack trace to perl.exe.stackdump
    C:\Users\hoge\Documents\SVN>
    C:\Users\hoge\Documents\SVN>git --version
    git version 2.27.0.windows.1
    C:\Users\hoge\Documents\SVN>
    

    バージョンを確認したら、新しいGitのバージョンが出ていたので、2.29.2にアップデートして、もう一度、試したら、成功した。

    参考: https://teratail.com/questions/266878