Hypertext Preprocessor, hypertext preprocessor. It is a scripting language executed on the server side, similar to C language. It is a commonly used website programming language.
After php is built, MySQLi Extension Library will be used to instantiate a MySQL connection object through MySQLi construction method, which is equivalent to establishing a connection. The subsequent code uses the object-oriented method entirely and uses the object's member functions to operate the MySQL database.
In this article, let's take a look at php architecture on RedHat 7.2~
1. Preparing installation package
Friendship Link php: https://www.php.net/downloads.php
2. Installation Dependence
# yum -y install pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel openldap-servers openldap-client nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel bzip2 bzip2-devel libxml2 libxml2-devel bzip2 bzip2-devel curl-devel gmp-devel readline-devel
3. Specify the directory and extract it
# tar zxvf php-7.1.30.tar.gz
4. Compiling
./configure \ --prefix=/usr/local/php \ --with-pdo-mysql=/opt/mysql \ --enable-mysqlnd \ --with-pdo-mysql=mysqlnd \ -with-mysqli=mysqlnd \ --with-mysql-sock=/tmp/mysql.sock \ --with-config-file-path=/usr/local/php \ --enable-fpm \ --enable-inline-optimization \ --disable-debug \ --disable-rpath \ --enable-shared \ --enable-soap \ --with-libxml-dir \ --with-xmlrpc \ --with-openssl \ --with-mhash \ --with-pcre-regex \ --with-sqlite3 \ --with-zlib \ --enable-bcmath \ --with-iconv \ --with-bz2 \ --enable-calendar \ --with-curl \ --with-cdb \ --enable-dom \ --enable-exif \ --enable-fileinfo \ --enable-filter \ --with-pcre-dir \ --enable-ftp \ --with-gd \ --with-openssl-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib-dir \ --with-freetype-dir \ --enable-gd-jis-conv \ --with-gettext \ --with-gmp \ --with-mhash \ --enable-json \ --enable-mbstring \ --enable-mbregex \ --enable-mbregex-backtrack \ --with-onig \ --enable-pdo \ --with-zlib-dir \ --with-pdo-sqlite \ --with-readline \ --enable-session \ --enable-shmop \ --enable-simplexml \ --enable-sockets \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-wddx \ --with-libxml-dir \ --with-xsl \ --enable-zip \ --with-pear \ --enable-opcache
At compilation time, there may be some other packages or tools that need to be installed because of different versions.~
5. Installation
[root@localhost php]# make && make install
6. Copy the php configuration file to the specified directory and optimize the command path
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# ln -s /usr/local/php/bin/ /usr/local/bin/
[root@localhost etc]# ln -s /usr/local/php/sbin/ /usr/local/sbin/
7. Adding Users
[root@localhost etc]# useradd -M -s /sbin/nologin php
[root@localhost etc]# id php
uid=1003(php) gid=1003(php) groups=1003(php)
8. Modify configuration files
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# vi www.conf
Modify the following parameters in www.conf
user = php #User php group = php #Group php pm.max_children = 50 # Maximum number of subprocesses that php-fpm can initiate pm.start_servers = 20 #Number of initial php-fpm processes in dynamic mode pm.min_spare_servers = 5 #Minimum number of php-fpm processes in dynamic idle state pm.max_spare_servers = 35 #The maximum number of php-fpm processes in dynamic idle state.
9. Start php-fpm
[root@localhost php-fpm.d]# /usr/local/php/sbin/php-fpm
10. View the php process
[root@localhost php-fpm.d]# pgrep php
View the port number:
[root@localhost php-fpm.d]# netstat -ntap | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 94154/php-fpm: mast
11. Connecting nginx with php
[root@localhost php-fpm.d]# cd /usr/local/nginx/conf/
[root@localhost conf]# vi nginx.conf
#Add index.php to identify the default home page location / { root html; index index.html index.htm index.php; } #Remove the following comment, where you need to change / scripts to $document_root, otherwise nginx returns to the blank page location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
12. Modify the default home page of nginx
[root@localhost conf]# cd ../html/
[root@localhost html]# pwd
/usr/local/nginx/html
[root@localhost html]# vi index.php
13. Restart nginx service
[root@localhost html]# /usr/local/nginx/sbin/nginx -s reload
Enter the Web Site View Page in the browser:
The following mysql extension modules are required:
14. Connecting database with php
[root@localhost html]# vi index.php
[root@localhost html]# cat index.php
<?php
$link=mysqli_connect('192.168.100.131','root','root');
if($link) echo "<h1>PHP-link-MySQL-chenlijian Success!</h1>";
else echo "<h1>PHP-link-false!</h1>";
?>
Refresh the page just now to show that the connection was successful!
Note: Errors occur during compilation: libxml2 configure: error: xml2-config not found. Please check your libxml2 installation.
The solution is: Yum install libxml 2-devel
Maybe there will be other wrapping errors, just put them on.~