Nginx+php (FastCGI)+Memcached+MySQL+APC is the current mainstream way to build high-performance servers! Suitable for large and medium-sized websites, small webmasters can also use this combination!
Nginx surpasses Apache in high performance and stability, and more and more domestic websites use Nginx as a web server, including the largest domestic electronic map MapBar, Sina Blog, Sina Podcast, NetEase News and other portal channels, six rooms , 56.com and other video sharing websites, Discuz! Well-known forums such as official forums and Shuimu Community, emerging Web 2.0 websites such as Douban, YUPOO Photo Album, Domestic SNS, and Thunder Online, and more websites are using Nginx configuration.
Download the required installation package: Here we use the source code package to compile and install: This blog integrates the download
http://wgkgood.gicp.net/download/nginx-0.7.61.tar.gz
http://wgkgood.gicp.net/download/pcre-8.01.tar.gz
http://wgkgood.gicp.net/download/memcache-2.2.5.tgz
http://wgkgood.gicp.net/download/libevent-1.4.12-stable.tar.gz
http://wgkgood.gicp.net/download/APC-3.1.4.tgz
Download to /usr/src
There are also two packages mysql-5.1.41.tar.gz and php-5.3.5.tar.gz [Other similar versions are also available! 】Can be downloaded from the official website.
1. Officially install Nginx. [Before installing nginx, you need to install the pcre package and zlib to support rewriting, regularization, web page compression, etc.]
cd /usr/src
tar xzf pcre-8.01.tar.gz
cdpcre-8.01
./configure –PRefix=/usr/local/pcre
make
make install
(2), and then install nginx:
useradd www && cd /usr/src && tar xzf nginx-0.7.61.tar.gz &&cd nginx-0.7.61 && ./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-openssl=/usr / –with-pcre=/usr/src/pcre-8.01 –user=www –group=www &&make &&make install
[nginx note* –with-pcre=/usr/src/pcre-8.01 points to the path to decompress the source code package, not the installation path, otherwise it will report
make[1]: ***[/usr/local/pcre/Makefile] Error 127 Error】
2. Next install mysql
cd /usr/src && tar xzf mysql-5.1.41.tar.gz && cd mysql-5.1.41 && ./configure –prefix=/usr/local/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
(2) After mysql is installed, create the mysql user and group, initialize the database, and start the database.
cd /usr/local/mysql && useradd mysql && chown -R mysql:mysql /usr/local/mysql && /usr/local/mysql/bin/mysql_install_db –user=mysql && chown -R mysql:mysql var/ && ./ bin/mysqld_safe –user=mysql &
That’s it. [If an error occurs when mysql starts, please check the /usr/local/mysql/var directory to see if mysql has permissions]
3. Install php:
cd /usr/src &&tar xzf php-5.3.5.tar.gz && cd php-5.3.5 && ./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/ php/etc –with-mysql=/usr/local/mysql –with-mysqli=/u
sr/local/mysql/bin/mysql_config –with-iconv-dir=/usr/local –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-li
bxml-dir=/usr –enable-xml –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem
–enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fpm –enable-sockets && make &&make install
Installation completed! [Note that –enable-fastcgi does not need to be added to this parameter here; other previous versions need to add it. The above installation can be added according to your own choice. If an error is reported, find the reason according to the specific error report]
4. Integrate Nginx and php (FastCGI) to support fastCGI after installing php-5.3.5
user www www;
worker_processes 8;
error_log /usr/local/logs/nginx/error.log crit;
pid /usr/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
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 4 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;
server
{
listen 80;
server_name wgkgood.gicp.net;
index index.php index.htm index.html;
root /usr/webapps/www;
#limit_conn crawler 20;
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 1h;
}
log_format access '$remote_addr – $remote_user [$time_local] “$request” '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /usr/local/logs/nginx/access.log access;
}
}
Nginx configuration completed! Start nginx; /usr/local/nginx/sbin/nginx. The command to restart nginx is as follows /usr/local/nginx/sbin/nginx –s reload
This configuration file is for reference only, thank you Teacher Zhang Yan!
(2) Configure the fcgi.conf file as follows
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;
5. Configure the php configuration file:
cd /usr/local/php5/etc/ && cp php-fpm.conf.default php-fpm.conf
Then modify the options in php-fpm.conf according to the prompts.
After the configuration is complete, start php-fpm
The following cp /usr/src/php-5.3.5/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
Then start /etc/init.d/php-fpm start.
6. Install apc configuration:
cd /usr/src && tar xzf APC-3.1.4.tgz &&cd APC-3.1.4
/usr/local/php5/bin/phpize
./configure –enable-apc –enable-apc-mmap –with-php-config=/usr/local/php5/bin/php-config
&&make&& make install
After installation, an apc.so will be generated in /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/.
7. Install memcached so that fastcGI supports memcached
First install libevent,
cd /usr/src && tar xzf libevent-1.4.12-stable.tar.gz && cd libevent-1.4.12-stable && ./configure –prefix=/usr/local/libevent &&make && make install
Then install memcached
tar xzf memcache-2.2.5.tar.gz && cd memcache-2.2.5 && /usr/local/php5/bin/phpize && ./configure –prefix=/usr/local/memcached –with-libevent=/usr/ local/libevent –with-php-config=/usr/local/php5/bin/php-config &&make &&make install
After installation, a memcache.so module will be generated in /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/:
8. Next modify php.ini
The default php.ini is in /usr/local/php5/lib/php.ini. You can also specify:
extension_dir = "./"
Modify to
extension_dir=”/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626″
Add the following to the end:
extension=apc.so
extension=memcache.so //The cache module is referenced here
[APC]
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 64M
apc.optimization=1
apc.num_files_hint = 0
apc.ttl=7200
apc.user_ttl=7200
apc.gc_ttl = 3600
apc.cache_by_default = on
The installation is now complete!
Restart nginx and php-fpm and access it with the test page.
This article is for reference only! Please correct me if there are any inaccuracies! Learn together!
Article source: http://blog.mgcrazy.com/?p=627 Please indicate the source link when reprinting