PHP(Phalcon) + Nginx + Mysql with Docker compose - Part 2

by Lovefield

Back End /

Hi, I’m Lovefield.

Did docekr-compose up-d work well following the previous article? If you've run it correctly, you'll see page 404 of nginx after connecting to localhost. No code is ready yet, so it's obvious, right?

Let's create a component.json in the phalcon folder.

   "name": "phalcon/blog",
   "description": "Phalcon project!",
   "license": "proprietary",
   "require": {
     "php": "^7.4",
     "phalcon/devtools": "v4.0.3",
     "phalcon/cphalcon": "4.0.6"

Access the "php" container via the command dockerexec -itphp /bin/bashDownload the underlying library for the phalcon project with the composer install command inside the container.
You should be able to write the command at the end of the download, but you should find and use the executable file yourself because you cannot use the command if it is a bug.

Using vendor/palcon/devtools/palcon executes the phalcon command.


Create a phalcon project through vendor/palcon/devtools/palcon create-project blog Then a blog project will be created in the phalcon folder. We will use the phalcon folder as a project, so we move all the files to the phalcon folder location.


Now, when you connect to localhost, the following screen will appear.


Now the screen using phalcon is accessible. Lastly, we need to set up a DB. I personally use Mysql Workbench.


After setting it as above, enter root_pw, the root password, through the Store in Keychain.


You can check if it works normally.I checked that DB is OK, so please modify "palcon/app/config/config.php" to connect to db from Phalcon.

defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');

return new \Phalcon\Config([
   'database' => [
       'adapter'     => 'Mysql',
       'host'        => 'mysql:3306',
       'username'    => 'root',
       'password'    => 'root_pw',
       'dbname'      => 'app',
       'charset'     => 'utf8',
   'application' => [
       'appDir'         => APP_PATH . '/',
       'controllersDir' => APP_PATH . '/controllers/',
       'modelsDir'      => APP_PATH . '/models/',
       'migrationsDir'  => APP_PATH . '/migrations/',
       'viewsDir'       => APP_PATH . '/views/',
       'pluginsDir'     => APP_PATH . '/plugins/',
       'libraryDir'     => APP_PATH . '/library/',
       'cacheDir'       => BASE_PATH . '/cache/',
       'baseUri'        => '/',

All settings are now finished. One Phalcon project with DB associates was created.




Web Front-End developer

하고싶은게 많고, 나만의 서비스를 만들고 싶은 변태스러운 개발자입니다.


디코에 오신 것을 환영해요!
전문가들의 수많은 아티클 창고 🤓