PHP extension module, Apache rewrite module

Source: Internet
Author: User
Tags deprecated phpinfo response code zts zend

11.32 PHP Dynamic Expansion Module installation

Note: This section operates using PHP7.

To view the PHP module:

[Email protected] ~]#/usr/local/php/bin/php-m
Installing the Redis module

Redis is a key-value storage system. Similar to memcached, it supports storing more value types, including string (string), list (linked list), set (set), and Zset (ordered collection).

Preparatory work:

[Email protected] ~]# CD/USR/LOCAL/SRC

To download the Redis installation package:
[Email protected] src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop

Rename:
[Email protected] src]# MV Develop Phpredis-develop.zip

Extract:
[Email protected] src]# Unzip Phpredis-develop.zip

[Email protected] src]# CD phpredis-develop/

[Email protected] phpredis-develop]#/usr/local/php7/bin/phpize
#执行该命令的目的是生成configure文件, or you cannot compile the installation

Error:
Cannot find autoconf. Please check your autoconf installation and the
$PHP _autoconf environment variable. Then, rerun the this script.

Workaround:
[email protected] phpredis-develop]# Yum install-y autoconf

[Email protected] phpredis-develop]#/usr/local/php7/bin/phpize
Configuring for:
PHP Api version:20160303
Zend Module Api no:20160303
Zend Extension Api no:320160303
Start installation

Environment configuration

[Email protected] phpredis-develop]#/configure--with-php-config=/usr/local/php7/bin/php-config
Compile & Install

[[email protected] phpredis-develop]# make

[[email protected] phpredis-develop]# make install
Installing Shared extensions:/usr/local/php7/lib/php/extensions/no-debug-zts-20160303/

[Email protected] phpredis-develop]# ls/usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
Opcache.so redis.so
To load a Redis module for PHP

First look at the directory where the extension module resides:

[Email protected] phpredis-develop]#/usr/local/php7/bin/php-i|grep Extension_dir
Extension_dir =/usr/local/php7/lib/php/extensions/no-debug-zts-20160303 =/usr/local/php7/lib/php/ extensions/no-debug-zts-20160303
Sqlite3.extension_dir = no value = no value
Description: This directory can be set in PHP config file php.ini (leave the default).

Loading the Redis module

To edit a PHP configuration file:

[Email protected] phpredis-develop]# Vim/usr/local/php7/etc/php.ini

; If you wish to a extension loaded automatically, use the following
; Syntax
; ... or under UNIX:
;
; Extension=msql.so
Extension=redis.so

[Email protected] phpredis-develop]#/usr/local/php7/bin/php-m |grep Redis
Redis
Description: Add "extension=redis.so" to the configuration file! The ";" in the file represents the comment symbol, which is the same as "#".

About expansion Plates

In the PHP source package does not have a third-party module package, but in the PHP source package/ext/Directory has a lot of extension modules, if the required extension module in this directory, you can directly install:

Switch to the specified module directory first, and then do the following:

Generate the Configure file:
[Email protected] phpredis-develop]#/usr/local/php7/bin/phpize

Environment configuration:
[Email protected] phpredis-develop]#/configure--with-php-config=/usr/local/php7/bin/php-config

Compile:
[[email protected] phpredis-develop]# make

Installation:
[[email protected] phpredis-develop]# make install

After the installation is complete, configure it in edit php.ini!
Extended:

Apache Rewrite tutorials

Rewrite engine will parse each rewrite rule, each rewrite rule can be with or without rewrite condition, with the words written before the rewrite rule. If the rewrite rule is met, the rewrite condition will be examined further. The specific treatment is as follows:

First match rewrite's patern, if not match then enter the next rewrite rule.
If it matches, then mod_rewrite checks rewrite condition, and if there is no condition, the new string replaces the URL and then goes to the next rewrite rule.
If rewrite condition exists, the conditions is checked sequentially. The condition match is not for URLs, but for extension variables. Conditons is the relationship between and between the default, that is, conditon if there is a mismatch, then exit the match; When a condition is matched, the next bar is checked until it does not match, and if all conditions match, the substitution takes place.
Test conditions:

-F file exists;
-D directory exists;
-L is a link file (symbol link);
-S file non-0

Rewrite the rule parameter:

Rewritecond instruction Format
Syntax: Rewritecond teststring Condpattern
Eg: "Rewritecond%{http_host} ^ ww.example.net [NC]"

TestString is a plain-text string, but can contain an extensible composition
Condpattern is a conditional pattern, a regular expression applied to the teststring of the current instance. That is, teststring will be computed and then matched to Condpattern.
In addition, you can append a special tag [flags] for Condpattern as the third parameter of the Rewritecond directive. Flags is a comma-delimited list of the following tokens:
' nocase| NC ' It causes the test to ignore case, i.e. teststring and Condpattern no case checking
' ornext| Or ' it combines the conditions of several rules in or, not the implied and.
rewriterule Directive
Syntax: Rewriterule Pattern Substitution
Eg:rewriterule ^ (. *) $ http://www.9med.net/$1 [r= PERMANENT,L]

Pattern is a Perl-compatible regular expression that acts on the current URL. The "current" here refers to the value of the URL when the rule is in effect.
Substitution is a string that is substituted (or replaced) when the original URL matches the pattern.
In addition, substitution can append a special tag [flags] as the third parameter of the Rewriterule directive. Flags is a comma-delimited list of the following tags:
' Redirect| R [=code] '
(Force redirect redirect) a substitution that is prefixed with http://thishost[:thisport]/(making the new URL a URI) can be forced to perform an external redirect. If code is not specified, an HTTP response code of 302 (temporary move) is generated. If you need to use a different response code in the range of 300-400, you can specify this value here, plus one of the following symbol names: Temp (default), permanent, seeother. It can be used to feedback the normalized URL to the client, such as rewriting "/~" to "/u/", or/u/user plus slashes, etc.
Note: When using this tag, you must ensure that the replacement field is a valid url! Otherwise, it will point to an invalid location! And keep in mind that this tag itself is just a prefix to the URL plus http://thishost[:thisport]/, and the rewrite operation will still continue. In general, you will want to stop the rewrite operation and immediately redirect, then you also need to use the ' L ' tag.

' Forbidden| F ' (force URL for forbidden Forbidden)
Forces the current URL to be disabled, that is, immediately feedback an HTTP response code of 403 (forbidden). With this tag, you can link several rewriteconds to conditionally block certain URLs.

' Gone| G ' (force URL to obsolete gone)
Forces the current URL to be obsolete, that is, immediately feedback an HTTP response code 410 (deprecated). Using this tag, you can indicate that the page has been deprecated and does not exist.

' Proxy| P ' (Force agent proxy)
This flag causes the replacement ingredient to be internally coerced to the proxy request and immediately (that is, the rewrite rule handles immediate interrupts) handing over the processing to the proxy module. You must make sure that this replacement string is a valid URI (such as a common one that starts with http://hostname) that can be handled by the Apache proxy module. With this tag, some remote components can be mapped to the local server namespace, thereby enhancing the functionality of the Proxypass directive.
Note: To use this feature, the proxy module must be compiled on the Apache server. If you are not sure, you can check the output of "httpd-l" for mod_proxy.c. If so, mod_rewrite can use this feature, and if not, you must enable Mod_proxy and recompile the HTTPD program.

' Last| L ' (Final Rule last)
Stops the rewrite operation immediately and no longer applies another rewrite rule. It corresponds to the last command in Perl or the break command in the C language. This tag prevents the currently overridden URL from being overridden by its successor rule. For example, use it to rewrite the URL of the root path ('/') to a URL that actually exists, for example, '/e/www/'.

' Next| N ' (re-execute next round)
Re-executes the rewrite operation (starting with the first rule). The URL that was processed again is not the original URL, but the URL that was processed by the last rewrite rule. It corresponds to the next command in Perl or the Continue command in the C language. This tag can restart the rewrite operation, that is, immediately return to the head of the loop. But be careful not to create a dead loop!

' Chain| C ' (link to next rule chained)
This tag causes the current rule to be linked to the next rule (which itself can be linked to its successor rule and can be so repeated). It produces such an effect: if a rule is matched, it will usually continue to process its successor, that is, the tag does not work, and if the rule cannot be matched, then its subsequent linked rules are ignored. For example, when performing an external redirect, for a directory-level rule set, you may need to delete ". www" (where ". www" should not appear).

' Type| T=mime-type ' (force MIME type types)
The mandatory MIME type for the target file is Mime-type. For example, it can be used to simulate the Scriptalias directive in Mod_alias to internally force the MIME type of all files in the mapped directory to be "application/x-httpd-cgi".

' Nosubreq| NS ' (only for no internal sub-request processing no internal sub-request)
This token forces the rewrite engine to skip the rewrite rule when the current request is an internal child request. For example, when Mod_include tries to search for possible directory default files (index.xxx), Apache generates child requests internally. A child request, which is not necessarily useful, and may even throw an error if the entire ruleset is working. Therefore, you can use this tag to exclude certain rules. Follow these guidelines according to your needs: If you use URL prefixes with CGI scripts to force them to be handled by CGI scripts, the error rate (or overhead) of processing a child request is high, in which case you can use this tag.

' Nocase| NC ' (ignoring case of uppercase and lowercase)
It makes the pattern ignore case, that is, ' A-Z ' and ' A-Z ' are not different when pattern matches the current URL.

' Qsappend| QSA ' (Append request string query string append)
This flag forces the rewrite engine to append a request string to an existing replacement string, rather than a simple replacement. You can use this tag if you need to add information to the request string through a rewrite rule.

' Noescape| NE ' (no URI escaped in output no URI escaping)
This flag prevents Mod_rewrite from applying a general URI escape rule to the overridden result. In general, special characters (such as '% ', ' $ ', '; ') And so on) will be escaped to the equivalent hexadecimal encoding. This tag prevents such escapes from allowing symbols such as percent sign to appear in the output, such as: rewriterule/foo/(. *)/bar?arg=p1%3d$1[r,ne] can turn '/foo/zed ' to a secure request '/bar?arg=p1= Zed '.

' Passthrough| PT ' (handed over to the next processor pass through)
This flag forces the rewrite engine to set the URI field in the internal structure request REC to the value of the FileName field, which is only a small modification to the Alias,scriptalias from other URIs to the file name translator, Redirect The output of the command is subsequently processed. Give an example of what it means: if you want to rewrite/abc as/def through mod rewrite's rewrite engine, and then convert /def to/ghi through the MoD alias, you can: Rewriterule ^/abc (. *)/def$1 [PT] Alias/def/ghi, if the PT tag is omitted, although MoD rewrite works properly, that is, as a URI to the file name translator using the API, it can rewrite the uri=/abc/... For filename=/def/..., however, the subsequent mod alias isinvalidated when it attempts to translate the URI to the file name.
Note: You must use this tag if you need to mix a different module that contains a URI to the file name translator. Mixed use of MoD
alias and mod_rewrite is a typical example.

' Skip| S=num ' (Skip the successor rule skip)
This flag forces the rewrite engine to skip the NUM rules succeeding the current matching rule. It can implement a pseudo-If-then-else construct: The last rule is the then clause, and the skip=n rule that is skipped is the ELSE clause. (IT and ' chain| The C ' tag is different!)

' Env| E=var:val ' (Set environment variable environment variable)
This flag causes the environment variable var value to be val,val to contain a regular expression $n and%n that can have an extensible inverse reference. This tag can be used multiple times to set multiple variables. These variables can be referenced indirectly in many subsequent cases, but usually in Xssi (via <!– #echo var= "var" –>) or CGI (e.g. $env{' var '}), You can also use%{env:var} as a reference in the pattern of subsequent rewritecond instructions. Use it to peel and remember some information from the URL.

' cookie|co=name:val:domain[:lifetime[:p Ath]] ' (set cookies)
It sets a cookie on the client browser. The name of the cookie is "name" and its value is Val. The Domain field is the field of the cookie, such as '. Apache.org ', the optional lifetime is the number of minutes of the cookie's lifetime, and the optional path is the cookie.

In fact, the Apache Handbook has: http://man.chinaunix.net/newsoft/ApacheManual/mod/mod_rewrite.html

Apache Official Rewrite Guide example, the following is the WordPress rewrite. htaccess:

BEGIN WordPress

Rewriteengine on
Rewritebase/
#把learndiary. com URLs are all redirected to Www.learndiary.com
Rewritecond%{http_host} ^learndiary.com [NC]
Rewriterule ^ (.) $ http://www.learndiary.com/$1 [l,r=301]
#除开
. Do form URL (required)
Rewritecond%{request_filename}!-f
Rewritecond%{request_filename}!-d
Rewritecond%{request_uri}!. +.do
Rewriterule. /index.php [L]
Apache dead Loop

Rules:

Rewriterule ^ (. *)/111/$1 [r,l]
With curl testing, there is no problem, but there is an infinite loop when using browser access. Originally visited is the www.111.com result becomes www.111.com/111/111/111/... Although in the end added [L] still does not work, maybe Apache is not smart enough, has been satisfied with the conditions have been to match, has been to jump. Finally, there's only one additional condition.

Rewritecond%{request_uri}!^/111
Rewriterule ^ (. *)/111/$1 [r,l]
This will stop the loop.

Another way of Rewritecond

Rewritecond $!^/111
Rewriterule ^ (. *)/111/$1 [r,l]
For objects that match!^, we can also write in multiple forms:

Rewritecond%{request_uri}!^ (/111|/222|/333|index.php)
PHP.ini opening a short label

Control parameters: Short_open_tag = On
If set to OFF, PHP files similar to this form cannot be parsed properly:

<?
Phpinfo ()
?>
and can only parse:

<?php
Phpinfo ()
?>
PHP files in this form.
So if you want PHP to support short tags, we need to set Short_open_tag to on.

PHP extension module, Apache rewrite module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.