Classified directory archiving: PHP

PHP 7.3 configure: error: Please reinstall the libzip distribution

Q: Problem description: configure: error: Please reinstall the libzip distribution
Problem solving:
 $ yum remove -y libzip
$ wget -P /mnt/renwolecom //nih.at/libzip/libzip-1.2.0.tar.gz
$ tar -zxvf libzip-1.2.0.tar.gz
$ cd libzip-1.2.0
$ ./ configure
$ make && make install

Q: Problem description: configure: error: off_t undefined; check your library configuration
Problem solving:

 $ echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf
$ ldconfig -v

Q: Problem description:/usr/local/include/zip. h: 59:21: fatal error: zipconf. h: No such file or die
Problem solving:

 $ cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf. h

The operation environment is normal. The DedeCMS verification code cannot be displayed

When the environment is OK, the DedeCMS verification code cannot be displayed.

Solution 1:

stay include Open under directory vdimgck.php Files, finding if(function_exists(“imagejpeg”)) Add above ob_clean(); Problem solving.

This problem is very strange. Sometimes it's OK if you don't add it. Of course, my problem is that if you add it to the problem, it's OK. It's OK before, but suddenly it's not OK.

The specific codes added are as follows:

 ob_clean(); if(function_exists(“imagejpeg”)) { header(“content-type:image/jpeg\r\n”); imagejpeg($im); } else { header(“content-type:image/png\r\n”); imagepng($im); }

Solution 2:

Cancel the background login verification code of Dream Weaving.

The specific operations are as follows:

The following files were found:

 /data/safe/inc_safe_config.php

Find in this file $safe_gdopen = ’1,2,3,5,6,7′; delete six Number to cancel the verification code function.

Apache Nginx prohibits directory execution of PHP script files

When building a website, we may need to set permissions on some directories separately to achieve the security effect we need. The following example shows how to set a directory under Apache or Nginx to prohibit the execution of php files.

1. Apache configuration

 <Directory /apps/web/renwole/wp-content/uploads> php_flag engine off </Directory> <Directory ~ "^/apps/web/renwole/wp-content/uploads"> <Files ~ ".php"> Order allow,deny Deny from all </Files> </Directory>

2. Nginx configuration

 location /wp-content/uploads { location ~ .*\. (php)?$  { deny all; } }

Nginx prohibits multiple directories from executing PHP:

 location ~* ^/(css|uploads)/.*\. (php)${ deny all; }

After the configuration is completed, reload the configuration file or restart the Apache or Nginx service. After that, all php files accessed through uploads will return 403, greatly increasing the security of the web directory.

Redis Cache PHP 7.2 Session Variable Sharing

Generally, there are two forms of load balancing content, one is static, the other is dynamic. Dynamic website content may need to interact, so session sharing is involved. By default, PHP stores sessions on LocalDisk. If multiple PHP hosts load, how can they share sessions? Today we will solve this problem.

There are many ways for session sessions to share files:

Distributed file sharing; NFS, NAS file storage, etc.
Nginx load balancing ip_hash module, which fixes visitors to a back-end server.
Store the session in the database; For example, MySQL, Memcached, Redis, Mongodb, etc.

Personally, I prefer to store the session to the Redis database. Synchronizing the session sharing in this way will not increase the burden on the database, and the security is higher than that of cookies. Putting the session into memory will be much faster than reading from disk files. "Some people think that if I install all the cache software, the speed will be faster. It will not be the cache acceleration, but the cache library.".

PHP language script does not support operations on Redis by default, so you need to install a third-party phpRedis extension module to enable it to support operations on Redis. For how to install and use phpRedis, please refer to the article I wrote earlier《 Install, configure and use the phpRedis extension module 》。 In addition, a Redis server is needed here. See《 Linux Centos7 Redis 3.2.9 Source Compilation, Installation and Configuration 》。

1. Modify the PHP configuration file php.ini to store the session in Redis.

 # vim /usr/local/php/etc/php.ini session.save_handler = files ; session.save_path = "N;/path"

Revised as:

 session.save_handler = Redis session.save_path = “ tcp://10.10.204.66:6379  ; If Redis has a password connection session.save_path = “ tcp://10.10.204.66:6379?auth=password 

 

2. Restart the php fpm service to take effect

 # systemctl restart php-fpm

All the above processes are manually tested and 99% can be used for production.

Install, configure and use the phpRedis extension module

What is phpRedis? The phpredis extension provides an API for communicating with Redis key value storage. If you need to use Redis related functions, you must install the phpRedis extension package. It seems very complicated, but actually it is not so difficult to operate by hand.

Environmental Science:

CentOS Linux release 7.3.1611 (Core) x64
Redis server v=3.2.9 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=37db043e44b54a88

1. Download the phpRedis extension and unzip it. Download address:

 //pecl.php.net/package/redis # cd /tmp # wget //github.com/phpredis/phpredis/archive/develop.zip# unzip develop.zip # cd phpredis-develop/

2. Next, compile the phpize extension tool in the phpredis development directory, which is mainly used to generate the configure file in the phpredis development directory.

 

 # /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20160303 Zend Module Api No: 20160303 Zend Extension Api No: 320160303 # ./ configure --with-php-config=/usr/local/php/ # make && make install ... Build complete. Don't forget to run 'make test'. Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20160303/

The last line is the path of the compiled Redis dynamic library:/usr/local/php/lib/php/extensions/no debug zts-20160303/

3. Modify php.ini to add Redis.so path at the bottom of the file, and then restart nginx/php fpm service to take effect.

 # vim /usr/local/php/etc/php.ini extension="/usr/local/php/lib/php/extensions/no-debug-zts-20160303/redis.so" # systemctl restart nginx # systemctl restart php-fpm

4. Whether the installation of phpRedis is successful can be tested through the PHP probe.

 <? phpinfo();?>

Save the above code as phpinfo.php and upload it to the root directory of the website for access. You can view the support of the Redis&Session extension module.

redis
Redis Support enabled

Redis Version 3.1.2

Available serializers php

session
Session Support enabled

Registered save handlers   files user redis rediscluster

Registered serializer handlers php_serialize php php_binary

So far, the installation and configuration of phpRedis has been completed. I hope it will be helpful to you.

Windows server 2003&iis6&PHP5.3&Zend&FastCGI installation configuration

1. Related software download

//Windows. php. net/downloads/releases/archives/Download the required php version
//Www.iis.net/downloads/microsoft/fastcgi-for-iis Download FastCGI components
//Www.zend. com/en/products/loader/downloads # Windows download required ZEND version
Microsoft Visual C++2008 Redistributable Package x86 (default installation)

FastCGI is installed by default. The downloaded php is unzipped to the E disk and named as the PHP folder. The default permissions are given to the php directory users.

2. FastCGI Configuration

Add parameters to the last line of the FastCGI configuration file;

 C:\WINDOWS\system32\inetsrv\fcgiext.ini [Types] php=PHP [PHP] ExePath=E:\PHP\php-cgi.exe InstanceMaxRequests=10000 EnvironmentVars=PHP_FCGI_MAX_REQUESTS:10000 ActivityTimeout=3600 RequestTimeout=3600

Add system environment variables:

My Computer ->Properties ->Advanced ->Environment Variables ->System Variables, add in the last side of Path; E:\PHP\
3. php.ini Configuration

Rename E: php php. ini development to php. ini, and enable PHP related parameters
Create a new E: PHP tmp directory in the php directory and give cache users write permission.

 short_open_tag = On upload_tmp_dir="E:\PHP\tmp" cgi.force_redirect=0 fastcgi.impersonate=1; extension_dir="E:\PHP\ext" date.timezone =PRC ; Or Asia/Shanghai extension=php_curl.dll extension=php_gd2.dll extension=php_ldap.dll extension=php_mbstring.dll extension=php_exif.dll extension=php_mysql.dll extension=php_mysqli.dll extension=php_sockets.dll extension=php_xmlrpc.dll

4. iis6.0 Configuration

IIS extension adding, open iis - website - property - home directory - configuration - application extension - add, the executable file is below;

C:\WINDOWS\system32\inetsrv\fcgiext.dll

Extension; PHP

Other Defaults
5. Zend Installation Configuration
Put the DLL file of the php version corresponding to the extracted zend package into the E: php ext directory, and then add the following zend configuration parameters in the last line of php.ini;

 [ZendGuardLoader] zend_loader.enable=1 zend_loader.disable_licensing=1 zend_loader.obfuscation_level_support=3 zend_loader.license_path= zend_extension="E:\php\ext\ZendLoader.dll"

6. Restart iis, create a new site in iis, and write a php probe to test whether it succeeds

Create a new ordinary txt file, copy the following content to the txt file, and name it php. php (pay attention to the extension);

 <? phpinfo(); ?>

Successful access will display php related information and version.

Smooth and seamless upgrade of PHP 7.1.0 to PHP 7.1.5 for Linux Centos7

I am a person who likes new technology. Once something new appears or is released, I will research it and finally use it in production. New things have both advantages and disadvantages. The new version of PHP has many features, and there are also unknown bugs. Therefore, you should be careful whether you use it for learning or production. However, since the stable version has been released, you may as well try it.

Experimental environment: CentOS Linux release 7.3.1611 (Core)
Kernel version: Linux version 3.10.0-514.el7.x86_64

1. There are two ways to view the php version, and the display results are the same.

First

# /usr/local/php/bin/php -v

Second

# php  -v

PHP 7.1.0 (cli) (built: Dec 17 2016 17:00:32) ( ZTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.1.0, Copyright (c) 1999-2016, by Zend Technologies

2. Before upgrading, you need to find the previous configuration module information to ensure that it is consistent before and after upgrading, otherwise normal access to the website may be affected. If you do not remember the previous configuration information, you can write a phpinfo probe to find it, or use the following command:;

 # php -i | grep configure Configure Command => './ configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--with-fpm-user=www' '--with-fpm-group=www' '--with-iconv-dir' '--with-freetype-dir' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimiza tion' '--with-curl' '--enable-mbregex' '--enable-fpm' '--enable-mbstring' '--with-mcrypt' '--with-gd' '--enable-gd-jis-conv' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--enable-opcache' '--with-libmbfl' '--with-onig' '--enable-pdo' '--with-mysqli=mysq lnd' '--with-pdo-mysql=mysqlnd' '--with-pdo-mysql' '--enable-mysqlnd-compression-support' '--with-pear' '--enable-maintainer-zts' '--enable-session' '--with-gettext'

After the above information is slightly modified, it can be installed and configured for use.

3. Important: Back up the old version of php first, in case of rapid rollback after upgrade failure

 # mv /usr/local/php /usr/local/php7.1.bak # mkdir /renwole # cd /renwole # wget //am1.php.net/distributions/php-7.1.5.tar.gz # tar zxvf php-7.1.5.tar.gz # cd php-7.1.5 # ./ configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm-user=www --with-fpm-group=www --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbrege x --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-jis-conv --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-mysql --enable-mysqlnd-compressi on-support --with-pear --enable-maintainer-zts --enable-session --with-gettext

After compiling PHP, you will see“ Thank you for using PHP. ”The character "" indicates that the compilation is completed and the following installation commands are executed;

# make && make install

This process is a little slow, but it does not affect the normal access of your website. Be patient

4. After php completes the upgrade and installation configuration, start copying the php configuration file

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cp /renwole/php-7.1.5/php.ini-development /usr/local/php/etc/php.ini
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

Or continue to use the old PHP configuration file (if the PHP version span is not large, it is recommended to use the old version of php.ini, otherwise many things in the PHP configuration file need to be reconfigured), cp - rf means no prompt for overwriting

# \cp -rf /usr/local/php7.1.0.bak/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf
# \cp -rf /usr/local/php7.1.0.bak/etc/php.ini /usr/local/php/etc/php.ini
# \cp -rf /usr/local/php7.1.0.bak/etc/php-fpm.d/www.conf /usr/local/php/etc/php-fpm.d/www.conf

5. Now restart php fpm

# systemctl restart php-fpm.server

6. Check the php version again

# /usr/local/php/bin/php -v

PHP 7.1.5 (cli) (built: May 11 2017 16:18:43) ( ZTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.5, Copyright (c) 1999-2017, by Zend Technologies

The printed PHP version information is displayed; Successfully and seamlessly upgraded from PHP 7.1.0 to PHP 7.1.5

Production of compiling and installing source code of Centos 7 php7.2

Introduction:

I have heard for a long time that the speed and performance of PHP 7 is faster than that of any version of the PHP 5 series. How good is the specific performance? I suggest you try it first. If you are upgrading or installing, you need to first consider whether PHP 7 is compatible with the program. If the program is developed based on PHP 5, you need to consider whether PHP 7 is suitable for your current production environment. Today I will practice and install it for production.

Install the PHP dependency package first, or various errors will appear during the compilation and installation of PHP 7. After the installation is completed, you can move on to the next step.

Install the expansion pack and update the system kernel:

 $ yum install epel-release -y $ yum update

Install php dependency components (including Nginx dependency):

 $ yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc- devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel

Create users and groups, and download the php installation package to unzip:

 $ cd /tmp $ groupadd www $ useradd -g www www $ wget //am1.php.net/distributions/php-7.2.1.tar.gz $ tar xvf php-7.2.1.tar.gz $ cd php-7.2.1

Set variables and start source code compilation:

 $ cp -frp /usr/lib64/libldap* /usr/lib/ $ ./ configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --enable-mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --enable-mysqlnd-compression-support \ --with-iconv-dir \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir \ --enable-xml \ --disable-rpath \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --enable-mbregex \ --enable-mbstring \ --enable-intl \ --with-mcrypt \ --with-libmbfl \ --enable-ftp \ --with-gd \ --enable-gd-jis-conv \ --enable-gd-native-ttf \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --with-gettext \ --disable-fileinfo \ --enable-opcache \ --with-pear \ --enable-maintainer-zts \ --with-ldap=shared \ --without-gdbm \ --enable-fileinfo \

If there is no error report, execute the next step of installation. If there is an error in the compilation process, install the dependent package according to the error report. This problem usually does not occur.

be careful: – enable gd jis conv This parameter will cause Zabbix Chinese characters to be garbled. It is recommended to cancel it.

Start installation:

 $ make -j 4 && make install

After installation, configure the php.ini file:

 $ cp php.ini-development /usr/local/php/etc/php.ini $ cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf $ cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

Modify php.ini related parameters:

 $ vim /usr/local/php/etc/php.ini expose_php = Off short_open_tag = ON max_execution_time = 300 max_input_time = 300 memory_limit = 128M post_max_size = 32M date.timezone = Asia/Shanghai mbstring.func_overload=2 extension = "/usr/local/php/lib/php/extensions/no-debug-zts-20160303/ldap.so"

Set OPcache cache:

 [opcache] zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20160303/opcache.so opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=1

Set the php security function:

 $ vim /usr/local/php/etc/php.ini

Default value:

 disable_functions =

Revised as:

 disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error, posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid, posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

Or general configuration:

 disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru

Configure www.conf

Uncomment the following and modify and optimize its parameters:

 listen = /var/run/www/php-cgi.sock listen.owner = www listen.group = www listen.mode = 0660 listen.allowed_clients = 127.0.0.1 pm = dynamic listen.backlog = -1 pm.max_children = 180 pm.start_servers = 50 pm.min_spare_servers = 50 pm.max_spare_servers = 180 request_terminate_timeout = 120 request_slowlog_timeout = 50 slowlog = var/log/slow.log

Create php-cgi.sock storage directory

 $ mkdir /var/run/www/ $ chown -R www:www /var/run/www

Configure php fpm. conf

Remove the following notes and complete the path:

 pid = /usr/local/php/var/run/php-fpm.pid

So far, php7 has been installed.

explain: Disable php functions. If the program needs these functions, you can cancel the prohibition. Novice recommends ignoring this step.

Create a php fpm startup script for the system unit file:

 $ vim /usr/lib/systemd/system/php-fpm.service

Add the following variable contents:

 [Unit] Description=The PHP FastCGI Process Manager After=syslog.target network.target [Service] Type=simple PIDFile=/usr/local/php/var/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID [Install] WantedBy=multi-user.target

Start the php fpm service and join the startup auto start:

 $ systemctl enable php-fpm.service $ systemctl restart php-fpm.service

The entire PHP installation process has been completed. If you failed to install according to this article, I hope you can leave a message explaining the reason for the error, and I will help you configure for free.

If you have good suggestions to improve this article, you are welcome to put forward and improve it. We will learn and progress together.