search
HomeBackend DevelopmentPHP TutorialHow to install php on linux

How to install php on linux

Mar 17, 2018 am 10:46 AM
linuxphphow

In this article we mainly share with you how to install php on Linux. This article is shared with you in the form of pictures and texts, hoping to help you.

1. Download the corresponding version from the php official website

Because the php download page only has the latest few version, the downloaded older version can no longer be found on the download page. You can only download it manually through the following URL,

http://cn.php.net/distributions/ php-5.3.9.tar.bz2, some old versions will be listed on this page. The 5.3 version is used here, and the download is in gz format


2. Install php

Unzip the tar package and enter the unzipped package directory - execute the command: ./configure --prefix=/opt/local/ php, "/opt/local/php" is the installation path, you can change it to the installation path you want.

(1) There may be a prompt here that some necessary plug-ins are missing. In this case, use the yum command to install it. For example, the most likely error is: configure error xml2-config not found. please Check your libxml2 installation, then execute the command: yum -y install libxml2 libxml2-devel, install the corresponding plug-in, and so on

After all plug-ins are installed, execute again

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


(2) If you want to install the php-fpm function here, you need to install more plug-ins with yum, for example:

<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>


In which installphp-mcrypt When libmcrypt libmcrypt-devel, you may be prompted that the package cannot be found. In this case, you need to update the source to solve the problem. The specific command is as follows:

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

Among them, update was executed twice before it was successful, and then configure was executed again

./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过程

The above is the detailed content of How to install php on linux. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

How does PHP handle object cloning (clone keyword) and the __clone magic method?How does PHP handle object cloning (clone keyword) and the __clone magic method?Apr 17, 2025 am 12:24 AM

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP vs. Python: Use Cases and ApplicationsPHP vs. Python: Use Cases and ApplicationsApr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.