Maison > Article > développement back-end > Comment installer php sur Linux
Dans cet article nous partageons principalement avec vous comment installer php sur Linux. Cet article est partagé avec vous sous forme d'images et de textes, en espérant vous aider.
1. Téléchargez la version correspondante depuis le site officiel de php
Parce que la page de téléchargement de php uniquement a la version la plus récente, l'ancienne version téléchargée ne peut plus être trouvée sur la page de téléchargement. Vous ne pouvez la télécharger que manuellement via l'url suivante,
http://cn. php.net/distributions/ php-5.3.9.tar.bz2, certaines anciennes versions seront listées sur cette page. La version 5.3 est utilisée ici Le téléchargement est au format gz
2. Installez php
Décompressez le package tar et entrez dans le répertoire du package décompressé - exécutez la commande : ./configure --prefix =/opt/local/ php, "/opt/local/php" est le chemin d'installation, qui peut être modifié par le chemin d'installation souhaité.
(1) Il peut y avoir une invite indiquant que certains plug-ins nécessaires sont manquants. À ce stade, utilisez la commande yum pour l'installer. Par exemple, l'erreur la plus probable est : configure error xml2-config not found. Veuillez vérifier votre installation de libxml2, puis exécutez la commande : yum -y install libxml2 libxml2-devel, installez le plug-in correspondant, et ainsi de suite
Une fois tous les plug-ins installés, exécutez à nouveau
<span style="font-size: 14px;">./configure --prefix=/opt/local/php<br/></span>
(2) Si vous souhaitez installer la fonction php-fpm ici, vous avez besoin de yum pour installer plus de plug -ins, par exemple :
<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>
Dans quelle installation php-mcrypt
libmcrypt libmcrypt-devel peut indiquer que le package est introuvable. Dans ce cas, vous devez mettre à jour la source pour résoudre le problème. La commande spécifique est la suivante :
<span style="font-size: 14px;">yum -y install epel-release<br/>yum update<br/></span>
Parmi eux, la mise à jour a été exécutée deux fois avant de réussir, puis la configuration a été exécutée à nouveau
./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'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/>; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on<br/>; a specific port;<br/>; 'port' - to listen on a TCP socket to all addresses on a<br/>; specific port;<br/>; '/path/to/unix/socket' - 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 '-1' 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.owner,listen.group段做如上修改,其中listen.owner,listen.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/>; - 'slowlog'<br/>; - 'listen' (unixsocket)<br/>; - 'chroot'<br/>; - 'chdir'<br/>; - 'php_values'<br/>; - 'php_admin_values'<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 'idle'<br/>; state (waiting to process). If the number<br/>; of 'idle' processes is less than this<br/>; number then some children will be created.<br/>; pm.max_spare_servers - the maximum number of children in 'idle'<br/>; state (waiting to process). If the number<br/>; of 'idle' 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 'static' and the<br/>; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.<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't<br/>; forget to tweak pm.* to fit your needs.<br/>; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'<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 'dynamic'<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 'dynamic'<br/>; Note: Mandatory when pm is set to 'dynamic'<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 'dynamic'<br/>; Note: Mandatory when pm is set to 'dynamic'<br/>pm.max_spare_servers = 8<br/>#保证空闲进程数最大值,如果空闲进程大于此值,此进行清理<br/></span>
相关推荐:
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!