PHP腳本的10個(gè)技巧(轉(zhuǎn)自ZDNet) --把PHP安裝為Apache DSO
Jun 21, 2016 am 09:12 AMapache|技巧|腳本
把PHP安裝為Apache DSO
PHP 經(jīng)常和Apache Web服務(wù)器一道用于Linux/Unix平臺(tái)。當(dāng)我們?cè)贏pache環(huán)境下安裝PHP的時(shí)候,你有三種安裝模式可供選擇:靜態(tài)模塊、動(dòng)態(tài)模塊(DSO)和CGI。
我建議你最好把PHP安裝為Apached的DSO ,這種安裝模式的維護(hù)和升級(jí)都相當(dāng)簡(jiǎn)單。比方說(shuō),假設(shè)你原先只安裝了PHP的數(shù)據(jù)庫(kù)支持功能??蛇^(guò)了幾天之后你又決定要為PHP添加加密功能。很簡(jiǎn)單,你只要鍵入make clean命令,然后增加新的配置選項(xiàng),接著再執(zhí)行make和 make install命令即可。這樣,新的PHP模塊就會(huì)被安裝到Apache上的恰當(dāng)位置,你只要重新啟動(dòng)Apache就一切OK了,當(dāng)然,整個(gè)過(guò)程完全不用重新編譯Apache。
安裝新版本的Apache以及安裝作為Apache DSO的PHP的簡(jiǎn)單步驟如下所示:
1. 從Apache軟件基金會(huì)這一站點(diǎn)下載Apache服務(wù)器軟件的最新版本源代碼。
2. 把代碼文件放到/usr/local/ 或者/opt/ 等合適的目錄下。
3. 用Gunzip命令對(duì)代碼文件解壓縮,然后你可以得到相應(yīng)的*.tar文件。
4. 鍵入以下的解包命令把以上的tar文件放到形為apache_[version]的目錄下:
tar -xvf apache_[version].tar
5. 進(jìn)到/usr/local/apache_[version] 目錄(或者在上面步驟中你所指定的目錄)。
6. 鍵入下面的配置命令,用你設(shè)定的路徑(比如/usr/local/apache[version]等,注意后面不要跟斜線?。┤〈鶾path]參數(shù),同時(shí)你還要啟用mod_so參數(shù)以允許Apache使用DSO。
./configure --prefix=[path] --enable-module=so
7. 回到命令提示行鍵入make命令并等待命令執(zhí)行完成再次回到命令提示狀態(tài)下。
8. 鍵入make install。
到這個(gè)時(shí)候,編譯器即可創(chuàng)建最終的目錄并返回到系統(tǒng)的命令提示狀態(tài)下。
接下來(lái)安裝PHP:
1. 訪問(wèn)PHP主頁(yè)的下載區(qū)域選中最新版本源代碼的鏈接。
2. 把下載的文件放到/usr/local/ 或者/opt/等適當(dāng)?shù)哪夸浵隆?br>3. 用Gunzip命令對(duì)代碼文件解壓縮,然后你可以得到相應(yīng)的*.tar文件。
4. 鍵入以下的解包命令把以上的tar文件放到形為php-[version]的目錄下:
tar -xvf php-[version]
5. 進(jìn)到/usr/local/php-[version]目錄下(或者你指定的目錄)。
現(xiàn)在即可編譯PHP DSO,其實(shí)這里只需要一個(gè)必要的配置選項(xiàng)--with-apxs(Apache bin目錄下的一個(gè)文件)--不過(guò),為了系統(tǒng)配置更為全面,我們?cè)谶@里還增加了對(duì)MySQL數(shù)據(jù)庫(kù)的支持。
./configure --with-mysql=/[path to mysql] --with-apxs=/[path to apxs]
6.回到命令提示行下鍵入make命令并等到命令執(zhí)行完成再次回到命令提示狀態(tài)下。
7.鍵入make install命令。
在這個(gè)時(shí)候,編譯器將會(huì)創(chuàng)建最終的DSO,并把它放在Apache模塊目錄下,同時(shí)會(huì)為你修改Apache的httpd.conf 配置文件,之后系統(tǒng)回到命令提示狀態(tài)下等待你輸入新指令。然后,你即可打開Apache的httpd.conf 配置文件做一些修正:
1. 找到有ServerAdmin字樣的一行,加入你自己的電子郵件地址,如下所示:
ServerAdmin you@yourdomain.com
2. 找到以ServerName開頭的一行,把后面的參數(shù)修改為實(shí)際值,比如:
ServerName localhost
3. 找到下面一段:
# And for PHP 4.x, use:
#
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps
修改這些配置行以便取消PHP 4.0下的某些加在AddType之前的注釋,同時(shí)你應(yīng)該添加一些為PHP所使用的文件擴(kuò)展名,修改后的以上各行看起來(lái)可能會(huì)是下面這樣子:
# And for PHP 4.x, use:
#
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
保存以上的配置文件,回到上級(jí)目錄,鍵入以下命令即可啟動(dòng)Apache:
./bin/apachectl start
如果啟動(dòng)期間沒(méi)有出現(xiàn)什么問(wèn)題,你即可測(cè)試Apache和PHP的安裝情況,方法是創(chuàng)建一個(gè)名叫phpinfo.php的文件,其中包含了以下的代碼行:
phpinfo() ?>
保存該文件并把它放置在Apache的文檔根目錄下(htdocs),然后啟動(dòng)你的Web瀏覽器,在瀏覽器地址欄里鍵入http://localhost/phpinfo.php,瀏覽器即會(huì)以很大的篇幅顯示出PHP和Apache系統(tǒng)的各個(gè)變量和變量值。
如果你想要重新設(shè)置PHP,你需要做的不外乎是執(zhí)行make clean命令,然后執(zhí)行帶有新配置選項(xiàng)的./configure命令,接著執(zhí)行make和make install。這樣,Apache模塊目錄中就會(huì)出現(xiàn)一個(gè)新模塊,你只要重啟Apache以裝載新模塊。以前的許多頭疼問(wèn)題現(xiàn)在就迎刃而解了。

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The core method of building social sharing functions in PHP is to dynamically generate sharing links that meet the requirements of each platform. 1. First get the current page or specified URL and article information; 2. Use urlencode to encode the parameters; 3. Splice and generate sharing links according to the protocols of each platform; 4. Display links on the front end for users to click and share; 5. Dynamically generate OG tags on the page to optimize sharing content display; 6. Be sure to escape user input to prevent XSS attacks. This method does not require complex authentication, has low maintenance costs, and is suitable for most content sharing needs.

To realize text error correction and syntax optimization with AI, you need to follow the following steps: 1. Select a suitable AI model or API, such as Baidu, Tencent API or open source NLP library; 2. Call the API through PHP's curl or Guzzle and process the return results; 3. Display error correction information in the application and allow users to choose whether to adopt it; 4. Use php-l and PHP_CodeSniffer for syntax detection and code optimization; 5. Continuously collect feedback and update the model or rules to improve the effect. When choosing AIAPI, focus on evaluating accuracy, response speed, price and support for PHP. Code optimization should follow PSR specifications, use cache reasonably, avoid circular queries, review code regularly, and use X

User voice input is captured and sent to the PHP backend through the MediaRecorder API of the front-end JavaScript; 2. PHP saves the audio as a temporary file and calls STTAPI (such as Google or Baidu voice recognition) to convert it into text; 3. PHP sends the text to an AI service (such as OpenAIGPT) to obtain intelligent reply; 4. PHP then calls TTSAPI (such as Baidu or Google voice synthesis) to convert the reply to a voice file; 5. PHP streams the voice file back to the front-end to play, completing interaction. The entire process is dominated by PHP to ensure seamless connection between all links.

1. Maximizing the commercial value of the comment system requires combining native advertising precise delivery, user paid value-added services (such as uploading pictures, top-up comments), influence incentive mechanism based on comment quality, and compliance anonymous data insight monetization; 2. The audit strategy should adopt a combination of pre-audit dynamic keyword filtering and user reporting mechanisms, supplemented by comment quality rating to achieve content hierarchical exposure; 3. Anti-brushing requires the construction of multi-layer defense: reCAPTCHAv3 sensorless verification, Honeypot honeypot field recognition robot, IP and timestamp frequency limit prevents watering, and content pattern recognition marks suspicious comments, and continuously iterate to deal with attacks.

PHP ensures inventory deduction atomicity through database transactions and FORUPDATE row locks to prevent high concurrent overselling; 2. Multi-platform inventory consistency depends on centralized management and event-driven synchronization, combining API/Webhook notifications and message queues to ensure reliable data transmission; 3. The alarm mechanism should set low inventory, zero/negative inventory, unsalable sales, replenishment cycles and abnormal fluctuations strategies in different scenarios, and select DingTalk, SMS or Email Responsible Persons according to the urgency, and the alarm information must be complete and clear to achieve business adaptation and rapid response.

PHP does not directly perform AI image processing, but integrates through APIs, because it is good at web development rather than computing-intensive tasks. API integration can achieve professional division of labor, reduce costs, and improve efficiency; 2. Integrating key technologies include using Guzzle or cURL to send HTTP requests, JSON data encoding and decoding, API key security authentication, asynchronous queue processing time-consuming tasks, robust error handling and retry mechanism, image storage and display; 3. Common challenges include API cost out of control, uncontrollable generation results, poor user experience, security risks and difficult data management. The response strategies are setting user quotas and caches, providing propt guidance and multi-picture selection, asynchronous notifications and progress prompts, key environment variable storage and content audit, and cloud storage.

PHPisstillrelevantinmodernenterpriseenvironments.1.ModernPHP(7.xand8.x)offersperformancegains,stricttyping,JITcompilation,andmodernsyntax,makingitsuitableforlarge-scaleapplications.2.PHPintegrateseffectivelyinhybridarchitectures,servingasanAPIgateway

The core role of Homebrew in the construction of Mac environment is to simplify software installation and management. 1. Homebrew automatically handles dependencies and encapsulates complex compilation and installation processes into simple commands; 2. Provides a unified software package ecosystem to ensure the standardization of software installation location and configuration; 3. Integrates service management functions, and can easily start and stop services through brewservices; 4. Convenient software upgrade and maintenance, and improves system security and functionality.
