The most detailed process of installing php on linux

小云云
Release: 2023-03-20 21:18:02
Original
22482 people have browsed it

This article mainly shares with you the most detailed process of installing php on Linux. I have written the installation configuration of nginx before, followed by the installation of php and the installation of mysql. However, the time is limited, and it is too long to put it in one article, so it is all It is written separately. After PHP is installed, it is the configuration of MySQL.

1: Check whether php is installed

1) yum installation check: yum list installed | grep php

2) rpm installation check: rpm -qa | grep php

3) There are many ways to query if you compile and install it yourself, such as finding the executable program of php, or checking the process ps -ef | grep php and other methods.

Two: Check if php is not installed, you can prepare the pre-installation software before php installation. Use yum install xxxx to install it. Of course, you can compile and install it yourself if you don't mind the trouble. I won't go into details here.

1) zlib and zlib-devel zlib provides a data compression function library and is also the front-end software of nginx. Since zlib needs to compile the zlib extension of php, the zlib.h header file will need to be used during compilation. The header files are in zlib-devel, so zlib-devel also needs to be downloaded.

2) libxml2 and libxml-devel libxml2 is a c language xml library that can simply perform various operations on xml, and supports xpath query, and partially supports xslt conversion and other functions.

3) libxslt and libxslt-devel If you do not install libxslt-devel, you will be prompted that the xslt.config file cannot be found. xslt is an extension for converting xml to other formats.


3) openssl and openssl-devel secure socket layer password library

4) jpeg IJG's jpeg library, php's gd library required.

5) libpng is a relatively low-level cross-platform library written in C language for reading and writing png files. It can help easily read and write each line of pixels in png files. It is required by the gd library of PHP.

6) freetype and freetype-devel are free, open source and portable font engines that provide a unified interface to access multiple font formats. Both of these are dependent software of the gd library, so if they are not installed, or The version is too low. If you set the gd library to be installed when installing PHP, an error will be reported. In addition, if -devel is not installed, an error will be reported because the ft2build.h file will be missing when compiling the extension. The error is reported as shown below.


7) gd gd is an extension library for PHP to process graphics

8) curl, because the version in my yum is too low, So I compiled and installed it myself. The installation method is very simple, that is, wget curl downloads the address and decompresses the tar, creates a new /usr/local/curl folder, and then enters the curl decompressed folder to configure./configure --prefix=/ usr/local/curl is enough, and finally make and make install are installed.

Note: xxx-devel is the development package of xxx software, including header files, static libraries and even source code.

Three: PHP download and installation

1) Use wget to download the tar.gz file of PHP: wget http://br2.php.net/get/php-7.2.2.tar. gz

2) Unzip the tar.gz file: tar zxvf php-7.2.2.tar.gz

3) Create a new folder where php will be installed later: mkdir /usr/local/ php, and then enter the decompressed php installation package folder and configure configure:

./configure --prefix=/usr/local/php --with-curl=/usr/local/curl -- with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with- openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib - -enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable- soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip

Note:

--prefix=installation directory

--with-use package name [= package directory]

--enable-functions that need to be activated

Four: Configure php related files

1) Configure php.ini , this is the configuration file of php: cp /home/myload/php-7.2.2/php.ini-development /usr/local/php/lib/php.ini

2) Configure php-fpm. conf, this is the php-fpm configuration file: cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

3) Configuration www.conf, the user configuration file: cp etc/php-fpm.d/www.conf.default etc/php-fpm.d/www.conf

4) Copy the php-fpm startup file to A copy of the init.d folder is convenient for starting php: cp -R sbin/php-fpm /etc/init.d/php-fpm

5: Start php and confirm whether the installation is successful

Execute the command /etc/init.d/php-fpm

Check whether it is started: ps -ef |grep php You can see which processes have been started by php

6: Installation successful After configuring nginx to support php

1) Change the php.ini file, vim /usr/local/php/lib/php.ini

By searching for the configuration cgi.fix_pathinfo=1, removing the comments, and changing it to cgi.fix_pathinfo=0, this is not related to nginx’s support for php configuration, but a security vulnerability specific to php under nginx. If this is The value is 1. The user can upload the Trojan by uploading a picture, then access the picture address through the URL, and add /xxx.php after the address to run the picture as a php file. This is a problem that only exists in nginx. , neither apache nor iis has this problem

For the above questions, you can directly refer to Brother Niao’s blog, which is written in quite detail: http://www.laruence.com/2010/05/20/1495.html

2) Configure web-specific groups and users

Add the www user group: groupadd www

Add the user www under the www user group: useradd -g www www

3) Change the php-fpm.conf configuration

Remove the comment of user=nobody, and change nobody to the www user configured above

Remove the comment of group=nobody, and Change nobody to the www user group configured above

Finally check whether the last include value of php-fpm.conf is the correct www.conf directory address. If it is incorrect, change it to the correct directory address.

4) Change the www.conf configuration

Remove the comment of user=nobody, and change nobody to the www user configured above

Remove the comment of group=nobody , and change nobody to the www user group configured above

5) Change the nginx.conf file /etc/local/nginx/conf/nginx.conf

and remove the comment #user=nobody And change it to user=www

Remove the comments of location ~ \.php${...} and change /scripts in fastcgi_param to $document_root


Finally, add index.php after the default index in location/{...} to ensure that index.php is used as the default homepage


6) Restart php-fpm and nginx, you can killall php-fpm and then /etc/init.d/php-pfm to restart, /usr/local/nginx/sbin/nginx -s stop to stop nginx, and then execute /usr/local/nginx/sbin/php to restart.

7) Create a php file in the html directory, the content is phpinfo();, and then access the file address in the browser to see if the correct php related information is obtained. If it is displayed correctly, the configuration is successful. .

Seven: Cooperate with apache to support php, this will be added later, to be continue...

Related recommendations:

Linux installation php error record

Linux installation php module --with-mysql --with-mysqli Do you need to install mysql?

Linux installation php and memcache process record

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template