vagrant + ContOS7 + php7.2 + nginx + phalcon4 environment construction and problem recording

vagrant + ContOS7 + php7.2 + nginx + phalcon4 environment construction and problem recording

Reference: https://qiita.com/wjtnk/items/f2d72fb3790d008a3154

Tool installation: https://www.virtualbox.org/ https://www.vagrantup.com/

1. Launching a virtual environment

$ mkdir phalcon
$ cd phalcon
$ mkdir sync
$ vagrant init CentOS7

Edit phalcon / Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  #IP address for local access.
  config.vm.network "private_network", ip: "192.168.10.10"
  #Specify the synchronization destination. "Current directory (.)/"Synchronize under vagrant" and "sync directory"/var/www/Synchronize below.
  config.vm.synced_folder ".", "/vagrant"
  config.vm.synced_folder "sync", "/var/www/"
  config.vm.network "forwarded_port", guest: 80, host: 8080
  #Now let's use epel and remi.
  config.vm.provision "shell", inline: <<-SHELL
    sudo yum update -y
    sudo yum -y install epel-release
    sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
  SHELL
end

Launch vagrant

$ cd phalcon
$ vagrant up --provision

If an error occurs, handle it with an error message.

https://qiita.com/chubura/items/4166585cf3f44e33271d

Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

The solution is:

$ vagrant plugin install vagrant-vbguest

2. Install the required applications in the virtual environment

$ vagrant ssh
$ sudo yum install --enablerepo=remi-php72 php php-mbstring php-mcrypt php-mysqlnd php-pdo php-fpm nginx -y

Edit php-fpm settings

$ sudo vi /etc/php-fpm.d/www.conf

Note: Search vim with "/"

/etc/php-fpm.d/www.conf


; user = apache 
; group = apache
; listen = 127.0.0.1:9000
;listen.owner = nobody
;listen.group = nobody

user = nginx    
group = nginx    
listen = /run/php-fpm/php-fpm.sock  
listen.owner = nginx 
listen.group = nginx   

Edit nginx settings

sudo vi /etc/nginx/nginx.conf

For root, specify the root directory specified in the Vagrantfile mentioned above. I set "allow all;", but when I control access by IP address with Nginx, I set it separately. reference: https://dev.classmethod.jp/articles/nginx-ip-access-control/

/etc/nginx/nginx.conf


 server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /var/www;
        index index.php index.html index.htm;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {
            #$_SERVER['REQUEST_URI']use
            try_files $uri $uri/ /index.php;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }

        location ~ .php$ {
            fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
            include fastcgi_params;
        }
    }

At this stage, test the server once

$ exit
$ cd sync
$ touch index.php

index.php


<?php phpinfo();

After completing the settings, check if the file is reflected in the virtual environment.

[vagrant@localhost /]$ cd var/www
[vagrant@localhost www]$ ls
cgi-bin  html  index.php

Start the server. Note: A reboot is required when new additions such as php extensions occur.

$ vagrant ssh
$ sudo systemctl restart php-fpm
$ sudo systemctl restart nginx

##Status check, successful if active
$ sudo systemctl status php-fpm
$ sudo sudo systemctl status nginx

If you access 192.168.10.10 and the phpinfo page appears, you are successful.

Occasionally, in the case of "403 Forbidden with Nginx", there is a workaround either to change the permissions of the files under "/ var / www" or to disable SELinux. Reference: https://engineers.weddingpark.co.jp/?p=1765

3. Install phalcon4

$ sudo yum install --enablerepo=remi-php72 php-phalcon4 -y

Find the installed phalcon.so.

$ find / -name phalcon.so

Found in the following places.

/usr/lib64/php/modules/phalcon.so
/usr/lib64/php-zts/modules/phalcon.so
php --info | grep phalcon

If you output below, you're done:

/etc/php.d/50-phalcon.ini
phalcon
phalcon => enabled

Access 192.168.10.10 again, and if "phalcon" appears on the phpinfo page, it is successful. スクリーンショット 2020-09-09 15.20.36.png

Recommended Posts

vagrant + ContOS7 + php7.2 + nginx + phalcon4 environment construction and problem recording
virtulbox + vagrant + Docker + nginx + puma + MySQL Rails environment construction
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
Environment construction summary with rvm and postgresql
Minimal Java environment construction and Hello World