Tag Archives: php

remi php missing /usr/bin/php56


php
-bash: php: command not found
source /opt/remi/php56/enable
echo "source /opt/remi/php56/enable" | tee -a /root/.bashrc

php -v
PHP 5.6.40 (cli) (built: Sep 29 2020 11:31:13)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

cat /opt/remi/php56/enable
export PATH=/opt/remi/php56/root/usr/bin:/opt/remi/php56/root/usr/sbin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/remi/php56/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/remi/php56/root/usr/share/man:${MANPATH}
v1.diavolesa.lt:~$ cat /opt/remi/php56/enable
export PATH=/opt/remi/php56/root/usr/bin:/opt/remi/php56/root/usr/sbin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/remi/php56/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/remi/php56/root/usr/share/man:${MANPATH}

pecl another php version

pecl multiple php version
pecl install mcrypt
pecl/mcrypt is already installed and is the same as the released version 1.0.3
install failed

update-alternatives –config=php
update-alternatives –config=php-config
update-alternatives –config=phpize

pecl install -f pecl

Also can help config-set:
pecl config-set ext_dir /usr/lib/php/20201226
pecl config-set php_bin /usr/bin/php7.4
pecl config-set php_ini /etc/php/7.4/cli/php.ini
pear config-set ext_dir /usr/lib/php/20201226
pear config-set php_bin /usr/bin/php7.4

nginx allow only index.php

upstream _php {
server unix:/var/run/php-fpm/php-fpm.sock;
}

server {
server_name 192.168.1.100;

root /path/to/root;
index index.php;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
location / { deny all; }
location = / { }
location = /index.php { fastcgi_pass _php; }

location /phpmyadmin/ { }
location ~ ^/phpmyadmin/.*\.php$ { fastcgi_pass _php; }
}

nohup style php


$lock = fopen('/path/to/pid', 'c+');
if (!flock($lock, LOCK_EX | LOCK_NB)) {
die('already running');
}

switch ($pid = pcntl_fork()) {
case -1:
die('unable to fork');
case 0: // this is the child process
break;
default: // otherwise this is the parent process
fseek($lock, 0);
ftruncate($lock, 0);
fwrite($lock, $pid);
fflush($lock);
exit;
}

if (posix_setsid() === -1) {
die('could not setsid');
}

fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);

$stdIn = fopen('/dev/null', 'r'); // set fd/0
$stdOut = fopen('/dev/null', 'w'); // set fd/1
$stdErr = fopen('php://stdout', 'w'); // a hack to duplicate fd/1 to 2

pcntl_signal(SIGTSTP, SIG_IGN);
pcntl_signal(SIGTTOU, SIG_IGN);
pcntl_signal(SIGTTIN, SIG_IGN);
pcntl_signal(SIGHUP, SIG_IGN);

// do some staff

// to kill the proccess
$lock = fopen(‘/path/to/pid’, ‘c+’);
if (flock($lock, LOCK_EX | LOCK_NB)) {
die(‘process not running’);
}
$pid = fgets($lock);

posix_kill($pid, SIGTERM);

ubuntu php 7.3

LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
apt update
apt install php7.3 php7.3-cli php7.3-common

php -v
PHP 7.3.20-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jul 9 2020 16:33:48) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.20, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.20-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

laravel hacked database

Its serious security issue this default Laravel configuration. because .env file and database credentials are not protected. So you need to create a .htaccess file in same folder to protect it:

<Files .env>
order allow,deny
Deny from all
</Files>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>