Tuesday, April 16, 2024

INSTALL PHP USING COMMAND LINE TOOL FOR WINDOWS

You need to run this in powershell (Admin)

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco upgrade chocolatey 

 

choco install php 

you can specify version

choco install php --version=7.4.1 

 


last step is to update windows environment, to do that you need to run these codes.

  1. Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"

  1. Update-SessionEnvironment
php -v



And your done! :)

Sunday, June 25, 2023

Switch php version command line inside vagrant homestead

 If you want to switch the PHP version in the command line of your Homestead Vagrant box, you can follow these steps:


1. SSH into your Homestead Vagrant box by running the following command from your project's root directory:

   ```

   vagrant ssh

   ```


2. Once you are inside the Vagrant box, you can use the `update-alternatives` command to switch the PHP version. Run the following command to see the available PHP versions:

   ```

   sudo update-alternatives --config php

   ```


3. The command will display a list of available PHP versions installed on your system. Each version will have a corresponding number associated with it. Enter the number of the PHP version you want to switch to and press Enter.


4. After selecting the PHP version, it will be set as the default version for the command line.


5. To verify the PHP version, you can run the following command:

   ```

   php -v

   ```


That's it! You have now switched the PHP version in the command line of your Homestead Vagrant box. The selected PHP version will be used for any subsequent PHP command you run from the command line.

Tuesday, March 28, 2023

RUN LINUX COMMAND IN VAGRANT HOMESTEAD @ START UP

I got error on my application when starting up the homestead, to fix this, I need to vagrant ssh and run a linux command. This method works with me

Edit your VagrantFile, replace the command in `inline`
go to the bottom line of the file and copy paste the command


Vagrant.configure("2") do |config|
  config.vm.provision "shell", run: "always", inline: "service nginx restart"
end

Tuesday, March 14, 2023

HOW TO SET GIT BASH AS THE DEFAULT TERMINAL IN YOUR VISUAL STUDIO CODE

 


This simple steps works on me

  • press down CTRL + SHIFT + P and then type in “select default profile“.
  • The drop-down includes every shell that is installed in your system that VS Code was able to detect.
  • Now simply select Git Bash and open up a new terminal window by pressing down CTRL + SHIFT + ~ (tilde) to check if Git Bash opens up as the default terminal.

Friday, March 3, 2023

HOW TO CREATE AN IMAGE IN PORTAINER FOR PHP8 AND APACHE TO RUN A WEB APPLICATION

Go to Image and build a New Image


Give it a name

and put this value in Web Editor portion

FROM php:8.0-apache
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
RUN apt-get update
RUN apt-get install -y \
    git \
    zip \
    curl \
    sudo \
    unzip \
    libicu-dev \
    libbz2-dev \
    libpng-dev \
    libjpeg-dev \
    libmcrypt-dev \
    libreadline-dev \
    libfreetype6-dev \
    g++

RUN docker-php-ext-install \
    bz2 \
    intl \
    bcmath \
    opcache \
    calendar \
    pdo_mysql \
    mysqli \
    gd

# 2. set up document root for apache
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf

# 3. mod_rewrite for URL rewrite and mod_headers for .htaccess extra headers like Access-Control-Allow-Origin-
RUN a2enmod rewrite headers

# 4. start with base php config, then add extensions
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

# 5. Composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
RUN chmod +x /usr/local/bin/composer
RUN composer self-update


ARG phpver=8
ARG git_repo="https://gitlab+deploy-token-1823228:tRSTqEaK7dviW47zXd_zw@gitlab.com/repoAccount/repo.git"
ARG webapppath="/var/www/html/your-foldername"
ARG max_execution_time
ARG max_input_time
ARG max_input_vars
ARG memory_limit
ARG post_max_size
ARG upload_max_filesize
ARG session_maxlifetime

#Clone source code
RUN git clone $git_repo $webapppath -b develop

RUN chmod -R 755 $webapppath/writable/ 
Run chown -R www-data:www-data $webapppath/writable/ 

RUN composer update --working-dir=$webapppath

RUN cp $webapppath/env $webapppath/.env

ARG uid=1000
ENV UID=$uid

RUN useradd -G www-data,root -u $UID -d /home/devuser devuser
RUN mkdir -p /home/devuser/.composer && \
    chown -R devuser:devuser /home/devuser

EXPOSE 80

===================================

Create 000-default.conf and change the value of your-foldername and upload it to Select Files button




then Build Image

  • For webapppath = edit this to your exact foldername

  • Note for ARG git_repo , if you are using gitlab. You may need to create a deploy token of your repository in able to download or clone your repository even without inputting any credential. You may check the gitlab documentation on how to create deploy token.

DONE!!
(you may now create your stack for this image for any modification, stack will create your container!)






Wednesday, March 1, 2023

502 BAD GATEWAY ERROR WHILE INSTALLING VAGRANT BOX TO RUN A LARAVEL PROJECT with 7.4 PHP

 To fix this what I did is.


go to your Homestead folder

run: vagrant ssh

type: sudo passwd root

type what password you want for root

then type: su

run the ff. commands

sudo systemctl enable php7.4-fpm
sudo service php7.4-fpm restart

Done!


Tuesday, February 21, 2023

HOW TO CREATE A NEW INSTANCE PHPMYADMIN IN DOCKER, DIRECTLY TO YOUR CLOUD SERVER

You can use this whenever you want another instance of phpmyadmin connected to your cloud mysql server

docker run --name phpmyadminContainerName -d -e PMA_HOST=[hostname] -e PMA_USER=[user] -e PMA_PASSWORD=[password] -p 8088:80 phpmyadmin/phpmyadmin

Replace [YOUR_HOSTNAME], [YOUR_USERNAME], and [YOUR_PASSWORD] with your own values. This command will start the phpMyAdmin container in the background and expose it on port 8088 of your local machine. You can access phpMyAdmin by opening a web browser and navigating to http://localhost:8088.

Monday, February 20, 2023

INSTALL MYSQL with PHPMYADMIN in DOCKER (Windows)

1. Install docker for windows https://docs.docker.com/desktop/install/windows-install/

2. After installation, start docker daemon by simply open the docker program.

3. Open any terminal and create docker network.

docker network create docker-network

4. Install mysql using the command below:

docker run --name mysql --network docker-network -p 3306:3306 -v mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=secret -d mysql

5. Install phpmyadmin using the command below:

docker run --name phpmyadmin --network docker-network -d --link mysql:db -p 8888:80 phpmyadmin


Congratulation! You may now access your mysql server using phpmyadmin @ http://localhost:8888


Friday, October 21, 2016

Installing LARAVEL 5.3 in windows

Server Requirements
  • PHP >= 5.6.4
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension
Installing via Composer

download and install https://getcomposer.org/download/

then go to your command line /cmd and type

composer global require "laravel/installer"

Go to your htdocs and create a project by typing

composer create-project --prefer-dist laravel/laravel blog

type this to run the local server of your laravel application

php artisan serve

now go to http://localhost:8000

Done! You may now proceed to configure your app.

Tuesday, September 13, 2016

how to install TWRP (team win recovery pro) to your MI3

download the following files.

https://dl.twrp.me/cancro/twrp-3.0.2-0-cancro.img.html (twrp.img)

https://androiddatahost.com/265a2 (tools to flash via fastboot)

Extract minimal_adb_fastboot_v1.3.1.zip and install

after that copy twrp-3.0.2-0-cancro in the folder location where adb installed and rename it as twrp.img 

usually C:\Program Files (x86)\Minimal ADB and Fastboot

go to fastboot mode of your MI3 phone, press power and volume down

if you see the logo of android connect your phone into your computer.

go to C:\Program Files (x86)\Minimal ADB and Fastboot click shift + right click and click "Open command window here"

Type 
fastboot devices
if you see device appear the computer successfully see your device.

then type
fastboot flash recovery twrp.img


done! go to your recovery mode.

Thursday, February 11, 2016

Get the dates inside the two date in PHP (YYYY-MM-DD)

<?php
function createDateRangeArray($strDateFrom,$strDateTo)
{
    // takes two dates formatted as YYYY-MM-DD and creates an
    // inclusive array of the dates between the from and to dates.

    // could test validity of dates here but I'm already doing
    // that in the main script

    $aryRange=array();

    $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2),     substr($strDateFrom,8,2),substr($strDateFrom,0,4));
    $iDateTo=mktime(1,0,0,substr($strDateTo,5,2),     substr($strDateTo,8,2),substr($strDateTo,0,4));

    if ($iDateTo>=$iDateFrom)
    {
        array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
        while ($iDateFrom<$iDateTo)
        {
            $iDateFrom+=86400; // add 24 hours
            array_push($aryRange,date('Y-m-d',$iDateFrom));
        }
    }
    return $aryRange;
}
$array = createDateRangeArray('2015-01-01','2015-01-10');
foreach($array as $dates){
    echo "'".$dates."'";
    echo "<br>";
}

?>


Sample output:
'2015-01-01'
'2015-01-02'
'2015-01-03'
'2015-01-04'
'2015-01-05'
'2015-01-06'
'2015-01-07'
'2015-01-08'
'2015-01-09'
'2015-01-10'
 

Thursday, February 4, 2016

Installing FFMPEG in CENTOS & ffmpeg-php

# vi /etc/yum.repos.d/dag.repo

click INSERT key and add this line:

[dag]
name=DAG RPM Repository
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1


save it! :wq!

# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
# yum update
# yum install ffmpeg ffmpeg-devel ffmpeg-libpostproc

# ffmpeg

 

done installing ffmpeg.

All we need to do is to install ffmpeg-php

# yum install php-gd php-devel 
1. Download the ffmpeg-php
2. Extract the archive:
# tar -xjf ffmpeg-php-X.x.x.tbz2
# cd ffmpeg-php-X.x.x/
# phpize
# ./configure
# make
# make install
# echo 'extension=ffmpeg.so' >> /etc/php.ini

now restart your httpd
# service httpd restart
 
now check your phpinfo and search ffmpeg.


 

Done, You can now use ffmpeg in your php application.

:) enjoy !



Installing DJANGO in CentOS release 6.7 (Final)

You need internet connection in your server.

# cd /opt/
# wget http://mirrors.nl.eu.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -Uvh epel-release-6-8.noarch.rpm

# rm epel-release-6-8.noarch.rpm -f

Now install python but most of CENTOS has installed python by default
# yum install python
# yum install Django

Now this is how to check the version after you successfully installed it.

# python
>>> import django
>>> print djnago.get_version()

You may now create a project
# django-admin startproject mysite
# cd mysite/

# python manage.py runserver

by default this will run in port 8000
If you want to run in other port and by IP you may type this.

# python manage.py runserver 192.168.1.85:8001

 

Done! :)

How to kill all processes via grep in once (CENTOS)

Run this command.

sample process is the httpd

# ps aux | grep 'httpd' | grep -v grep | awk '{print $2}'

This will output all process ID only.

Then run this to kill all processes.


# kill -9 `ps aux | grep 'httpd' | grep -v grep | awk '{print $2}'`

Done.