nginx installation and configuration support php tutorial of full

  • 2020-05-06 12:17:35
  • OfStack

pcre 7.8. tar. gz   regular expressions to download address: ftp: / / ftp csx. cam. ac. uk/pub/software/programming pcre/ 
nginx - 0.7.26. Download address: tar http: / / www nginx. net/   
php - 5.2.6. tar. Download address: bz2 http: / / www php. net releases/ 
php-5.2.6-fpm-0.5.9.diff.gz  
Es39en-fpm is an FastCGI administrative patch for PHP that smoothen changes to the php.ini configuration without restarting the php-cgi download address: http:// php-fpm.anight.org/ 
Note: the PHP version should be the same as the fpm version. Es56en-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 Nginx


# tar -zxvf nginx-0.7.26.tar.gz  
# cd nginx-0.7.26  
# ./configure --prefix=/usr/local/nginx  
# make && make install
 Start the nginx# /usr/local/nginx/sbin/nginx  
 stop nginx# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid`  
 restart nginxkill -HUP `cat /usr/local/nginx/logs/nginx.pid`  
 Add to auto boot # 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 to the self-boot: 
# /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 automatic startup service queue: 
#chkconfig --add mysqld  
#chkconfig  --level  345  mysqld  on add root password   
# /usr/local/mysql/bin/mysqladmin -u root password "123456"  
 Test it out: # /usr/local/mysql/bin/mysql -u root -p Enter password: 123456 Let's see if we can get into the database 
 Configuration library file search path: 
# echo "/usr/local/mysql/lib/mysql">>/etc/ld.so.conf  
# ldconfig  
# ldconfig -v  
 add /usr/local/mysql/bin To environment variables PATH In the   
#echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile  
#source /etc/profile

4. Install PHP

This is an executable, not the same as apache, but the dynamic library
when combined with apache


# 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 < /value > Modified to < value name="listen_address" > IP:9000 < /value >  
// the default is 127.0.0.1  

(2) remove the comments and modify
in the following two lines < value name="sendmail_path" > /usr/sbin/sendmail -t -i < /value >
< value name="display_errors" > 1 < /value >
(3) < value name="user" > nobody < /value >     // go to  
(4) < value name="group" > nobody < /value >   // go to  
(5) < value name="allowed_clients" > 127.0.0.1 < /value >     // PC is allowed to connect, the machine USES 127.0.0.1
Start php fpm # / usr local/php/sbin/php - fpm start since the launch of added to # 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.abcdefg.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;  
includefastcgi_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: server part is PHP virtual host 127.0.0.1:9000 is PC fastcgi, the machine I used here is var/www/blog$fastcgi_script_name; Directory test profile saved for PHP web 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 = 500065000

Make the configuration effective immediately: # /sbin/ sysctl-p.


Related articles: