Install nginx
CentOS 7 has no built-in nginx, so first go to the nginx official website http://nginx.org/en/linux_packages.html#stable, find CentOS 7 nginx-release package File link, and then install the following
Rpm-Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
After installation, the repository settings of yum are automatically generated (in/etc/yum. repos. d/nginx. repo ),
Then you can use the yum command to install nginx
Yum install nginx
Start nginx
Previously, chkconfig was used to manage services. CentOS 7 switched to systemctl management system services.
Start Now
Systemctl start nginx
View current operation status
Systemctl status nginx
View the current startup settings of the nginx service
Systemctl list-unit-files | grep nginx
If it is disabled, it can be changed to boot automatically
Systemctl enable nginx
If you have set a strong fire prevention, check the strong fire protection running status and check whether the port used by nginx is enabled.
Firewall-cmd -- state
Enable http services with strong fire prevention
Firewall-cmd -- permanent -- zone = public -- add-service = http
Firewall-cmd -- reload
List the setting of strong public in fire prevention
Firewall-cmd -- list-all -- zone = public
After the preceding settings, you can use a browser to access the nginx preset page.
Install PHP-FPM
Use yum to install php, php-fpm, and php-mysql
Yum install php-fpm php-mysql
View the current startup settings of the php-fpm service
Systemctl list-unit-files | grep php-fpm
Change to automatic start upon startup
Systemctl enable php-fpm
Start Now
Systemctl start php-fpm
View current operation status
Systemctl status php-fpm
How to modify the PHP-FPM listen
If you want to change the PHP-FPM listen method to unix socket, you can edit/etc/php-fpm.d/www. conf
Set
Listen = 127.0.0.1: 9000
Change
Listen =/var/execute/php-fpm/php-fpm.sock
Then restart php-fpm.
Systemctl restart php-fpm
Note: do not change to listen =/tmp/php-fcgi.sock (set the php-fcgi.sock under/tmp) because when the system generates a php-fcgi.sock, will be placed in the/tmp/systemd-private-*/tmp/php-fpm.sock random private directory, unless you change PrivateTmp = true in/usr/lib/systemd/system/to PrivateTmp = false, other problems still occur, so it is most convenient to change the location.
Delete previous versions
# Yum remove php *
Install the yum source corresponding to Php7 in rpm
CentOS/RHEL 7.x:
# Rpm-Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm # rpm-Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
CentOS/RHEL 6.x:
# Rpm-Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
Install php7 in yum
Yum install php70w php70w-opcache
Install other plug-ins (optional)
Note: If pear is installed, the php70w-devel needs to be installed
Php70w
Php70w-bcmath
Php70w-cli
Php70w-common
Php70w-dba
Php70w-devel
Php70w-embedded
Php70w-enchant
Php70w-fpm
Php70w-gd
Php70w-imap
Php70w-interbase
Php70w-intl
Php70w-ldap
Php70w-mbstring
Php70w-mcrypt
Php70w-mysql
Php70w-mysqlnd
Php70w-odbc
Php70w-opcache
Php70w-pdo
Php70w-pdo_dblib
Php70w-pear
Php70w-pecl-apcu
Php70w-pecl-imagick
Php70w-pecl-xdebug
Php70w-pgsql
Php70w-phpdbg
Php70w-process
Php70w-pspell
Php70w-recode
Php70w-snmp
Php70w-soap
Php70w-tidy
Php70w-xml
Php70w-xmlrp
Compile and install php7
Configure, make, and install)
Use configure -- help
You must specify the prefix for compiling and installation. This is the installation directory, which limits all files to this directory. You only need to delete the directory when uninstalling the directory. If this parameter is not specified, it will be installed in many places, it is inconvenient to delete the backend.
Configuration: -- cache-file = FILE cache test results in FILE -- help print this message -- no-create do not create output files -- quiet, -- silent do not print 'checking... 'messages -- version print the version of autoconf that created configure Directory and file names: -- prefix = PREFIX install architecture-independent files in PREFIX [/usr/local] -- exec-prefix = EPREFIX install architecture-dependent files in EPREFIX
Note:
An error occurs when the memory is smaller than 1 GB. A line of content is added after the compilation parameter -- disable-fileinfo
Other configuration parameters
-- Exec-prefix = EXEC-PREFIX
You can install system-related files in a different location, instead of PREFIX settings. This allows you to easily share system-related files between different hosts.
-- Bindir = DIRECTORY
Specifies the executable program declaration directory, which defaults to EXEC-PREFIX/bin.
-- Datadir = DIRECTORY
Set the Directory of the read-only files required by the installed program. The default value is PREFIX/share.
-- Sysconfdir = DIRECTORY
Used for directories of various configuration files. The default value is PREFIX/etc.
-- Libdir = DIRECTORY
Library file and directory of the dynamic Mount module. The default is EXEC-PREFIX/lib
-- Includedir = DIRECTORY
Directory of the C and C ++ header files. The default value is PREFIX/include.
-- Docdir = DIRECTORY
Document files (except man (manual page) will be installed in this directory. The default is PREFIX/doc
-- Mandir = DIRECTORY
The manual page that comes with the program will be installed in this directory. In their corresponding manx subdirectories, the default is PREFIX/man.
Note: to reduce pollution to shared installation locations (such as/usr/local/include), configure automatically attaches a "/postgresql" string to datadir, sysconfdir, includedir, and docdir, unless the expanded directory name already contains the string "s S" or "pgsql ". for example, if you select/usr/local as the prefix, the header file of C will be installed in/usr/local/include/postgresql, but if the prefix is/opt/postgres, then they will be put into/opt/S/include
-- With-nodes des = DIRECTORIES
DIRECTORIES is a series of colon-separated DIRECTORIES that will be added to the compiler's header file search list. if you have some optional packages (such as GNU Readline) installed in a non-standard Huai location, you must use this option and possibly have the corresponding -- with-libraries option.
-- With-libraries = DIRECTORIES
DIRECTORIES is a series of colon-separated DIRECTORIES used to find library files. if you have some packages installed in a non-standard location, you may need to use this option (and the corresponding -- with-provided des option)
-- Enable-XXX
Open XXX support
-- With-XXX
Create XXX module
Php fpm settings reference
[Global]
Pid =/usr/local/php/var/run/php-fpm.pid
Error_log =/usr/local/php/var/log/php-fpm.log
[Www]
Listen =/var/execute/php-fpm/php-fpm.sock
User = www
Group = www
Pm = dynamic
Pm. max_children = 800
Pm. start_servers = 200
Pm. min_spare_servers = 100
Pm. max_spare_servers = 800
Pm. max_requests = 4000
Rlimit_files = 51200
Listen. backlog = 65536.
; The reason for setting 65536 is that-1 may not be unlimited
; Description http://php.net/manual/en/install.fpm.configuration.php#104172
Slowlog =/usr/local/php/var/log/slow. log
Request_slowlog_timeout = 10
Nginx. conf settings reference
User nginx;
Worker_processes 8;
Error_log/var/log/nginx/error. log warn;
Pid/var/run/nginx. pid;
Events {
Use epoll;
Worker_connections 65535;
}
Worker_rlimit_nofile 65535;
# If this parameter is not set, the following error may occur: 65535 worker_connections exceed open file resource limit: 1024.
Http {
Include/etc/nginx/mime. types;
Default_type application/octet-stream;
Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" "$ http_x_forwarded_for "';
Access_log/var/log/nginx/access. log main;
Sendfile on;
Tcp_nopush on;
Keepalive_timeout 65;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 32 k;
Large_client_header_buffers 4 32 k;
Client_max_body_size 8 m;
Server_tokens off;
Client_body_buffer_size 512 k;
# Fastcgi
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
Fastcgi_buffer_size 64 k;
Fastcgi_buffers 4 64 k;
Fastcgi_busy_buffers_size 128 k;
Fastcgi_temp_file_write_size 128 k;
Fastcgi_intercept_errors on;
# Gzip (description http://nginx.org/en/docs/http/ngx_http_gzip_module.html)
Gzip off;
Gzip_min_length 1 k; #1 k or more before compression
Gzip_buffers 32 4 k;
# Http://stackoverflow.com/questions/4888067/how-to-get-linux-kernel-page-size-programatically
# Use getconf PAGESIZE to obtain the system one memory page size,
Gzip_http_version 1.0;
Gzip_comp_level 2;
Gzip_types text/css text/xml application/javascript application/atom + xml application/rss + xml text/plain application/json;
# View the mime. types file of nginx (/etc/nginx/mime. types), which contains various types of definitions
Gzip_vary on;
Include/etc/nginx/conf. d/*. conf;
}
If an error occurs: setrlimit (RLIMIT_NOFILE, 65535) failed (1: Operation not permitted)
First, view the current system settings.
Ulimit-n
If the value is too small, modify/etc/security/limits. conf.
Vi/etc/security/limits. conf
Add or modify the following two rows
* Soft nofile 65535
* Hard nofile 65535