Category Archives: PHP

[Solved] PHP Error: always_populate_raw_post_data = -1

Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set ‘always_populate_raw_post_data’ to ‘-1’ in php.ini and use the php://input stream instead. in Unknown on line 0

Warning: Cannot modify header information – headers already sent in Unknown on line 0

Solution: Under php.ini file: turn on always_populate_raw_post_data = -1 and then save and restart

Reason: Once enabled, you can receive data with $HTTP_RAW_POST_DATA, but usually we use php://input

How to Solve Phpize Run Error: Cannot find config.m4

Step1: phpize run error

[root@gadmobe ~]# /usr/local/php-fpm/bin/phpize

Cannot find config.m4. 
Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module

Step2: done!

#Go to the php source code directory
cd /usr/local/src/php-5.6.30/ext/

#Execution
./ext_skel --extname=my_module 


#goto my_module
cd /usr/local/src/php-5.6.30/ext/my_module

#edit
vim config.m4 

#
dnl PHP_ARG_WITH(my_module, for my_module support, 
dnl Make sure that the comment is aligned: 
dnl [ --with-my_module Include my_module support]) 

#modify to
PHP_ARG_WITH(my_module, for my_module support, 
Make sure that the comment is aligned: 
[ --with-my_module Include my_module support]) 


vim /usr/local/src/php-5.6.30/ext/my_module.c

#
/* {{{ my_module_functions[]
 *
 * Every user visible function must have an entry in my_module_functions[].
 */
const zend_function_entry my_module_functions[] = {
        PHP_FE(confirm_my_module_compiled,      NULL)           /* For testing, remove later. */
        PHP_FE_END      /* Must be the last line in my_module_functions[] */
};


#modify to
/* {{{ my_module_functions[]
 *
 * Every user visible function must have an entry in my_module_functions[].
 */
const zend_function_entry my_module_functions[] = {
PHP_FE(say_hello,    NULL) /* ?Add a line of code */
    PHP_FE(confirm_my_module_compiled,   NULL) /* For testing, remove later. */
    {NULL, NULL, NULL}   /* Must be the last line in my_module_functions[] */
};

[Solved] Fatal error: Call to undefined function json_decode()

Recently, we set up a test server and visited the website to check the error log. The following errors occurred:

Fatal error: Call to undefined function json_ decode()

The reason for this problem is that the JSON extension was not installed when PHP was installed

1. First, enter the JSON directory in Ext of PHP installation package, as shown in the following figure:

2. Execute phpize, as shown in the figure below:

3. Compile configuration, as shown in the figure below:

4. Install the extension, as shown in the figure below:

5. After successful installation, you can see the json.so extension, as shown in the following figure:

6. Finally, add extension = json.so to the php.ini configuration file, as shown in the following figure:

7. Finally, restart PHP FPM to see the extension loading

[Solved] Php5.6.30 environment error call to undefined function imagecreate() compile and install GD Library

php5.6.30 environment reports error Call to undefined function ImageCreate() compile and install gd library


Found that php5.6.30 does not load the gd library

[root@cn_vs_web04:/usr/local/php]# php -i |grep configure
Configure Command =>  './configure'  '--prefix=/usr/local/php-5.6.30_fpm' '--with-openssl=/usr/local/lab/openssl' '--with-libxml-dir=/usr' '--with-zlib-dir=/usr/local/lab/zlib-1.2.8' '--with-bz2' '--enable-calendar' '--with-curl=/usr/local/lab/curl-7.36.0' '--enable-dba' '--enable-exif' '--enable-ftp' '--with-jpeg-dir=/usr/local/lab/libjpeg-6b' '--with-png-dir=/usr/local/lab/libpng-1.6.10' '--with-freetype-dir=/usr/local/lab/freetype-2.5.4' '--with-gettext' '--enable-mbstring' '--with-ldap=/usr/local/openldap-2.4.23' '--with-mcrypt=/usr/local/lab/libmcrypt-2.5.8' '--with-mhash=/usr/local/lab/mhash-0.9.9.9' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-unixODBC=/usr/local/lab/unixODBC-2.3.2' '--with-pdo-dblib=/usr/local/lab/freetds-0.92' '--enable-zip' '--with-iconv-dir=/usr/local/lab/libiconv-1.14' '--with-fpm-user=apache' '--with-fpm-group=users' '--enable-fpm' '--with-xmlrpc' '--enable-soap' '--enable-mbregex' '--enable-opcache' '--enable-inline-optimization' '--enable-xml' '--enable-sockets' '--disable-debug

Solution:

The gd library was not compiled in during compilation, so it needs to be added again. Fortunately, the gd library is an extension library, so there is no need to recompile the whole php program.

1. Download php5.6.30 source code


Get the source code and decompress it
# wget https://www.php.net/distributions/php-5.6.30.tar.gz
# tar -zxf php-5.6.30.tar.gz
# cd php-5.6.30/ext/gd

Execute phpize in the source code directory
# /usr/local/php/bin/phpize

# Recompile
# ./configure --with-php-config=/usr/local/php/bin/php-config --with-gd
# make && make install

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php-5.6.30_fpm/lib/php/extensions/no-debug-non-zts-20131226/
Installing header files:           /usr/local/php-5.6.30_fpm/include/php/

# Add the extensions library to the extensions folder

cp /usr/local/php-5.6.30_fpm/lib/php/extensions/no-debug-non-zts-20131226/ /usr/local/php/lib/php/extensions

Edit php.ini to add the gd.so extension library

# vim /usr/local/php/php.ini
extension_dir=/usr/local/php/lib/php/extensions
extension=gd.so

# restart php
/etc/init.d/php-fpm restart

# Validation
[root@cn_vs_web04:/usr/local/lab]# php -m|grep gd
gd


[root@cn_vs_web04:/usr/local/lab]# cat /etc/init.d/php-fpm 
#! /bin/sh

### BEGIN INIT INFO
# Provides:          php-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO

prefix=/usr/local/php
exec_prefix=${prefix}

php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid


php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"


wait_for_pid () {
    try=0

    while test $try -lt 35 ; do

        case "$1" in
            'created')
            if [ -f "$2" ] ; then
                try=''
                break
            fi
            ;;

            'removed')
            if [ ! -f "$2" ] ; then
                try=''
                break
            fi
            ;;
        esac

        echo -n .
        try=`expr $try + 1`
        sleep 1

    done

}

case "$1" in
    start)
        echo -n "Starting php-fpm "

        $php_fpm_BIN --daemonize $php_opts

        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        fi

        wait_for_pid created $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;

    stop)
        echo -n "Gracefully shutting down php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -QUIT `cat $php_fpm_PID`

        wait_for_pid removed $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed. Use force-quit"
            exit 1
        else
            echo " done"
        fi
    ;;

    force-quit)
        echo -n "Terminating php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -TERM `cat $php_fpm_PID`

        wait_for_pid removed $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;

    restart)
        $0 stop
        $0 start
    ;;

    reload)

        echo -n "Reload service php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -USR2 `cat $php_fpm_PID`

        echo " done"
    ;;

    *)
        echo "Usage: $0 {start|stop|force-quit|restart|reload}"
        exit 1
    ;;

esac

[Solved] PHP7 configure: error: Cannot find OpenSSL’s

At first I thought it was because openssl and openssl-devel were not installed, but I found this error after installation. I searched for evp.h, and this file also exists. I googled it and found the answer on stackoverflow. It turned out that there was a problem with the configure script generated by phpize.

Solution: modify the configure file to add

This is an error when installing the mysqlnd extension

export PHP_OPENSSL_DIR = yes
  ./configure --with-php-config=/home/php/bin/php-config --enable-mysqlnd

 

[Solved] PHP Fatal error: Class ‘mysqli’ not found in xxx

Fatal error: class’ mysqli ‘not found in xxx

The error indicates that PHP lacks mysqli extension. You can check the PHP compilation parameters first to confirm/usr/local/PHP5/bin/php-i|grepconfigure

Attached are other common software queries:

nginx:/usr/local/nginx/sbin/nginx-V

apache :cat/usr/local/apache/build/config.nice

mysql:cat/usr/local/mysql/bin/mysqlbug|grepconfigure

It’s true that we didn’t enter the source code package ext/mysqli later

Linux installation is compiled with configuration, but it disappears after we have installed PHP. There is a file called phpize in the command directory bin of PHP5 folder, which can be used to generate configuration

/Usr/local/PHP5/bin/phpize// enter here to run. After execution, the configure file appears

Now add the extension mysqli

./configure –prefix=/usr/local/mysqli –with-php-config=/usr/local/php5/bin/php-config –with-mysqli=/usr/local/mysql/bin/mysql_ config

make && amp; make test && amp; make install

After compilation:

Thank you for helping to make PHP better.
Installing shared extensions: /usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/
Installing header files: /usr/local/php5/include/php/

The description is normal

Now mysqli. So appears

Modify php.ini file

extension_ Dir = “/ usr/local/PHP5/ext”
extension = mysqli. So new

I found that there are two PHP directories, which may be due to problems in the previous compilation, and both generated php.ini files. I found that they need to be modified to add the last two sentences to run normally

Finally, the generated mysqli.so file CP is put under/usr/local/PHP5/ext

Restart PHP FPM to complete the program

If you feel troublesome, you can directly delete the PHP file of compilation and installation, and the installation directory and configuration file can be recompiled and installed

If you have other questions, you can reply and learn together

Fatal error: class’ mysqli ‘not found in

/login/login_ action.html” method=”post” onSubmit=”return checkform(‘false’)”>

The php.ini file does not recognize the form and needs to be modified

Found

short_ open_ Change tag = on to on

Nginx+PHP FastCGI sent in stderr: “Primary script unknown” while reading response head…

When deploying ZABBIX’s LNMP environment, the test PHP page can’t be opened. Check the error log of nginx and report an error fastcgi send in stderr: “primary script unknown” while reading response header from upstream

1. Online query has modified nginx. Conf, as follows

fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
to
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

Then execute service nginx reload or service nginx restart or enter/etc/init.d/nginx restart

The author is to modify the above configuration to solve the problem

2. Some say that user and group in PHP FPM do not specify nginx as their user( My configuration has been specified in advance, so rule out this reason. Students without configuration can try.)

edit php-fpm
vi /usr/local/php/etc/php-fpm.conf

line 149

[Solved] PHP write file permission failure: file_put_contents: failed to open stream: Permission denied

Questions

File is used in the method of writing log_ put_ Content this method, when executing the callback method to write the log today, prompts that there is no permission to write to the file, and reports an error

file_put_contents: failed to open stream: Permission denied

Solution process

Check the log folder permissions. Because it is generated on a daily basis, a scheduled task is executed on a regular basis, and the executing user is root. Therefore, both the generating folder user and the user group are root. In the callback method, the executing user is WWW, which is written to the log method

  if(!is_dir($dir)){
        mkdir($dir,0777,true);
    }

If the directory doesn’t exist, create a directory, but set 777 permission to create a folder in PHP’s MKDIR function. In fact, the created file still has 755 permission. In Linux system, there is a default permission when creating files/folders. This permission is affected by umask settings. We can find the following configuration in/etc/bashrc configuration file:

if [ $UID -gt 99 ] && [ "`id -gn`" = "`id -un`" ]; then
        umask 002
else
        umask 022
fi

The default umask in Linux system is 022, which is similar to our 777 & amp; After the operation, it becomes 755. That’s why. The setting here directly affects the default permission setting of Linux system, not just the problem of PHP. Therefore, it is not recommended to change 022 to 000 directly

Final solution

First create a directory, and then use Chmod to modify the permission to 777

mkdir('test', 0777);
chmod('test', 0777);

[How to Fix] file_put_contents failed to open stream

The following error occurred at runtime:

ErrorExceptioninFilesystem.php line 81:file_ put_ contents(/var/www/mysite/bootstrap/cache/services.json): failed to open stream: Permission denied

 

It can be seen from the above error that the cache directory does not have write permission, so write permission to this directory:

solution:

#sudochmod-R777/var/www/mysite/bootstrap/cache

The difference between permissions 777 and 755:

777 is that all users have execute, read and write permissions, 755 is that root can execute permissions. The user of the file and other group users do not have execute permissions