検索
ホームページバックエンド開発PHPチュートリアルLinuxにPHPをインストールする方法

LinuxにPHPをインストールする方法

Mar 17, 2018 am 10:46 AM
linuxphpどうやって

この記事では、主に Linux に php をインストールする方法を写真とテキストの形式で共有し、お役に立てれば幸いです。

1. php公式ウェブサイトから対応するバージョンをダウンロードします

phpのダウンロードページには最新バージョンのみがあり、古いバージョンはダウンロードページで見つけることができなくなっているため、次の URL に手動でアクセスしてダウンロードします。

http://cn.php.net/distributions/php-5.3.9.tar.bz2 一部の古いバージョンがこのページにリストされています。5.3 バージョンが使用されます。 gz 形式です


2. php

をインストールし、解凍されたパッケージディレクトリに移動し、コマンドを実行します: ./configure --prefix=/opt/local /php、「 /opt/local/php」はインストールパスです。任意のインストールパスに変更できます。

(1) 必要なプラグインがいくつかないことを示すプロンプトが表示される場合があります。たとえば、最も可能性の高いエラーは次のとおりです。configure error xml2-config not found. libxml2 のインストールを確認してください。この時点で実行してください。コマンド: yum -y install libxml2 libxml2-devel、対応するプラグインのインストールなど

すべてのプラグインがインストールされたら、再度実行します

<span style="font-size: 14px;">./configure --prefix=/opt/local/php<br/></span>


(2) ここに php-fpm 関数をインストールしたい場合 その場合は、yum を使用してさらに次のようなプラグインをインストールする必要があります:

<span style="font-size: 14px;">yum -y install openssl openssl-devel bzip2 bzip2-devel curl curl-devel readline-devel fcgi php-mcrypt libmcrypt libmcrypt-devel<br/></span>


-mcrypt libmcrypt libmcrypt-devel を実行すると、パッケージが見つからないというメッセージが表示される場合があります。この場合、問題を解決するにはソースを更新する必要があります。

<span style="font-size: 14px;">yum -y install epel-release<br/>yum update<br/></span>

このうち、Update は成功するまでに 2 回実行され、その後、configure が実行されます。

./configure --prefix=/opt/local/php5.3.29 --with-config-file-path=/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline --without-sqlite3 --without-pdo-sqlite --with-pear  

通过后执行make

此时可能会出现以下提示

PEAR package PHP_Archive not installed: generated phar will require PHP&#39;s phar extension be enabled.

此处可暂进忽略,等之后再行安装,再次在php目录执行make all install

如果安装了php-fpm,则还需要执行以下命令,将php/etc目录下的配置文件拷贝一份

cp etc/php-fpm.conf.default etc/php-fpm.conf

将php/lib/php.ini拷贝到/etc/下

3.初装phar

这时可以执行

<span style="font-size: 14px;">wget http://pear.php.net/go-pear.phar<br/></span>

之后再执行

/opt/local/php/bin/php /opt/local/go-pear.phar

在出现的提示后,选1,选择phar安装目录,然后一路回车进行安装即可

最后制作php软链,让php全局可用

<span style="font-size: 14px;">ln -s /opt/local/php/bin/php /usr/bin/php<br/></span>

4.验证

执行php -v和sbin/php-fpm -v查看php版本以验证php是否已安装



5.启动php-fpm

php/sbin/php-fpm

INT, TERM 立刻终止

QUIT 平滑终止

USR1 重新打开日志文件

USR2 平滑重载所有worker进程并重新载入配置和二进制模块

示例:

php-fpm 关闭:

kill -INT `cat /opt/local/php/var/run/php-fpm.pid`

php-fpm 重启:

kill -USR2 `cat /opt/local/php/var/run/php-fpm.pid`

如果找不到php-fpm.pid文件,可通过查找php-fpm进程号进行重启和关闭

例如

<span style="font-size: 14px;">[root@SH-DEV local]# ps -aux|grep php-fpm<br/>root     141735  0.0  0.0 201840  3892 ?       <br/> Ss   16:27   0:00 php-fpm: master process (/opt/local/php5.3.29/etc/php-fpm.conf)<br/><br/>kill -USR2 141735<br/></span>


6.修改php-fpm配置

(1)如果在nginx.conf中使用了fastcgi_pass   unix:/tmp/php-cgi.sock,则需要修改php-fpm.conf,找到如下码段:

<span style="font-size: 14px;">; The address on which to accept FastCGI requests.<br/>; Valid syntaxes are:<br/>;   &#39;ip.add.re.ss:port&#39;    - to listen on a TCP socket to a specific address on<br/>;                            a specific port;<br/>;   &#39;port&#39;                 - to listen on a TCP socket to all addresses on a<br/>;                            specific port;<br/>;   &#39;/path/to/unix/socket&#39; - to listen on a unix socket.<br/>; Note: This value is mandatory.<br/>;listen = 127.0.0.1:9000<br/>listen = /tmp/php-cgi.sock<br/><br/>; Set listen(2) backlog. A value of &#39;-1&#39; means unlimited.<br/>; Default Value: 128 (-1 on FreeBSD and OpenBSD)<br/>;listen.backlog = -1<br/><br/>; Set permissions for unix socket, if one is used. In Linux, read/write<br/>; permissions must be set in order to allow connections from a web server. Many<br/>; BSD-derived systems allow connections regardless of permissions.<br/>; Default Values: user and group are set as the running user<br/>;                 mode is set to 0660<br/>listen.owner = nobody<br/>listen.group = nobody<br/>listen.mode = 0660<br/></span>

将原listen和listen.ownerlisten.group段做如上修改,其中listen.ownerlisten.group为nginx启动用户名,如此处不修改,会提示

nginx error connect to php-fpm.sock failed (13: Permission denied)

当然此处如果将sock放在内存中/dev/shm/php-fpm.sock会更快

(2)修改php-fpm线程数

<span style="font-size: 14px;">; Per pool prefix<br/>; It only applies on the following directives:<br/>; - &#39;slowlog&#39;<br/>; - &#39;listen&#39; (unixsocket)<br/>; - &#39;chroot&#39;<br/>; - &#39;chdir&#39;<br/>; - &#39;php_values&#39;<br/>; - &#39;php_admin_values&#39;<br/>;   dynamic - the number of child processes are set dynamically based on the<br/>;             following directives. With this process management, there will be<br/>;             always at least 1 children.<br/>;             pm.max_children      - the maximum number of children that can<br/>;                                    be alive at the same time.<br/>;             pm.start_servers     - the number of children created on startup.<br/>;             pm.min_spare_servers - the minimum number of children in &#39;idle&#39;<br/>;                                    state (waiting to process). If the number<br/>;                                    of &#39;idle&#39; processes is less than this<br/>;                                    number then some children will be created.<br/>;             pm.max_spare_servers - the maximum number of children in &#39;idle&#39;<br/>;                                    state (waiting to process). If the number<br/>;                                    of &#39;idle&#39; processes is greater than this<br/>;                                    number then some children will be killed.<br/>;  ondemand - no children are created at startup. Children will be forked when<br/>;             new requests will connect. The following parameter are used:<br/>;             pm.max_children           - the maximum number of children that<br/>;                                         can be alive at the same time.<br/>;             pm.process_idle_timeout   - The number of seconds after which<br/>;                                         an idle process will be killed.<br/>; Note: This value is mandatory.<br/>pm = dynamic<br/>#如何控制子进程,选项有static和dynamic。如果选择static,则由pm.max_children指定固定的子进程数。如果选择dynamic,则由下面的参数决定<br/><br/>; The number of child processes to be created when pm is set to &#39;static&#39; and the<br/>; maximum number of child processes when pm is set to &#39;dynamic&#39; or &#39;ondemand&#39;.<br/>; This value sets the limit on the number of simultaneous requests that will be<br/>; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.<br/>; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP<br/>; CGI. The below defaults are based on a server without much resources. Don&#39;t<br/>; forget to tweak pm.* to fit your needs.<br/>; Note: Used when pm is set to &#39;static&#39;, &#39;dynamic&#39; or &#39;ondemand&#39;<br/>; Note: This value is mandatory.<br/>pm.max_children = 8<br/>#子进程最大数<br/><br/>; The number of child processes created on startup.<br/>; Note: Used only when pm is set to &#39;dynamic&#39;<br/>; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2<br/>pm.start_servers = 8<br/>#启动时的进程数<br/><br/><br/>; The desired minimum number of idle server processes.<br/>; Note: Used only when pm is set to &#39;dynamic&#39;<br/>; Note: Mandatory when pm is set to &#39;dynamic&#39;<br/>pm.min_spare_servers = 1<br/>#保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程<br/><br/>; The desired maximum number of idle server processes.<br/>; Note: Used only when pm is set to &#39;dynamic&#39;<br/>; Note: Mandatory when pm is set to &#39;dynamic&#39;<br/>pm.max_spare_servers = 8<br/>#保证空闲进程数最大值,如果空闲进程大于此值,此进行清理<br/></span>

相关推荐:

Linux上安装php-mysqlnd扩展实例

mac安装php开发环境方法实例分享

最详细的linux安装php过程

以上がLinuxにPHPをインストールする方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
PHPの継続的な使用:その持久力の理由PHPの継続的な使用:その持久力の理由Apr 19, 2025 am 12:23 AM

まだ人気があるのは、使いやすさ、柔軟性、強力なエコシステムです。 1)使いやすさとシンプルな構文により、初心者にとって最初の選択肢になります。 2)Web開発、HTTP要求とデータベースとの優れた相互作用と密接に統合されています。 3)巨大なエコシステムは、豊富なツールとライブラリを提供します。 4)アクティブなコミュニティとオープンソースの性質は、それらを新しいニーズとテクノロジーの傾向に適応させます。

PHPおよびPython:類似点と相違点を調査しますPHPおよびPython:類似点と相違点を調査しますApr 19, 2025 am 12:21 AM

PHPとPythonはどちらも、Web開発、データ処理、自動化タスクで広く使用されている高レベルのプログラミング言語です。 1.PHPは、ダイナミックウェブサイトとコンテンツ管理システムの構築によく使用されますが、PythonはWebフレームワークとデータサイエンスの構築に使用されることがよくあります。 2.PHPはエコーを使用してコンテンツを出力し、Pythonは印刷を使用します。 3.両方ともオブジェクト指向プログラミングをサポートしますが、構文とキーワードは異なります。 4。PHPは弱いタイプの変換をサポートしますが、Pythonはより厳しくなります。 5. PHPパフォーマンスの最適化には、Opcacheおよび非同期プログラミングの使用が含まれますが、PythonはCprofileおよび非同期プログラミングを使用します。

PHPおよびPython:さまざまなパラダイムが説明されていますPHPおよびPython:さまざまなパラダイムが説明されていますApr 18, 2025 am 12:26 AM

PHPは主に手順プログラミングですが、オブジェクト指向プログラミング(OOP)もサポートしています。 Pythonは、OOP、機能、手続き上のプログラミングなど、さまざまなパラダイムをサポートしています。 PHPはWeb開発に適しており、Pythonはデータ分析や機械学習などのさまざまなアプリケーションに適しています。

PHPとPython:彼らの歴史を深く掘り下げますPHPとPython:彼らの歴史を深く掘り下げますApr 18, 2025 am 12:25 AM

PHPは1994年に発信され、Rasmuslerdorfによって開発されました。もともとはウェブサイトの訪問者を追跡するために使用され、サーバー側のスクリプト言語に徐々に進化し、Web開発で広く使用されていました。 Pythonは、1980年代後半にGuidovan Rossumによって開発され、1991年に最初にリリースされました。コードの読みやすさとシンプルさを強調し、科学的コンピューティング、データ分析、その他の分野に適しています。

PHPとPythonの選択:ガイドPHPとPythonの選択:ガイドApr 18, 2025 am 12:24 AM

PHPはWeb開発と迅速なプロトタイピングに適しており、Pythonはデータサイエンスと機械学習に適しています。 1.PHPは、単純な構文と迅速な開発に適した動的なWeb開発に使用されます。 2。Pythonには簡潔な構文があり、複数のフィールドに適しており、強力なライブラリエコシステムがあります。

PHPとフレームワーク:言語の近代化PHPとフレームワーク:言語の近代化Apr 18, 2025 am 12:14 AM

PHPは、多数のWebサイトとアプリケーションをサポートし、フレームワークを通じて開発ニーズに適応するため、近代化プロセスで依然として重要です。 1.PHP7はパフォーマンスを向上させ、新機能を紹介します。 2。Laravel、Symfony、Codeigniterなどの最新のフレームワークは、開発を簡素化し、コードの品質を向上させます。 3.パフォーマンスの最適化とベストプラクティスは、アプリケーションの効率をさらに改善します。

PHPの影響:Web開発などPHPの影響:Web開発などApr 18, 2025 am 12:10 AM

phphassiblasifly-impactedwebdevevermentandsbeyondit.1)itpowersmajorplatformslikewordpratsandexcelsindatabase interactions.2)php'sadaptableability allowsitale forlargeapplicationsusingframeworkslikelavel.3)

スカラータイプ、リターンタイプ、ユニオンタイプ、ヌル可能なタイプなど、PHPタイプのヒントはどのように機能しますか?スカラータイプ、リターンタイプ、ユニオンタイプ、ヌル可能なタイプなど、PHPタイプのヒントはどのように機能しますか?Apr 17, 2025 am 12:25 AM

PHPタイプは、コードの品質と読みやすさを向上させるためのプロンプトがあります。 1)スカラータイプのヒント:php7.0であるため、基本データ型は、int、floatなどの関数パラメーターで指定できます。 3)ユニオンタイプのプロンプト:PHP8.0であるため、関数パラメーターまたは戻り値で複数のタイプを指定することができます。 4)Nullable Typeプロンプト:null値を含めることができ、null値を返す可能性のある機能を処理できます。

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SecLists

SecLists

SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

PhpStorm Mac バージョン

PhpStorm Mac バージョン

最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

AtomエディタMac版ダウンロード

AtomエディタMac版ダウンロード

最も人気のあるオープンソースエディター

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境