Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of installing php environment and configuring Nginx to support php-fpm module under Linux

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article "Linux installation php environment and configuration Nginx support php-fpm module method" article knowledge point most people do not understand, so Xiaobian to everyone summarized the following content, detailed content, clear steps, has a certain reference value, I hope you can read this article to gain, let's take a look at this article "Linux installation php environment and configuration Nginx support php-fpm module method" article bar.

Take centos 7.2 as an example, install php running environment, first open php official website and click downloads in the navigation bar to enter the download page:

Download the latest PHP 7.0.5 source package here:

Download and upload to the server

Because php installation needs to be compiled, the server should guarantee gcc and g++ environment installation

First release the installation package:

tar -xvzf php-7.0.5.tar.gzcd php-7.0.5

Next, configure the parameters. If there is no libxml2 and libxml2-devel before configuration, an error will be reported, so you should update libxml2 and install libxml2-devel. Use online installation:

yum -y install libxml2yum -y install libxml2-devel

Supplement, because different operating system environment, system installation development environment package integrity is not the same, so it is recommended to install the operating system to make the necessary choice, you can also uniformly execute all the commands, will not install the installed components, if installed may be upgraded, the version is completely consistent will not carry out any operation, except for the above two commands, summarized as follows:

yum -y install opensslyum -y install openssl-develyum -y install curlyum -y install curl-develyum -y install libjpegyum -y install libjpeg-develyum -y install libpngyum -y install libpng-develyum -y install freetypeyum -y install freetype-develyum -y install pcreyum -y install pcre-develyum -y install libxsltyum -y install libxslt-develyum -y install bzip2yum -y install bzip2-devel

These packages are basically enough. If you find any problems, add them. After installation, execute the configuration:

The copy code is as follows:

./ configure --prefix=/usr/local/php --with-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-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip

In fact, there are more configuration items here than above, you can use./ configure --help command to view all options, here note that in php7--with-mysql native support no longer exists, the operation has become mysqli or pdo; these options are completely sufficient in normal php development, later if necessary, you can choose to manually open the corresponding module

Then perform compilation:

make

Compilation time may be a bit long, after compilation is complete, perform installation:

make install

The default installation location for php has been specified above as/usr/local/php, so configure the corresponding file:

cp php.ini-development /usr/local/php/lib/php.inicp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confcp sapi/fpm/php-fpm /usr/local/bin

Then set php.ini, use: vim/usr/local/php/lib/php.ini to open the php configuration file and find the cgi.fix_pathinfo configuration item, which is commented by default and has a value of 1. According to the official documentation, in order to prevent nginx from sending requests to the php-fpm module on the backend when the file does not exist, so as to avoid malicious script injection attacks, this item should be removed and set to 0.

Set up, save and exit

Another thing to note is that the location of the php.ini configuration file can be set in the pre-build configuration parameters, which can be written as: --with-config-file-path=/usr/local/php In this case php will go back to the specified directory to read the php.ini configuration file. If you do not add this parameter, the default location is the lib directory under the php installation directory. You can also view the phpinfo() output interface. If php.ini is placed elsewhere, php cannot read it. Then all configuration modifications are not effective, this point should be noted

The first thing you should do is create a web user:

groupadd www-datauseradd -g www-data www-data

Then some tutorials on the Internet say to modify php-fpm.conf to add the users and groups created above. At this time, use vim /usr/local/etc/php-fpm.conf to open the file and cannot find the official prompt location:

If you add it in any position at this time, then when you start php-fpm next, you will report an error that the directory cannot be found, so don't add users and groups in php-fpm.conf. At this time, turn to the last line of php-fpm.conf and you will find the following content (if you add the--prefix option during compilation, the following positions will be automatically completed, the default is empty, note):

All conf configuration files in php-fpm.d directory are introduced here, but none needs to be modified to our actual directory: /usr/local

By default, etc/php-fpm.d/has a configuration user file named www.conf.defalut. Copy a new file and open it by executing the following command:

cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.confvim /usr/local/etc/php-fpm.d/www.conf

The default user and group settings are nobody, change them to www-data

When the modification is complete, save and exit, and then execute the following command to start the php-fpm service:

/usr/local/bin/php-fpm

After startup, php-fpm service defaults to port 9000, using netstat -tln| grep 9000 can view port usage:

Port 9000 is in normal use, indicating that php-fpm service is successfully started.

Then execute vim /usr/local/nginx/nginx.conf to edit the nginx configuration file. The specific path is edited according to the actual nginx.conf configuration file location. The following mainly modifies the contents of the nginx server {} configuration block, modifies the location block, and adds index.php to make the nginx server default support index.php as the home page:

The configuration.php request is then passed to the php-fpm module on the backend. By default, the php configuration block is commented, so remove the comment and modify it to read as follows:

Many of these are default, root is the root directory where the php program is placed, the main modification is that/scripts in fastcgi_param is $document_root

After modifying the above, go back to the first line of nginx.conf, the default is #user nobody; here, remove the comment and change it to user www-data; or user www-data www-data; indicating that the permissions of the nginx server are www-data.

After modifying these save and exit, then restart nginx:

/usr/local/nginx/nginx -s stop/usr/local/nginx/nginx

Next, edit a test php program, create a test.php file in the html directory under nginx, and print out the php configuration:

Then open the browser to enter the corresponding address to access, see the output page, indicating that nginx and php are configured successfully

The above is about "Linux php environment installation and configuration Nginx support php-fpm module method" The content of this article, I believe everyone has a certain understanding, I hope the content shared by Xiaobian is helpful to everyone, if you want to know more related knowledge content, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report