Creating a Vagrant PHP 8 box

PHP 8 is generally available since 26th November and now it’s the time to start considering the migration to the latest php version. I’m here just recoding the steps for building a vagrant based simple dev environment for php 8.0.

Final code can be fond in this repo: https://github.com/thilinah/php8-vagrant

Add a Vagrantfile under your project to start with debian linux.

Vagrant.configure("2") do |config|
  config.vm.box = "debian/buster64"
end

Assuming we already have Vagrant installed, should run vagrant up first

vagrant up

This creates a running vagrant machine, which you can ssh into. Ssh into the machine and update all required certificates.

vagrant ssh
sudo apt-get update

Download the Sury PPA for PHP 8 package

sudo apt -y install lsb-release \
                    apt-transport-https \
                    ca-certificates wget
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

Update source list

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list

sudo apt update

Install php fpm and cli

sudo apt-get install php8.0-cli php8.0-fpm
php -v

Install xdebug

Xdebug is essential for most of the php developers. So lets first install it and configure it

sudo apt-get install php8.0-xdebug

Update xdebug configuration

sudo nano /etc/php/8.0/mods-available/xdebug.ini

Here we need to pay attention to the xdebug.remote_host, as we have selected 192.168.10.1, we should use an IP like 192.168.10.100 for the vagrant machine

zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=192.168.10.1
xdebug.client_port=9003

Install other required php extensions

sudo apt install php8.0-{common,mysql,xml,curl,gd,imagick,cli,dev,imap,mbstring,opcache,soap,zip,intl,bcmath} -y

Update default Php runtime parameters (optional)

sudo nano /etc/php/8.0/fpm/php.ini

upload_max_filesize = 50M 
post_max_size = 50M 
memory_limit = 256M 
max_execution_time = 600

Install Nginx

sudo apt-get install nginx

Assign an IP to the Vagrant Machine

Updates to Vagrantfile

 Vagrant.configure("2") do |config|
  config.vm.box = "debian/buster64"
  config.vm.network "private_network", ip: "192.168.10.100"
      config.vm.synced_folder ".", "/vagrant", type: "nfs"

      config.vm.provider "virtualbox" do |vb|
        vb.memory = "1024"
        vb.cpus = "2"
      end
end
exit
vagrant reload
vagrant ssh

Visit http://192.168.10.100 and you should see

Change Nginx default site root to /vagrant

Add nginx default site to your workspace

<work-space>/deployment/nginx/sites-available/default

server {
   listen 80;
   listen [::]:80;

    root /vagrant;

    # Add index.php to the list if you are using PHP
    index index.html index.php;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    # pass PHP scripts to FastCGI server
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}

Update Vagrantfile to replace default nginx file during provision

Vagrant.configure("2") do |config|
  config.vm.box = "debian/buster64"
  config.vm.network "private_network", ip: "192.168.10.100"
      config.vm.synced_folder ".", "/vagrant", type: "nfs"

      config.vm.provider "virtualbox" do |vb|
        vb.memory = "1024"
        vb.cpus = "2"
      end

      config.vm.provision "shell", inline: <<-SHELL
          sudo rm /etc/nginx/sites-enabled/default
          sudo ln -s /vagrant/deployment/nginx/sites-available/default /etc/nginx/sites-enabled/default

          sudo service nginx restart
          sudo chmod 755 -R /var/log
      SHELL
end

Add Php files to Workspace

Create index.php and info.php in your workspace root to test if everything is working fine.

index.php

<?php
echo 'Welcome to PHP 8.0';

info.php

<?php
phpinfo();

Reload Vagrant

exit
vagrant reload
vagrant ssh
sudo service nginx restart

Visit http://192.168.10.100/info.php and you should see php 8.0 info from your vagrant machine

Install MySQL 5.7 or 8.0

Going one step further you can install your preferred DB also and the PHP framework you want to start with

wget http://repo.mysql.com/mysql-apt-config_0.8.13-1_all.deb 
sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb

In order to install MySQL 8.0, ignore above images and proceed with default settings.

Create a win32 dll in managed languages (Or call a .Net web service from VB6)

Note: This is the first ever post I’ve created in wordpress in 2008, I’m just keeping it for its archaeological value

Today I got a new challenge which seems impossible or I thought that is impossible. My employer asked me to create a win32 dll which is readable through a VB6 application and to make things more interesting he wanted to call a web service method through that. Anyway I first surf the web until I find enough resources about this topic and created a simple VB.NET project which is a class library. There I add a simple class. This should be public and must implement a public interface which defines all methods, getters and setters for your class. Then I select the com interop option in project properties, compile section. So when I compile the application it will generate a .tlb file wit the same name as your assembly.

Then to test the compatibility of my dll, I create a VB6 project and add the above mentioned .tlb file as a reference to the project. So now its done. I can create an object of the type of my C#.net class in a VB6 application and call its methods. Even if the dll has a reference to a web service, it works fine.

for more on this visit:
http://support.microsoft.com/kb/817248