In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to set up a high-performance WEB server in Linux+Nginx+Php". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "Linux+Nginx+Php how to set up a high-performance WEB server".
Nginx ("engine x") is a high-performance http and reverse proxy server, as well as an imap/pop3/smtp proxy server. Nginx was developed by igor sysoev for the second most visited rambler.ru site in Russia, where it has been running for more than two and a half years. Igor publishes the source code as a bsd-like license. Although it is still a beta, nginx is already known for its stability, rich feature set, sample configuration files, and low system resource consumption.
Installation steps
1. Compile and install the support libraries needed for php5.2.9
Tar zxvf libiconv-1.13.tar.gz
Cd libiconv-1.13/
. / configure-- prefix=/usr/local
Make
Make install
Cd.. /
Tar zxvf libmcrypt-2.5.8.tar.gz
Cd libmcrypt-2.5.8/
. / configure
Make
Make install
/ sbin/ldconfig
Cd libltdl/
. / configure-- enable-ltdl-install
Make
Make install
Cd.. /.. /
Tar zxvf mhash-0.9.9.9.tar.gz
Cd mhash-0.9.9.9/
. / configure
Make
Make install
Cd.. /
Ln-s / usr/local/lib/libmcrypt.la / usr/lib/libmcrypt.la
Ln-s / usr/local/lib/libmcrypt.so / usr/lib/libmcrypt.so
Ln-s / usr/local/lib/libmcrypt.so.4 / usr/lib/libmcrypt.so.4
Ln-s / usr/local/lib/libmcrypt.so.4.4.8 / usr/lib/libmcrypt.so.4.4.8
Ln-s / usr/local/lib/libmhash.a / usr/lib/libmhash.a
Ln-s / usr/local/lib/libmhash.la / usr/lib/libmhash.la
Ln-s / usr/local/lib/libmhash.so / usr/lib/libmhash.so
Ln-s / usr/local/lib/libmhash.so.2 / usr/lib/libmhash.so.2
Ln-s / usr/local/lib/libmhash.so.2.0.1 / usr/lib/libmhash.so.2.0.1
Tar zxvf mcrypt-2.6.8.tar.gz
Cd mcrypt-2.6.8/
/ sbin/ldconfig
. / configure
Make
Make install
Cd.. /
II. Compile and install the mysql 5.1.34 extension library
/ usr/sbin/groupadd mysql
/ usr/sbin/useradd-g mysql mysql
Tar zxvf mysql-5.1.34.tar.gz
Cd mysql-5.1.34/
/ configure-- prefix=/usr/local/webserver/mysql/-- enable-assembler-- with-extra-charsets=complex-- enable-thread-safe-client-- with-big-tables-- with-readline-- with-ssl-- with-embedded-server-- enable-local-infile-- with-plugins=innobase
Make & & make install
Chmod + w / usr/local/webserver/mysql
Chown-r mysql:mysql / usr/local/webserver/mysql
Cd.. /
The installation of mysql is omitted here
3. Compile and install php (fastcgi mode)
Tar zxvf php-5.2.9.tar.gz
Gzip-cd php-5.2.9-fpm-0.5.10.diff.gz | patch-d php-5.2.9- p1
Cd php-5.2.9/
/ configure-- prefix=/usr/local/webserver/php-- with-config-file-path=/usr/local/webserver/php/etc-- with-mysql=/usr/local/webserver/mysql-- with-mysqli=/usr/local/webserver/mysql/bin/mysql_config-- with-iconv-dir=/usr/local-- with-freetype-dir-- with-jpeg-dir-- with-png-dir-- with-zlib-- with-libxml-dir=/usr-- enable-xml-- disable- Rpath-- enable-discard-path-- enable-safe-mode-- enable-bcmath-- enable-shmop-- enable-sysvsem-- with-curl-- with-curlwrappers-- enable-mbregex-- enable-fastcgi-- enable-fpm-- enable-force-cgi-redirect-- enable-mbstring-- with-mcrypt-- with-gd-- enable-gd-native-ttf-with-openssl-- with-mhash-- enable-pcntl-- enable-sockets-- with-ldap--with-ldap-sasl
Make zend_extra_libs='-liconv'
Make install
Cp php.ini-dist / usr/local/webserver/php/etc/php.ini
Cd.. /
IV. Modify the php-fpm configuration file
Rm-f / usr/local/webserver/php/etc/php-fpm.conf
Vi / usr/local/webserver/php/etc/php-fpm.conf
Enter the following:
/ usr/local/webserver/php/logs/php-fpm.pid
/ usr/local/webserver/php/logs/php-fpm.log
Notice
ten
1m
5s
Yes
Default
127.0.0.1:9000
-1
0666
/ usr/sbin/sendmail-t-I
one
Www
Www
Static
one hundred and twenty eight
twenty
five
thirty-five
0s
0s
Logs/slow.log
51200
0
Yes
five hundred
127.0.0.1
$hostname
/ usr/local/bin:/usr/bin:/bin
/ tmp
/ tmp
/ tmp
$ostype
$machtype
two
5. Create www user groups and www users
/ usr/sbin/groupadd www
/ usr/sbin/useradd-g www www
VI. Compile and install nginx
Tar zxvf nginx-0.6.35.tar.gz
Cd nginx-0.6.35/
Default installation:
. / configure
Make & & make install
By default, nginx is installed in / usr/local/nginx. You can change this setting by setting compilation options.
Specify compilation options to install, such as:
. / configure-user=www-group=www-prefix=/usr/local/webserver/nginx-with-http_stub_status_module-with-http_ssl_module
Make & & make install
Cd.. /
7. Create fcgi.conf file
Rm-f / usr/local/webserver/nginx/conf/fcgi.conf
Vi / usr/local/webserver/nginx/conf/fcgi.conf
Enter the following:
Fastcgi_param gateway_interface cgi/1.1
Fastcgi_param server_software nginx
Fastcgi_param query_string $query_string
Fastcgi_param request_method $request_method
Fastcgi_param content_type $content_type
Fastcgi_param content_length $content_length
Fastcgi_param script_filename $document_root$fastcgi_script_name
Fastcgi_param script_name $fastcgi_script_name
Fastcgi_param request_uri $request_uri
Fastcgi_param document_uri $document_uri
Fastcgi_param document_root $document_root
Fastcgi_param server_protocol $server_protocol
Fastcgi_param remote_addr $remote_addr
Fastcgi_param remote_port $remote_port
Fastcgi_param server_addr $server_addr
Fastcgi_param server_port $server_port
Fastcgi_param server_name $server_name
# php only, required if php was built with-- enable-force-cgi-redirect
Fastcgi_param redirect_status 200
8. Edit the nginx configuration file
Rm-f / usr/local/webserver/nginx/conf/nginx.conf
Vi / usr/local/webserver/nginx/conf/nginx.conf
Enter the following:
User www www
Worker_processes 8
Error_log / usr/local/webserver/nginx/logs/logs/nginx_error.log crit
Pid / usr/local/webserver/nginx/logs/nginx.pid
Worker_rlimit_nofile 51200
Events {
Use epoll
Worker_connections 51200
}
Http {
Include mime.types
Default_type application/octet-stream
Charset utf-8
Server_names_hash_bucket_size 128
Client_header_buffer_size 32k
Large_client_header_buffers 4 32k
Client_max_body_size 8m
Sendfile on
Tcp_nopush on
Keepalive_timeout 60
Tcp_nodelay on
Fastcgi_connect_timeout 300
Fastcgi_send_timeout 300
Fastcgi_read_timeout 300
Fastcgi_buffer_size 64k
Fastcgi_buffers 8 64k
Fastcgi_busy_buffers_size 128k
Fastcgi_temp_file_write_size 128k
Gzip on
Gzip_min_length 1k
Gzip_buffers 4 16k
Gzip_http_version 1.0
Gzip_comp_level 2
Gzip_types text/plain application/x-javascript text/css application/xml
Gzip_vary on
# limit_zone crawler $binary_remote_addr 10m
# multiple site settings. Site folders must be placed in the html directory of nginx, otherwise multi-sites are not supported
Server {
Listen 80
Server_name www.v-ec.com
Root / usr/local/webserver/nginx/html/www.v-ec.com
Index index.php index.html
Location. *\. (php | php5)? ${
# fastcgi_pass unix:/tmp/php-cgi.sock
Fastcgi_pass 127.0.0.1:9000
Fastcgi_index index.php
Include fcgi.conf
}
Location. *\. (gif | jpg | jpeg | png | bmp | swf) ${
Expires 30d
}
Location. *\. (js | css)? ${
Expires 6h
}
Log_format veclog'$remote_addr-$remote_user [$time_local] "$request"'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent" $http_x_forwarded_for'
Access_log logs/vec.log veclog
}
# multiple site settings. Site folders must be placed in the html directory of nginx, otherwise multi-sites are not supported
Server {
Listen 80
Server_name www.w3cgroup.com
Root / usr/local/webserver/nginx/html/www.w3cgroup.com
Index index.php index.html
Location. *\. (php | php5)? ${
# fastcgi_pass unix:/tmp/php-cgi.sock
Fastcgi_pass 127.0.0.1:9000
Fastcgi_index index.php
Include fcgi.conf
}
Location. *\. (gif | jpg | jpeg | png | bmp | swf) ${
Expires 30d
}
Location. *\. (js | css)? ${
Expires 6h
}
Log_format w3cclog'$remote_addr-$remote_user [$time_local] "$request"'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent" $http_x_forwarded_for'
Access_log logs/w3c.log w3clog
}
}
9. Configure to boot nginx + php automatically.
Vi / etc/rc.local
Add the following at the end:
Ulimit-shn 51200
/ usr/local/webserver/php/sbin/php-fpm start
/ usr/local/webserver/nginx/sbin/nginx
Optimize linux kernel parameters
Vi / etc/sysctl.conf
Add the following at the end:
Net.ipv4.tcp_fin_timeout = 30
Net.ipv4.tcp_keepalive_time = 300
Net.ipv4.tcp_syncookies = 1
Net.ipv4.tcp_tw_reuse = 1
Net.ipv4.tcp_tw_recycle = 1
Make the configuration effective immediately:
/ sbin/sysctl-p
If you do this, you can restart linux by reboot. If nothing happens, you should be able to start nginx smoothly.
Smooth restart of nginx
Ps aux | grep nginx
Find the master process of nginx, if: 5800, and then kill
Kill-hup 5800
Smooth restart of php
/ usr/local/webserver/php/sbin/php-fpm restart
Other commands of php-fpm: start | stop | quit | restart | reload | logrotate
At this point, I believe you have a deeper understanding of "Linux+Nginx+Php how to set up a high-performance WEB server". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.