Nginx installation and configuration support for PHP tutorials (full) _nginx

Source: Internet
Author: User

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 that can smooth change php.ini configuration without restarting php-cgi download address: http://php-fpm.anight.org/
Note: The version of PHP will be consistent with the FPM version mysql-5.0.67.tar.gz
Discuz!_6.0.0_sc_utf8.zip

1. Installation Pcre

Copy Code code as follows:

# TAR-ZXVF Pcre-7.8.tar.gz
# CD pcre-7.8
#./configure
# Make && make install

2. Installation Nginx

Copy Code code as follows:

# 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 Nginxkill-hup ' Cat/usr/local/nginx/logs/nginx.pid '
Add to self-starter # echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local

3, install MySQL

Copy Code code as follows:

# 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 bootstrap:
#/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
To 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: #/usr/local/mysql/bin/mysql-u root-p Enter password: 123456, see if you can access to the database
To configure a library file search path:
# echo "/usr/local/mysql/lib/mysql" >>/etc/ld.so.conf
# Ldconfig
# ldconfig-v
Add/usr/local/mysql/bin to environment variable path
#echo "Export path= $PATH:/usr/local/mysql/bin" >>/etc/profile
#source/etc/profile

4. Install PHP

This produces an executable file, unlike Apache, where the combination of Apache creates a dynamic library

Copy Code code as follows:

# 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>
This machine will use the default 127.0.0.1

(2) The following two lines remove comments and modify
<value name= "Sendmail_path" >/usr/sbin/sendmail-t-i</value>
<value name= "Display_errors" >1</value>
(3) <value name= "user" >nobody</value>/to comment
(4) <value name= "group" >nobody</value>/To comment
(5) <value name= "allowed_clients" >127.0.0.1</value>//Allow connected PCs, 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 Linux nginx configuration file, support PHP

Copy Code code as follows:

# 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: The server section for the PHP virtual host 127.0.0.1:9000 for the fastcgi pc, I use this machine/var/www/blog$fastcgi_script_name; Directory test profile saved for PHP Web page:
#/usr/local/nginx/sbin/nginx-t

6, optimize the Linux kernel parameters
# vi/etc/sysctl.conf
Add the following at the end:

Copy Code code as follows:

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 configuration take effect immediately: #/sbin/sysctl-p.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.