1024programmer Nginx Install and configure Nginx and support php

Install and configure Nginx and support php

Before introducing Linux Nginx to you in detail, let everyone know about Linux Nginx first, and then introduce Linux in a comprehensive way
Nginx, I hope it is useful to everyone. Use Linux Nginx to build a high-performance web environment Linux Nginx (“engine x”)
It is a high-performance HTTP and reverse proxy server, and also an IMAP/POP3/SMTP proxy server. Linux Nginx is powered by
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
The source code is released under a BSD-like license.
Linux Nginx surpasses Apache’s high performance and stability, making domestic use of Linux Nginx as a Web server
There are also more and more websites on the server, including Sina Blog, Sina Podcast, NetEase News and other portal channels, Liujianfang, 56.com and other video sharing websites, Discuz! Official Forum, Shuimu Community and other well-known forums, Douban, YUPOO Emerging Web sites such as photo albums, domestic SNS, and Thunder Online
2.0 website.

Experimental environment
Centos4.5

pcre-7.8.tar.gz regular expression download address: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

nginx-0.7.26.tar download address: http://www.nginx.net/ 

php-5.2.6.tar.bz2 download address: http://www.php.net/releases/
php-5.2.6-fpm-0.5.9.diff.gz
php-fpm is a FastCGI management patch for PHP, which can smoothly change the php.ini configuration without restarting php-cgi download address: http://php-fpm.anight.org/

Note: The version of PHP should be consistent with the version of fpm mysql-5.0.67.tar.gz
Discuz!_6.0.0_SC_UTF8.zip

1. Install pcre
# tar -zxvf pcre-7.8.tar.gz
# cd pcre-7.8
# ./configure
# make && make install

2. Install Linux Nginx
# tar -zxvf nginx-0.7.26.tar.gz
# cd nginx-0.7.26
# ./configure –prefix=/usr/local/nginx
# make && make install
Start nginx# /usr/local/nginx/sbin/nginx
stop nginx# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid`

restart nginx kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

Add to autostart # echo “/usr/local/nginx/sbin/nginx”>>/etc/rc.local

3. Install mysql
# tar -zxvf mysql-5.0.67.tar.gz
# cd mysql-5.0.67
# groupadd mysql
# useradd -g mysql -s /sbin/nologin -M mysql

# ./configure –prefix=/usr/local/mysql –with-charset=gbk –with-extra-charset=all –enable-hread-safe-client
–enable-local-infile –with-low-memory
# make && make install
# cp support-files/my-medium.cnf /etc/my.cnf

# chown -R mysql.mysql /usr/local/mysql/

# /usr/local/mysql/bin/mysql_install_db –user=mysql
# chown -R root.root /usr/local/mysql/

# chown -R mysql.mysql /usr/local/mysql/var/
Start the database service and add it to self-start
# /usr/local/mysql/bin/mysqld_safe –user=mysql &

#cp support-files/mysql.server /etc/rc.d/init.d/mysqld

#chmod 755 /etc/rc.d/init.d/mysqld
Join the autostart service queue:
#chkconfig –add mysqld
#chkconfig –level 345 mysqld on add root password

# /usr/local/mysql/bin/mysqladmin -u root password “123456”

Test it: # /usr/local/mysql/bin/mysql -u root -p Enter the password: 123456 to see if you can enter the database
Configure library file search path
# echo “/usr/local/mysql/lib/mysql”>>/etc/ld.so.conf

# ldconfig
# ldconfig -v
Add /usr/local/mysql/bin to the environment variable PATH
#echo “export PATH=$PATH:/usr/local/mysql/bin”>>/etc/profile

#source /etc/profile

4. Install PHP
What is generated here is an executable file, which is different from apache. When combined with apache, a dynamic library is generated
# tar -jxvf php-5.2.6.tar.bz2
# gzip -cd php-5.2.6-fpm-0.5.9.diff.gz |patch -d php-5.2.6 -p1

# cd php-5.2.6
# ./configure –prefix=/usr/local/php –with-mysql=/usr/local/mysql –enable-fastcgi –enable-fpm

–with-config -file-path=/usr/local/php/etc –enable-force-cgi-redirect

# make && make install
# cp php.ini-recommended /usr/local/php/etc/php.ini

# vi /usr/local/php/php-fpm.conf
(1) <value name=”listen_address”127.0.0.1:9000 changed to <value strong> name=”listen_address”>IP:9000
//This machine uses the default 127.0.0.1
(2) Remove the comments and modify the following two lines

<value name=”sendmail_path”/usr/sbin/sendmail -t -i
<value name=”display_errors”1
(3)<value name=”user”nobody //Denote

(4)<value name=”group”nobody //Denote

(5)<value name=”allowed_clients”127.0.0.1 //Allowed connection PC, this machine is used 127.0.0.1
Start php-fpm# /usr/local/php/sbin/php-fpm start Add to self-start# echo
“/usr/local/php/sbin/php-fpm start”>>/etc/rc.local

5. Modify the configuration file of Linux Nginx to support PHP
# vi /usr/local/nginx/conf/nginx.conf
user nobody;
worker_processes 8;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 1024;
events
{use epoll;
worker_connections 1024;}
http{
include mime.types;

default_type application/octet-stream;
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;
server {
listen 80;
server_name www.bbb.com;
root /var/www/blog;
index index.html index.htm index.php;

location ~ .*\.(php|php5)?$ {
root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/blog$fastcgi_script_name;

include fastcgi_params;}

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 /var/logs/access.log access;}}
Note: The server part is the PHP virtual host 127.0.0.1:9000 is the PC of fastcgi, the local machine I use here is /var/www/blog$fastcgi_script_name;
Directory test configuration files saved for PHP pages:
# /usr/local/nginx/sbin/nginx -t

6. 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
net.ipv4.ip_local_port_range = 5000 65000
Make the configuration take effect immediately: # /sbin/sysctl -p.

e = 300
net.ipv4.tcp_synCOOKIEs = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000 65000
Make the configuration take effect immediately: # /sbin/sysctl -p.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/install-and-configure-nginx-and-support-php/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索