Nginx has been on the server and mysql, so I decided to use PHP + Nginx + mysql this combination, turned a lot of information on the Internet, because of linux and PHP does not understand, and do not know PHP and nginx mysql is how associated encountered For various reasons (not php installed wrong, the package is not installed,), spent a lot of time, and later discovered after deployment, these three are installed separately (also installed with the amount of ~ ~ do), you need only install php the latter configuration, the configuration nginx (associated, php) can run directly. As for mysql, just open, php projects which connect to the database configured, can be connected directly up. Therefore, this paper mainly for php installation.
About nginx and mysql installation, before starting the installation requires some linux development library is not installed in this retelling, which have reference links.
This article made reference to this link blog: https://www.cnblogs.com/flower-tree/p/7562101.html
php version: 5.6.31
nginx Version: 1.7.3
mysql Version: 5.6.62
PHP installation configuration
nginx itself can not handle PHP, it is just a WEB server, after receiving the request, if the request is php, it is sent to the interpreter process php, and the results returned to the client.
nginx fastcgi generally send the request to process management process, the management process selection cgi fastcgi child process and returns the processing result nginx.
What is PHP-FPM? PHP-FPM is a part of the PHP FASTCGI manager, only for PHP, the new version has integrated a php-fpm, php-fpm better php process management, can effectively control the memory and processes can smoothly overloaded php configuration . When configure, with -enable-fpm parameters to open php-fpm, other parameters can be seen here , as to what is fastcgi, and anything to do with php-fpm, refer to the link https://segmentfault.com/q/1010000000256516
Preparation Before Installation
Add epel source
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Installation depends
yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel yum -y install gcc gcc-c++ glibc yum -y install libmcrypt-devel mhash-devel libxslt-devel \ libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \ zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \ ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \ krb5 krb5-devel libidn libidn-devel openssl openssl-devel
Download php-5.6.31
1) The installation package to extract the / usr / local / src
cd /usr/local/src tar -zvxf php-5.6.31.tar.gz
2) into the installation directory, the installation
cd php-5.6.31 ./configure --prefix=/usr/local/php --enable-fpm --with-mcrypt \ --enable-mbstring --enable-pdo --with-curl --disable-debug --disable-rpath \ --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets \ --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex \ --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli \ --with-gd --with-jpeg-dir --with-freetype-dir --enable-calendar make && make install
CentOS download php: wget http://php.net/get/php-5.6.30.tar.gz/from/this/mirror
This completes the php-fpm installation, the installation process will take some time.
About php configuration
1, provides profiles for php
cp php.ini-production /usr/local/php/etc/php.ini
Note: php.ini-production or directory in the just /usr/local/src/php-5.6.31
2, the configuration file to provide php-fpm
cd /usr/local/php cp etc/php-fpm.conf.default etc/php-fpm.conf vim etc/php-fpm.conf
Modify the php-fpm.conf
user = www
group = www
If the www user does not exist, then add www first user (the default user to run nobody)
groupadd www
useradd -g www www
If this step is not configured, the browser will open the php file error
“The page you are looking for is temporarily unavailable. Please try again later”
3, start php-fpm
carried out
/usr/local/php/sbin/php-fpm
Use the following command to verify the positive (if the output of this command has several php-fpm start the process to explain the success):
ps to | grep php-fpm
The results as shown below:
3, nginx and php-fpm integration
Edit the nginx configuration file
vim /usr/local/nginx/conf/nginx.conf
Initial reads as follows:
# Nginx run username the User nginx; # nginx start the process, and usually set to equal the number of cpu, here is automatically worker_processes Auto; # errorlog file location error_log / var / log / nginx / error.log; # pid file address, nginx recorded the pid, facilitate process management pid / RUN / nginx.pid; . # dynamic modules See the load / usr / report this content share / nginx / . README.dynamic # is used to load other dynamic configuration module of the include / usr / report this content share / nginx / modules / * .conf; # mode of operation and the number of connections limit events { maximum number of concurrent links # worker_processes each of the total number of concurrent #: worker_processes * worker_connections worker_connections 1024; } # http and provide similar services related to some of the configuration parameters as well as mail HTTP { # Set the log format log_format main '$ REMOTE_ADDR - $ REMOTE_USER [$ time_local] "$ Request"' '$ Status $ body_bytes_sent "$ HTTP_REFERER"' ' "$ HTTP_USER_AGENT" "$ HTTP_X_FORWARDED_FOR"'; User # access_log record access, page, browser, ip, and other access information access_log /var/log/nginx/access.log main; # this section will explain below separately # set whether to use nginx sendfile function of the output file sendfile on; maximum packet # contract ( Nagle's algorithm) tcp_nopush ON; # immediately send packets (disable Nagle algorithm) TCP_NODELAY ON; # link timeout keepalive_timeout 65; # this I do not know ... types_hash_max_size 2048; # Import file extension and file type map /etc/nginx/mime.types the include; # Default file type default_type the Application / OCTET-Stream; . # Modular the Load at The /etc/nginx/conf.d from the Configuration Files Directory # See # default web root directory (www directory)http://nginx.org/en/docs/ngx_core_module.html #include # for More Information. the include /etc/nginx/conf.d/*.conf; support several virtual hosts # http service. # Each virtual host server corresponding to a configuration item # which contains configuration items associated with the virtual host configuration. Server { # port the listen the default_server 80; the listen [::]: 80 the default_server; domain # access server_name _; the root / usr / Share / Nginx / HTML; # The default for the Load Configuration Server Block Files. /etc/nginx/default.d/*.conf the include; # default request LOCATION / { } # error page (404) error_page 404 /404.html; LOCATION /40x.html = { } # error page (50X) error_page 500 /50x.html 503 504 502; LOCATION /50x.html = { } } }
We need to change the configuration of only server
part of it. Vim enter edit mode, or use FlashFXP configuration file to the desktop to share your changes.
You can only change three
{Server the listen 80 default_server; the listen [::]: 80 default_server; # change here, you can also write your domain name, I use the IP address server_name 192.168.0.222 ; root / usr / report this content share / nginx / HTML; # the Load files Configuration for . the default Server Block the include /etc/nginx/default.d / * .conf; LOCATION / { # name is defined herein altered the home index file index the index.php index.html index.htm; } error_page 404 / 404.html; LOCATION /40x.html = { } 500 502 503 504 /50x.html error_page; {LOCATION = /50x.html } # newly added here # PHP script request is forwarded to all protocol FastCGI FastCGI process using the default configuration.. # Fastcgi server and a program (PHP, Python) communication . agreement LOCATION ~ \ .php $ { # set listening port fastcgi_pass 127.0.0.1:9000; # script file that requests path fastcgi_param SCRIPT_FILENAME $ $ DOCUMENT_ROOT fastcgi_script_name; # fastcgi profile introduction the include fastcgi_params; } }
Restart nginx server
nginx -s reload
At this point, nginx and php have jointly completed the configuration, but we do not know how to effect the actual configuration, this time we can write a small test scripts to verify.
I mentioned earlier the / usr / share / nginx / html is Nginx web root directory, we can build a php test script in this directory.
# Phpinfo.php I want to create a file name
we /usr/share/nginx/html/phpinfo.php
After opening the editor, in which the input
<? PHP phpinfo (); // test information ?>
Save and exit, enter in your browser http://192.168.0.222/phpinfo.php, ip I have here is 192.168.0.222, you can replace your own. FIG screen appears similar to the following:
Nginx and php configuration have been completed.
4, the installation process wrong reasons
I press the install process, there has been a mistake: mcrypt.h not found Please reinstall libmcrypt.
Because php-mcrypt libmcrypt libmcrypt-devel These packages not installed, errors are generally missing libraries or packages can be installed.
PHP has been configured at this time, Zhu Junan installed successfully. Incidentally, in advance Happy New Year!