Показаны сообщения с ярлыком php. Показать все сообщения
Показаны сообщения с ярлыком php. Показать все сообщения

понедельник, 9 ноября 2020 г.

PHP-FPM via command line

1. Install apt install libfcgi0ldbl

2. Install apt install html2text

3. Sh script

SCRIPT_FILENAME=/path/to/site/php_info.php \
REQUEST_URI=/ \
QUERY_STRING= \
REQUEST_METHOD=GET \
cgi-fcgi -bind -connect /run/php/php7.3-fpm.sock

4. script.sh | html2text

We will get phpinfo() function output through php-fpm, not through php-cli

четверг, 25 июня 2020 г.

PHP Xdebug multi php versions in the server , fixing xdebug.so: undefined symbol: zend_post_startup_cb

If you have many php versions in the server we might face Xdebug installing.
Firstly, I installed via manual as
install PECL, then install xdebug through pecl
As result, I got an error

xdebug.so: undefined symbol: zend_post_startup_cb

The default php version in the server is PHP 7.3 . I need to install Xdebug for PHP 7.2
I used those links
https://gist.github.com/amenk/29636622c60a420330a8b827d166f9cf
https://qna.habr.com/q/729423
https://xdebug.org/docs/install
The server is Debian. I installed php7.2-dev. We will use phpize and php-config from the package.
It is MATTER to use version as  phpize7.2 and php-config7.2
1) download
2) tar -xzf xdebug-2.9.6.tgz && cd xdebug-2.9.6
3) phpize7.2
4) ./configure --with-php-config=/usr/bin/php-config7.2
5) make
6) copy from modules folder to lib folder.
to check that lib folder via phpize7.2
7) add to available modules with 20 priority
PS: firstly, I used 10 priority and got error with IonCube. 20 priority helped
Then restart PHP service and enjoy

понедельник, 3 февраля 2020 г.

PHP Ioncube extension

It uses for encoding a code
1) Check an extension folder
php -i | grep extension_dir
2) download lib from https://www.ioncube.com/loaders.php site
3) make ini file in mods-available folder with
zend_extension = /usr/lib/php/20170718/ioncube_loader_lin_7.2.so
4) make symlinks to apache2 cli fpm folders
5) restart php, nginx, apache2

вторник, 21 января 2020 г.

Composer dump-autoload

Magento 2.3.3 Commerce
Useful links
https://phpprofi.ru/blogs/post/52
https://getcomposer.org/doc/03-cli.md#dump-autoload-dumpautoload-
https://magento.stackexchange.com/questions/284911/cant-run-any-commands-in-terminal/301796#301796

After

composer dump-autoload --optimize
php7.2 bin/magento setup:di:compile

throws error
Class Magento\Framework\App\ResourceConnection\Proxy does not exist

It works with composer dump-autoload
Also, I noticed if I run composer dump-autoload --optimize twice , second running was longer than first and compiling worked afterwards.

пятница, 13 декабря 2019 г.

Nginx php in subdirectory

Wordpress is in sub-directory nested, and blog address is domain.tld/nested

useful links
https://serversforhackers.com/c/nginx-php-in-subdirectory
https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/

server {
  listen 80 default_server; 
  listen [::]:80 default_server; 
  root /var/www/top/public; 
  index index.html index.htm index.php; 
  server_name _; 

  location / { 
    try_files $uri $uri/ /index.php$is_args$args; 
  } 

  location /nested { 
    alias /var/www/nested/public; 
    try_files $uri $uri/ @nested; 

    location ~ \.php$ { 
      index index.php;
      include snippets/fastcgi-php.conf; 
      fastcgi_param SCRIPT_FILENAME $request_filename; 
      fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; 
    } 
  } 
  location @nested { 
    rewrite /nested/(.*)$ /nested/index.php?/$1 last; 
  } 
  location ~ \.php$ { 
    include snippets/fastcgi-php.conf; 
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; 
  }
}

Short explanations.

1) root of blog is not domain as domain.tld, but it is address location as domain.tld/nested. So there should be rewrite rule:

    rewrite /nested/(.*)$ /nested/index.php?/$1 last;

2) We use alias, because of explanation from one of useful links below.
Note that distinction - with that alias, Nginx does NOT look for files within /var/www/nested/public/nested/foo, like it would with the root directive.

3) We use $request_filename instead of $document_root$fastcgi_script_name because of next explanation.
If you use the alias directive with $document_root$fastcgi_script_name, $document_root$fastcgi_script_name will return the wrong path.
Request /api/testing.php:
  • $document_root$fastcgi_script_name == /app/www//api/testing.php
  • $request_filename == /app/www/testing.php
Request /api/:
  • $document_root$fastcgi_script_name == /app/www//api/index.php
  • $request_filename == /app/www/index.php
4) And if you use $request_filename, you should set index using index directive, fastcgi_index will not work.
It means index index.php; in location

понедельник, 28 октября 2019 г.

Linux Ubuntu 18.04 Use redis for cache pages and PHP sessions storage

apt update -y && apt install redis-server php-redis

/etc/php/7.2/fpm/pool.d/user.conf
php_admin_value[session.save_handler] = redis
php_admin_value[session.save_path] = "tcp://127.0.0.1:6379?persistent=1&weight=1&database=2"

phpinfo should display redis info on the page.
There is link https://github.com/phpredis/phpredis#php-session-handler for save_path parameters

The checking script is 

<?php

  $redisinstance = new Redis();
  $redisinstance->connect("127.0.0.1", 6379);
  $result = $redisinstance->get("test");

  if ($result) {
      echo $result;
  } else {
      echo "No matching key found. Refresh the browser to add it!";
      $redisinstance->set("test", "Successfully retrieved the data!") or die("Couldn't save anything to redis...");
  }
?>
After refreshing page

redis-cli
127.0.0.1:6379> select 0
OK
127.0.0.1:6379> keys "*"
1) "test"
127.0.0.1:6379> get "test"
"Successfully retrieved the data!"

четверг, 24 октября 2019 г.

Linux Ububntu 18.04 Use memcached for PHP session storage

https://devdocs.magento.com/guides/v2.3/config-guide/memcache/memcache_ubuntu.html

apt update -y && apt install php-memcached memcached
/etc/php/7.2/fpm/php.ini
session.save_handler = "memcached"
session.save_path = "127.0.0.1:11211"

or /etc/php/7.2/fpm/pool.d/user.conf
php_admin_value[session.save_path] = '127.0.0.1:11211'
php_admin_value[session.save_handler] = 'memcached'

phpinfo should display memcached info on the page.

Check working with a script cache-test.php

PHP Nginx error "No input file specified." display on a page, and FastCGI sent in stderr: "Unable to open primary script: *.php (Operation not permitted)" in nginx log

/var/log/nginx/error.log

FastCGI sent in stderr: "Unable to open primary script: /var/www/html/phpinfo.php (Operation not permitted)

Don't forget to check open_basedir parameter

fastcgi_param PHP_ADMIN_VALUE   "open_basedir=/var/www/html/:/tmp/";

вторник, 2 июля 2019 г.

PHP Phpunit errors in pipeline

Куча разных ошибок в пайплайне
[InvalidArgumentException]
Project directory phpunit-6.5/ is not empty.

PHP Fatal error: Uncaught Error: Class 'Symfony\Bridge\PhpUnit\TextUI\Command' not found in

Failed to download sebastian/global-state from dist: No such zip file

среда, 26 июня 2019 г.

PHP Laravel add user

Задача добавить нового юзера в приложение

php artisan tinker

>>> DB::table('users')->insert(['name'=>'MyUsername','email'=>'thisis@myemail.com','password'=>Hash::make('123456')])

четверг, 30 мая 2019 г.

Linux PHP remove http header X-Powered-By

Для безопасности лучше удалить такие headers
До удаления
curl -I -L example.com
x-powered-by: PHP/7.2.18

Чтобы удалить, прописываем в
php.ini
expose_php = off
И reload php
После этого таких заголовков не наблюдаем

пятница, 26 апреля 2019 г.

Linux buster Zabbix Apache choose PHP version

После upgrade to buster вылезла проблема с zabbix. Он был установлен из официального репозитория. Но с ним возникла проблема с зависимостями
libcurl3 (>= 7.28.0)` but `libcurl4` in buster and `libevent-2.0-5` but `libevent-2.1-6
Но в репозиториях buster есть zabbix 4.0.4, поэтому переустановил оттуда.
Фронтенд (на apache2) пришлось также переустанавливать через remove и install. Но версия php обновилась тоже и было теперь две версии php 7.0 и 7.3, причем php-mysql . Нужно было поменять ее для apache. Это делается через
a2dismod php7.0
a2enmod php7.3
systemctl restart apache2

суббота, 2 марта 2019 г.

Linux phpmyadmin nginx config

с git репозитория
1) git clone https://github.com/phpmyadmin/phpmyadmin.git
2) composer update --no-dev
3) yarn install

релиз с сайта
1a) просто скачать zip архив с сайта
4) permissions www-data:www-data, nginx config

server
{
    listen <IP>;
    server_name phpmyadmin.server.tld;

    root /var/www/phpmyadmin;

    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ ^/(.+\.php)$
    {
        try_files $uri = 404;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_index index.php;
    }

    error_log /var/log/nginx/phpmyadmin_error.log;
    access_log /var/log/nginx/phpmyadmin_access.log;
}