b23prodtm / acake2php

The Docker web-server features well-known functionalities as cool as posting some web contents with pictures stored in a database. Submodules may be installed via Composer packages.
http://www.b23prodtm.info
Apache License 2.0
1 stars 0 forks source link
apache cakephp circleci cms docker-image mariadb mysql openshift php-framework

We are moving to Kubernetes to host our website... See more about that project in Kubespray.

A CakePHP 2.x application

TravisCI Status CircleCI Status

Including PHP-CMS ex-Pohse

Quickstart

Using the basic container orchestrator or engine to deploy and test, is straitforward. Currently the deployment script . deploy.sh Based on Balena engine. See more about NodeJs dependencies

balena deploy button

Plugins

You do not need to change anything in your existing PHP project's repository. However, if these files exist they will affect the behavior of the build process:

CakePHP Plugins

Plugins are registered in both git submodule and composer.json. To allow a plugin to accept composer update, edit composer.json according to the available released tags. In the plugin's home repository (app/Vendor/<package-name> or app/Plugin/<plugin-name>/)

NodeJs dependencies

This project depends on npmjs balena-cloud. Please call npm update whenever the system complains about balena_deploy not found.

Compatibility

CAKE includes a server application that´s only made for local tests on port 9000. Open a Terminal window:

DB=Mysql ./configure.sh --mig-database -u
./start-cake.sh --docker -c server -p 9000

Ctrl-click the URLs to open them in the browser. To get more help about the command line interface :

./start-cake.sh --help

PHPUnit Test

JUNIT tests are available with the following call to CAKE server: Open a Terminal window:

./test-cake.sh

There are options (--travis, --openshift, --circle) dedicated to continuous integration build environments. Use --help to see more about options.

See below to allow access on the built-in local server.

Device pod environment

When deployment happens on device or is triggered by a git push event, 'source-to-image (s2i)', the httpd-server or pod needs proper environment variables to be set ready. Otherwise the scripts will fail with an error state, unable to connect to the database

The following variables must be set up as server environment, provided by your database administrator:

# Sqlite, Postgres
DB:Mysql

Note: DB selects CakePhp Model/Datasource/Database DBOSource class to configure SQL connections.

MYSQL_DATABASE:default
# a hostname or IP address
MYSQL_HOST:mysql

Note: Prefixed with TEST_ they are used by the index.php?test=1 URLs and ./test-cake.sh (--travis)

The following additional variables must be set up as server secrets environment, provided by your database administrator:

#(optional)
WEBHOOK_URL:<discordapp-url>
# Persistent connection credentials
DATABASE_USER:<provided-user>
MYSQL_ROOT_PASSWORD:<provided-password>
# Just add MYSQL_USER and MYSQL_PASSWORD
MYSQL_USER:<test-user>
MYSQL_PASSWORD:<test-password>
# CakePHP generated
CAKEPHP_SECRET_TOKEN:<secret-token>
CAKEPHP_SECRET_SALT:<secret-salt>
CAKEPHP_SECURITY_CIPHER_SEED:<cipher-seed>
# Generated by ./configure.sh -h
GET_HASH_PASSWORD:<hashed-password>

MYSQL_DATABASE
aria_db

MYSQL_HOST
db

MYSQL_PASSWORD
maria-abc

MYSQL_ROOT_PASSWORD
mariadb

MYSQL_TCP_PORT
3306

MYSQL_USER
maria

SERVER_NAME
<Domain-Name>

Database terminal

Container engines provides provide a confined environment, with persistent storage. Check that last database deployment was successful, open a pod shell :

Inside db pod:

mysql -uroot --password=${MYSQL_ROOT_PASSWORD}

Issue some SQL statements, for instance :

ùse aria_db; show tables; should list tables

Inside acake2php pod:

cake schema update --connection=default should build the databases

cake schema update --connection=test should build the test databases

More Database Configuration

An SQL server (must match remote server version) must be reachable by hostname or via its socket. If it's the 1st time you use this connection,

Configure it as a service and configure the login ACL with the user shell.

./configure.sh -d -u -i
mysql_secure_installation
./configure.sh -d -p <root-password> -i --sql-password=<new-password>
./configure.sh --help && ./migrate-database.sh --help

Generate new administrator password

To sign in with staff rights, at http://localhost/admin/index.php, somebody needs a unique password stored in GET_HASH_PASSWORD. One way to generate this hashed password with "salted“ encryption and setup:

    ./configure.sh -h -p <password> -w <salt>

To regenerate or read the current password hash again, simply browse to http://localhost/php-cms/e13/etc/getHashPassword.php

GET_HASH_PASSWORD=<HaSheD/PasSwoRd!> must be stored in the local server environment as a system readable variable.

Common Issues

  1. How to fix the following error?

    Index page displays:

    errno : 1146
    sqlstate : 42S02
    error : Table 'phpcms.info' doesn't exist

    Try the following to migrate (update) all database tables, answer 'y' when prompted:

    ./migrate-database.sh -u
  2. ACCESS DENIED appears with other information complaining about database connection, what does that mean ?

    You probably have modified user privileges on your server:

    mysql -u root
    use mysql;
    grant all PRIVILEGES on $TEST_DATABASE_NAME.* to '$MYSQL_USER'@'$MYSQL_HOST';
    exit
    ```acake2php
    ./configure.sh -c

    This will reset the connection profile in ..etc/ properties file with the template. More about environment variables are located in the remote pod (OpenShift) settings and locally in ./Scripts/fooargs.sh.

    Note:

    ./configure.sh --mig-database -p -i --sql-password

    to do a reset with environment root and user password.

  3. ACCESS DENIED for root@'127.0.0.1' or root@'localhost' appears with other information complaining about database connection, what does that mean ?

    (automatic) This looks like a first installation of mysql. You have to secure or reset your mysql root access:

    MYSQL_ROOT_PASSWORD=<password> sudo bash deployment/images/mysqldb/mysql_secure_shell

    (manual) The Linux shell way to reinitialize sql root password:

    sudo rm -rf /usr/local/var/mysql
    mysqld --initialize | grep "temporary password" | cut -f4  -d ":" | cut -c 2-  > app/tmp/nupwd

    Note: A temporary password is generated for root@localhost. Now import identities.

    brew services restart mysql@5.7
    ./configure.sh --mig-database -p $(cat app/tmp/nupwd) -i --sql-password

    You have now configured a new SQL root password and a test password. Local SQL access and server is ready to run tests:

    ./test-cake.sh -p -t <test-password>

    Go on to development phase with the Local Built-in server.

  4. I've made changes to mysql database tables, I've made changes to Config/Schema/schema.php, as Config/database.php defines it, what should I do ?

    Migrate all your tables:

    ./migrate-database.sh -u

    Answer 'y' when prompted.

  5. How to fix up 'Database connection "Mysql" or could not be created ? PHP mysql extensions must be installed.

    php -i | grep Extensions

    Log in with root privileges should work:

    mysql -u root --password=${MYSQL_ROOT_PASSWORD}

    If not, do a reset of your passwords:

    mysqladmin -uroot password

    If it isn't possible to login:

    • Check your environment variables (common.env and docker-compose.yml) settings). Use one or the other, and see which works for you:
      MYSQL_HOST=$(hostname)
      ```(Unix/OSX platforms)
          or if docker-compose services are the following name:

      MYSQL_HOST=db MYSQL_TCP_PORT=3306

    • Debug the local configuration, look for unbound VARIABLES, add verbosity level information (add -o if you are in a remote shell):
      set -u
      ./configure.sh --verbose -d -u
    • Try resetting privileges
      ./configure.sh --mig-database -p ${MYSQL_ROOT_PASSWORD} -t ${MYSQL_PASSWORD} -i

      Don't miss the parameter to startup a local container database :

      ./migrate-database.sh -u --docker -i or ./configure.sh --mig-database -u --docker -i
    • Note that localhost is a special value. Using 127.0.0.1 is not the same thing. The latter will connect to the mysqld server through tcpip.
    • Try the secure_installation.
  6. How to fix up ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2) ?

    Run the socket fixup script with arguments:

    ./migrate-database.sh /tmp/mysqld.sock
    brew services restart mysql@5.7
  7. I'm testing with ./start_cake.sh and I cannot add any new post on Updates section, what should I do ?

    With the CLI, you may ctrl-X ctrl-C to exit server and migrate your database:

    ./migrate-database.sh -u
    ./start_cake.sh

    Answer 'y' when prompted.

  8. I cannot upload any picture, why ?

    The Mysql.php Datasource must define binary and mediumbinary storage types. Please look at the file __app/Model/Datasource/Mysql_cms.php__ if it exists and if you experienced the following error:

    errno : 1054
    sqlstate : 42S22
    error : Unknown column 'image' in 'field list'

    Add the mediumbinary storage, extending the original Datasource class:

<?php
App::uses('Mysql', 'Model/Datasource/Database');

class Mysql_cms extends Mysql
{
    public function __construct()
    {
        parent::__construct();
        $this->columns['mediumbinary'] = array('name' => 'mediumblob');
    }

    /**
     * Converts database-layer column types to basic types
     *
     * @param string $real Real database-layer column type (i.e. "varchar(255)")
     * @return string Abstract column type (i.e. "string")
     */
        public function column($real) {
            $s = parent::column($real);
            if($s === "text") {
                $col = str_replace(')', '', $real);
                $limit = $this->length($real);
                if (strpos($col, '(') !== false) {
                    list($col, $vals) = explode('(', $col);
                }
                if (strpos($col, 'mediumblob') !== false || $col === 'mediumbinary') {
                    return 'mediumbinary';
                }
            }
            return $s;
        }
}
?>

Ensure it is set as $identities[DB]['datasource'] in app/Config/database.php,./Scripts/fooargs.sh, .travis.yml and update the database schema:

    ./migrate-database.sh -u
  1. It looks like submodule folders have disappeared, why ?

    A recent git checkout made the submodule disappear from disk, that can happen on master/development branch. Recall or add the shell configure script to your workflow:

    ./configure.sh -m
  2. Error: Please install PHPUnit framework v3.7 (http://www.phpunit.de)

    You need to configure development environment from Composer dependencies.

    ./configure.sh --development
  3. Undefined functins balena_deploy or init_functions: No such file or directory

    You need to export the node_modules/.bin for this shell to find npmjs installed binaries.

    export PATH="`pwd`/node_modules/.bin:\$PATH"
  1. Any message "saved[@]: unbound variable" on Darwin (OSX)

    Your BASH doesn't handle array in scripts and uses version 3. Please upgrade to v.4 or later. Check your bash version and upgrade OpenSSL Cacert as well:

    .travis/TravisCI-OSX-PHP/build/prepare_osx_env.sh

    License

    Copyright 2016 www.b23prodtm.info

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

    Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.