Centos7 source installation php7

Because php installation requires compilation, the server should ensure the installation of gcc and g++ environments

 1. First release the installation package:

tar -xvzf php-7.0.5.tar.gz
cd php-7.0.5

 2. 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, using online installation:

yum -y install libxml2
yum -y install libxml2-devel

 Because different operating system environments have different degrees of completeness of the system installation development environment package, it is recommended to make necessary choices when installing the operating system. You can also execute all the commands in a unified manner to install the components that are not installed. It may be upgraded if the version is completely consistent, and no operation will be performed if the version is exactly the same. Except for the above two commands, the summary is as follows:

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

  The above packages are basically enough. If you find any problems, add them. After the installation is complete, execute the configuration:

./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 the above. You can use the  ./configure --help command to view all options. Note that in php7, the --with-mysql native support no longer exists, and the operations have become mysqli or pdo; The above options are completely sufficient in normal php development. Later, if necessary, you can choose to manually open the corresponding module

 3. Then execute the compilation:

make

  The compilation time may be a bit long. After the compilation is completed, execute the installation:

make install

 4. The default installation location of php has been specified as /usr/local/php, and then configure the corresponding files:

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 cow/fpm/php-fpm /usr/local/bin

 5. 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, which is commented by default and has a value of 1, according to the official documentation , here in order to prevent Nginx from sending requests to the PHP-FPM module of the backend when the file does not exist, so as to avoid malicious script injection attacks, so this item should be uncommented and set to 0

  

  Save and exit after setting

 6. Another thing to note is that the location of the php.ini configuration file can be set in the configuration parameters before compilation. The compilation parameters can be written as: --with-config-file-path=/usr/local/php In this case, php will go back and specify Read the php.ini configuration file in the directory of php.ini. If you do not add this parameter, the default location is the lib directory under the php installation directory. You can also view it in the phpinfo() output interface. If php.ini is placed in another location, php reads If not, then all configuration modifications will not take effect, please pay attention to this

  At this point you should first create a web user:

groupadd www-data
useradd -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/php/etc/php-fpm.conf to open the file and can't find the location suggested by the official:

  

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

  

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

  

  By default, there is a file called www.conf.defalut under etc/php-fpm.d/ for configuring users. 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 complete, save and exit, and then execute the following command to start the php-fpm service:

/usr/local/bin/php-fpm

  After startup, the php-fpm service uses port 9000 by default. Use  netstat -tln | grep 9000 to view the port usage:

  

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

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

  

  Then the configuration.php request is sent to the php-fpm module on the backend. By default, the php configuration block is commented. At this time, remove the comment and modify it to the following:

  

 8. Many of them are default. root is the root directory where the php program is configured. 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 you need to remove the comment and change it to user www-data; or user www-data www-data; indicates that the authority of the nginx server is www-data

  After modifying these save and exit, then restart nginx:

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

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

<?php
    phpinfo();
?>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325168080&siteId=291194637