


Detailed introduction to installing the php environment under Linux and configuring Nginx to support the php-fpm module (picture and text)
This article mainly introduces the detailed explanationLinuxInstallation PHP environment and configure Nginx to support the php-fpm module, which has certain reference value. Interested friends can refer to it.
The following takes CentOS 7.2 as an example to install the PHP operating environment. First open the PHP official website. Click Downloads in the navigation bar to enter the download page. Download the latest version of php 7.0.5 source code package here:
After downloadingupload to the server
Because PHP installation requires compilation, the server should ensure the installation of gcc and g++ environments
First release the installation package:
tar -xvzf php-7.0.5.tar.gz cd php-7.0.5
Next, configure the parameters. If there is no libxml2 and libxml2-devel will report an error, so you should update libxml2 and install libxml2-devel. Use online installation:
yum -y install libxml2 yum -y install libxml2-devel
Additionally, because of different operating system environments, the completeness of the system installation development environment package is also different, so it is recommended Make the necessary selections when installing the operating system. You can also execute all the commands at once to install the uninstalled components. If they are already installed, they may be upgraded. If the versions are exactly the same, no operations will be performed. The commands are except for the above two. In addition, the summary is as follows:
yum -y install openssl yum -y install openssl-devel yum -y install curl yum -y install curl-devel yum -y install libjpeg yum -y install libjpeg-devel yum -y install libpng yum -y install libpng-devel yum -y install freetype yum -y install freetype-devel yum -y install pcre yum -y install pcre-devel yum -y install libxslt yum -y install libxslt-devel yum -y install bzip2 yum -y install bzip2-devel
The above packages are basically enough. If you find any problems, please add them. After the installation is completed, execute the configuration:
The 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- mysql i --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-m hash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mb string --enable- opcache --enable-pcntl --enable-shmop --enable- soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip
Actually, there are more configuration items here than above. You can use the ./configure --help command to view all options. Note here that in php7, --with-mysql native support no longer exists, and the operations have become mysqli or pdo. ;The above options are completely sufficient for normal PHP development. If needed later, you can choose to manually open the corresponding module
and then perform compilation:
make
The compilation time may be a bit long, After the compilation is completed, perform the installation:
make install
The default installation location of php has been specified as /usr/local/php. Next, configure the corresponding file:
cp php.ini-development /usr/local/php/lib/php.ini cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf cp sapi/fpm/php-fpm /usr/local/bin
Then set php.ini, Use: vim /usr/local/php/lib/php.ini Open the php configuration file and find the cgi.fix_pathinfo configuration item. This item is commented by default and has a value of 1, according to According to the official document, this is to prevent Nginx from sending requests to the back-end PHP-FPM module when the file does not exist, thereby avoiding malicious script injection attacks, so this item should be uncommented and set to 0
After setting, save and exit
Another thing to note is that the location of the php.ini configuration file can be set in the pre-compile configuration parameters, and the compilation parameters can 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 this parameter is not added, the default location will be the lib directory under the PHP installation directory. , the details can also be viewed in the phpinfo() output interface. If php.ini is placed in other locations and PHP cannot read it, then all configuration modifications will not take effect. Please pay attention to this.
You should first create a web user:
groupadd www-data useradd -g www-data www-data
Then some online tutorials 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 After opening the file, the officially prompted location cannot be found:
If you add it in a random location at this time, then when you start php-fpm, the directory will be reported. error, so do not add users and groups in php-fpm.conf. At this time, go to the last line of php-fpm.conf and you will find the following content (if you add the --prefix option when compiling, the following The position will be automatically completed. The default is empty below, please note):
All conf configuration files in the php-fpm.d directory are introduced here, but NONE Need to be modified to our actual directory: /usr/local
By default, there is a configuration named www.conf.defalut under etc/php-fpm.d/ For the user's file, execute the following command to copy a new file and open it:
cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf vim /usr/local/etc/php-fpm.d/www.conf
The default user and group settings are nobody, change them to www-data
After the modification is completed, save and exit, then execute the following command to start the php-fpm service:
/usr/local/bin/php-fpm
After starting, the php-fpm service uses port 9000 by default. Use netstat -tln | grep 9000 to view the port. Usage:
9000端口正常使用,说明php-fpm服务启动成功
然后执行 vim /usr/local/nginx/nginx.conf
编辑nginx配置文件,具体路径根据实际的nginx.conf配置文件位置编辑,下面主要修改nginx的server {}配置块中的内容,修改location块,追加index.php让nginx服务器默认支持index.php为首页:
然后配置.php请求被传送到后端的php-fpm模块,默认情况下php配置块是被注释的,此时去掉注释并修改为以下内容:
这里面很多都是默认的,root是配置php程序放置的根目录,主要修改的就是fastcgi_param中的/scripts为$document_root
修改完上面的,回到nginx.conf第一行,默认是#user nobody; 这里要去掉注释改为user www-data;或者user www-data www-data;表示nginx服务器的权限为www-data
修改完这些保存并退出,然后重启nginx:
/usr/local/nginx/nginx -s stop /usr/local/nginx/nginx
接下来编辑一个测试的php程序,在nginx下的html目录下创建test.php文件,打印一下php配置:
<?php phpinfo(); ?>
然后打开浏览器输入对应的地址进行访问,看到输出页面,说明nginx和php都配置成功了:
相关文章:
The above is the detailed content of Detailed introduction to installing the php environment under Linux and configuring Nginx to support the php-fpm module (picture and text). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

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 is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

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.

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

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.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.
