Because the production environment is FreeBSD platform, before also wrote a FreeBSD installation mysql5.1.70+php5.2.17 (FastCGI) + nginx1.0.1 high-performance Web server, there are children's shoes want to help write an article on the installation of CentOS under the tutorial, in fact, there are many online, but many are not too complete, more or less the emergence of some problems, so wrote a CentOS 5.5 under the installation mysql5.1.70+ php5.2.17 (FastCGI) +nginx1.0.1 High Performance Web server
In the case of high concurrent connections, Nginx is a good substitute for Apache servers. Nginx can also be used as a 7-tier load-balancing server. According to my test results, Nginx 1.2.7 + PHP 5.2.17 (FastCGI) can withstand more than 30,000 concurrent connections, equivalent to Apache 10 times times the same environment.
Step One: Install the software required by the system environment
| The code is as follows |
|
|
Yum install-y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-deve L zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel Curl curl-devel e2fsprogs E2 Fsprogs-devel krb5-libs krb5-devel krb5-server libidn libidn-devel OpenSSL openssl-devel openldap openldap-devel Nss_ LDAP openldap-clients Openldap-servers |
Step two: Compile the libraries you need to install PHP
| The code is as follows |
|
Mkdir-p/data/soft
Mkdir-p/DATA/SRC
Cd/data/src
wget http://lcmp.googlecode.com/files/libiconv-1.13.1.tar.gz
Tar zxvf libiconv-1.13.1.tar.gz
CD libiconv-1.13.1
./configure--prefix=/usr/local
Make && make install
Cd..
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
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.. /.. /
wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/download
Tar jxvf mhash-0.9.9.9.tar.bz2
CD mhash-0.9.9.9
./configure
Make && make install
echo "/usr/local/lib" >>/etc/ld.so.conf
/sbin/ldconfig
Cd..
wget http://vps.googlecode.com/files/mcrypt-2.6.8.tar.gz
Tar zxvf mcrypt-2.6.8.tar.gz
CD mcrypt-2.6.8
/sbin/ldconfig
./configure
Make && make install |
Step three: Compile and install MySQL
| The code is as follows |
|
|
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/ mysql-5.1.70.tar.gz/from/http://cdn.mysql.com/
tar zxvf mysql-5.1.70.tar.gz
CD mysql-5.1.70
/usr/sbin/groupadd mysql
/usr/sbin/useradd-g MySQL MySQL
/configure--prefix=/data/soft/mysql--enable-assembler--with-extra-charsets= Complex--enable-thread-safe-client--with-big-tables--with-readline--with-ssl--with-embedded-server-- Enable-local-infile
make && make install
chown-r mysql:mysql/ Data/soft/mysql
chmod u+w/data/soft/mysql
mkdir-p/data/database
& nbsp; chown-r mysql:mysql/data/database
|
Create a data table as a MySQL user account:
| The code is as follows |
|
|
/data/soft/mysql/bin/mysql_install_db--basedir=/data/soft/mysql--datadir=/data/database--user=mysql |
Creating a MySQL configuration file
| The code is as follows |
|
Rm-rf/data/soft/mysql/my.cnf
Vi/data/soft/mysql/my.cnf |
As follows:
| The code is as follows |
|
[Client]
Port = 3306
Socket =/tmp/mysql.sock
[MySQL]
No-auto-rehash
[Mysqld]
user = MySQL
Port = 3306
Socket =/tmp/mysql.sock
Basedir =/data/soft/mysql
DataDir =/data/database
Skip-name-resolve
Open_files_limit = 600
Back_log = 20
max_connections = 1000
Max_connect_errors = 200
Table_cache = 60
external-locking = FALSE
Max_allowed_packet = 16M
Sort_buffer_size = 128K
Join_buffer_size = 128K
Thread_cache_size = 10
Thread_concurrency = 8
Query_cache_size = 2M
Query_cache_limit = 2M
Query_cache_min_res_unit = 2k
Default_table_type = MyISAM
Thread_stack = 192K
Transaction_isolation = read-uncommitted
Tmp_table_size = 512K
Max_heap_table_size = 32M
Long_query_time = 1
Log_long_format
Server-id = 1
#log-bin =/data/soft/mysql/binlog
Binlog_cache_size = 2M
Max_binlog_cache_size = 4M
Max_binlog_size = 512M
Expire_logs_days = 7
Key_buffer_size = 4M
Read_buffer_size = 1M
Read_rnd_buffer_size = 2M
Bulk_insert_buffer_size = 2M
Myisam_sort_buffer_size = 4M
Myisam_max_sort_file_size = 10G
Myisam_max_extra_sort_file_size = 10G
Myisam_repair_threads = 1
Myisam_recover
[Mysqldump]
Quick
Max_allowed_packet = 16M |
Modify the Mysqld script
| The code is as follows |
Copy Code |
Cp/data/soft/mysql/share/mysql/mysql.server/etc/init.d/mysqld
Vi/etc/init.d/mysqld |
Modify
| The code is as follows |
|
Basedir=/data/soft/mysql
Datadir=/data/database
Ln-s/data/soft/mysql/my.cnf/etc/my.cnf |
Start MySQL
| The code is as follows |
|
|
Service mysqld Start
lsof-i:3306
NETSTAT-NTUPL |grep 3306 |
Test login MySQL
| The code is as follows |
|
/data/soft/mysql/bin/mysql-u root-p
mysql> CreateDatabase Hello;
Chkconfig--add mysqld
Chkconfig mysqld on
Chkconfig--list |grep mysqld
Service mysqld Restart |
Fourth step: Compile and install PHP (FastCGI)
1. Installation php-5.2.17
| The code is as follows |
|
Cd/data/src
wget Http://cn2.php.net/get/php-5.2.17.tar.gz/from/this/mirror
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
wget Http://www.92csz.com/downloads/php-5.2.17-max-input-vars.patch
Tar zxvf php-5.2.17.tar.gz
GZIP-CD php-5.2.17-fpm-0.5.14.diff.gz | Patch-d PHP-5.2.17-P1
CD php-5.2.17
Patch-p1 < ... /php-5.2.17-max-input-vars.patch
Sed-i "S/!png_check_sig (SIG, 8)/png_sig_cmp (SIG, 0, 8)/" Ext/gd/libgd/gd_png.c
Cp.. /FOPEN_WRAPPERS.C main/Here Reference FreeBSD php Modify source code to resolve Nginx virtual host Webshell Cross directory
./configure--prefix=/data/soft/php--with-config-file-path=/data/soft/php/etc--with-mysql=/data/soft/mysql-- With-mysqli=/data/soft/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--enable-inline-optimization--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-SASL--with-xmlrpc--enable-zip--enable-soap
Make zend_extra_libs= '-liconv '
Make install
CP Php.ini-dist/data/soft/php/etc/php.ini
Cd.. |
2, compile and install PHP5 expansion module
| The code is as follows |
|
wget http://pecl.php.net/get/memcache-2.2.6.tgz
Tar zxvf memcache-2.2.6.tgz
CD memcache-2.2.6/
/data/soft/php/bin/phpize
./configure--with-php-config=/data/soft/php/bin/php-config
Make && make install
Cd..
wget http://lcmp.googlecode.com/files/eaccelerator-0.9.6.1.tar.bz2
Tar jxvf eaccelerator-0.9.6.1.tar.bz2
CD EACCELERATOR-0.9.6.1/
/data/soft/php/bin/phpize
./configure--enable-eaccelerator=shared--with-php-config=/data/soft/php/bin/php-config-- Without-eaccelerator-use-inode
Make && make install
Cd..
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
Tar zxvf pdo_mysql-1.0.2.tgz
CD pdo_mysql-1.0.2
/data/soft/php/bin/phpize
./configure--with-php-config=/data/soft/php/bin/php-config--with-pdo-mysql=/data/soft/mysql
Make && make install
Cd..
wget http://launchpadlibrarian.net/73608965/ImageMagick-6.7.0-8.tar.gz
Tar zxvf imagemagick-6.7.0-8.tar.gz
CD imagemagick-6.7.0-8
./configure
Make && make install
Cd..
wget http://pecl.php.net/get/imagick-3.0.1.tgz
Tar zxvf imagick-3.0.1.tgz
CD imagick-3.0.1
/data/soft/php/bin/phpize
./configure--with-php-config=/data/soft/php/bin/php-config
Make && make install
Cd.. |
3. Modify php.ini File
| The code is as follows |
|
Sed-i "s/output_buffering = off/output_buffering = on/"/data/soft/php/etc/php.ini
Sed-i "S/extension_dir =/; Extension_dir =/"/data/soft/php/etc/php.ini
Sed-i "s/; Cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/"/data/soft/php/etc/php.ini
Sed-i ' s%;open_basedir =%open_basedir = '/tmp/:/data/www/'% '/data/soft/php/etc/php.ini
Sed-i "S/disable_functions =/disable_functions = Popen,pentl_exec,passthru,exec,system,scandir,chgrp,chown,shell_ Exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink, Popepassthru,stream_socket_server,show_source,escapeshellcmd,escapeshellarg,curl_exec,curl_multi_exec,parse_ ini_file,assert/"/data/soft/php/etc/php.ini
Sed-i "s/expose_php = on/expose_php = off/"/data/soft/php/etc/php.ini
Sed-i "s/display_errors = On/display_errors = off/"/data/soft/php/etc/php.ini
Sed-i "s/log_errors = Off/log_errors = on/"/data/soft/php/etc/php.ini |
At the end of the php.ini add the following:
| The code is as follows |
|
Extension_dir = "/data/soft/php/lib/php/extensions/no-debug-non-zts-20060613/"
Extension = "memcache.so"
Extension = "pdo_mysql.so"
Extension = "imagick.so"
[Eaccelerator]
zend_extension= "/data/soft/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
Eaccelerator.shm_size= "1"
Eaccelerator.cache_dir= "/data/soft/eaccelerator_cache"
eaccelerator.enable= "1"
Eaccelerator.optimizer= "1"
Eaccelerator.check_mtime= "1"
eaccelerator.debug= "0"
Eaccelerator.filter= ""
eaccelerator.shm_max= "0"
Eaccelerator.shm_ttl= "3600"
eaccelerator.shm_prune_period= "3600"
eaccelerator.shm_only= "0"
eaccelerator.compress= "1"
Eaccelerator.compress_level= "9"
Eaccelerator.keys = "Disk_only"
Eaccelerator.sessions = "Disk_only"
Eaccelerator.content = "Disk_only" |
4. Create Eaccelerator Cache Directory
| The code is as follows |
|
|
Mkdir-p/data/soft/eaccelerator_cache |
5. Create php-fpm.conf files
| The code is as follows |
|
|
Rm/data/soft/php/etc/php-fpm.conf
Vi/data/soft/php/etc/php-fpm.conf |
As follows:
| The code is as follows |
|
<?xml version= "1.0"?>
<configuration>
All relative paths in this config are relative to php ' s install prefix
<section name= "Global_options" >
Pid file
<value name= "Pid_file" >/data/soft/php/logs/php-fpm.pid</value>
Error log File
<value name= "Error_log" >/data/soft/php/logs/php-fpm.log</value>
Log level
<value name= "Log_level" >notice</value>
When this amount the PHP processes exited with SIGSEGV or sigbus ...
<value name= "Emergency_restart_threshold" >10</value>
... in a less than this interval of time, a graceful restart would be initiated.
Useful to work around accidental curruptions in accelerator ' s shared memory.
<value name= "Emergency_restart_interval" >1m</value>
Time limit on waiting child ' s reaction on signals from master
<value name= "Process_control_timeout" >5s</value>
Set to ' no ' to debug FPM
<value name= "Daemonize" >yes</value>
</section>
<workers>
<section name= "Pool" >
Name of Pool. Used in logs and stats.
<value name= "Name" >default</value>
Address to accept fastcgi requests on.
Valid syntax is ' ip.ad.re.ss:port ' or just ' port ' or '/path/to/unix/socket '
<value name= "Listen_address" >127.0.0.1:9000</value>
<value name= "Listen_options" >
Set Listen (2) backlog
<value name= "Backlog" >-1</value>
Set Permissions for UNIX sockets, if one used.
In Linux Read/write permissions must is set in order to allow connections from Web server.
Many bsd-derrived systems allow connections regardless of permissions.
<value name= "owner" ></value>
<value name= "group" ></value>
<value name= "mode" >0666</value>
</value>
Additional php.ini defines, specific to this pool of workers.
<value name= "Php_defines" >
<value name= "Sendmail_path" >/usr/sbin/sendmail-t-i</value>
<value name= "Display_errors" >1</value>
</value>
Unix User of processes
<value name= "User" >www</value>
Unix Group of processes
<value name= "group" >www</value>
Process Manager Settings
<value name= "PM" >
Sets style of controling worker process count.
Valid values are ' static ' and ' Apache-like '
<value name= "Style" >static</value>
Sets the limit on the number of simultaneous requests that'll be served.
Equivalent to Apache maxclients directive.
Equivalent to Php_fcgi_children environment in original php.fcgi
Used with any pm_style.
<value name= "Max_children" >8</value>
Settings Group for ' Apache-like ' pm style
<value name= "Apache_like" >
Sets the number of server processes created on startup.
Used ' Apache-like ' Pm_style is selected
<value name= "Startservers" >20</value>
Sets the desired minimum number of idle server processes.
Used ' Apache-like ' Pm_style is selected
<value name= "Minspareservers" >5</value>
Sets the desired maximum number of idle server processes.
Used ' Apache-like ' Pm_style is selected
<value name= "Maxspareservers" >35</value>
</value>
</value>
The timeout (in seconds) to serving a single request after the which the worker process would be terminated
Should be used as ' max_execution_time ' ini option does not stop script execution for some reason
' 0s ' means ' off '
<value name= "Request_terminate_timeout" >0s</value>
The timeout (in seconds) for serving of single request after which a PHP backtrace'll be dumped to Slow.log file
' 0s ' means ' off '
<value name= "Request_slowlog_timeout" >0s</value>
The log file for slow requests
<value name= "Slowlog" >logs/slow.log</value>
Set Open File desc rlimit
<value name= "Rlimit_files" >65535</value>
Set Max Core Size Rlimit
<value name= "Rlimit_core" >0</value>
Chroot to this directory at the start, absolute path
<value name= "Chroot" ></value>
Chdir to this directory at the start, absolute path
<value name= "ChDir" ></value>
Redirect workers ' stdout and stderr into main error log.
If not set, they'll be redirected to/dev/null, according to FastCGI specs
<value name= "Catch_workers_output" >yes</value>
How much requests each process should execute before respawn.
Useful to work around memory leaks at 3rd party libraries.
For endless request processing please specify 0
Equivalent to Php_fcgi_max_requests
<value name= "Max_requests" >1024</value>
Comma separated list of IPv4 addresses of FastCGI clients that allowed to connect.
Equivalent to Fcgi_web_server_addrs environment in original php.fcgi (5.2.2+)
Makes sense only with af_inet listening socket.
<value name= "Allowed_clients" >127.0.0.1</value>
Pass environment variables like Ld_library_path
<value name= "Environment" >
<value name= "PATH" >/usr/local/bin:/usr/bin:/bin</value>
<value name= "TMP" >/tmp</value>
<value name= "Tmpdir" >/tmp</value>
<value name= "TEMP" >/tmp</value>
<value name= "OSType" > $OSTYPE </value>
<value name= "Machtype" > $MACHTYPE </value>
<value name= "Malloc_check_" >2</value>
</value>
</section>
</workers>
</configuration> |
6. Create WWW user and start php-fpm and add startup script
| The code is as follows |
|
|
/usr/sbin/groupadd www
/usr/sbin/useradd-g www www
Mkdir-p/data/www
Chown-r www:www/data/www
chmod +w/data/www
Ulimit-shn 65535
/DATA/SOFT/PHP/SBIN/PHP-FPM start
echo "Ulimit-shn 65535" >>/etc/rc.local
echo "/data/soft/php/sbin/php-fpm start" >>/etc/rc.local |
Fifth step, compile and install Nginx-1.0.1
1, the installation of Nginx required Pcre Library
| The code is as follows |
Copy Code |
|
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
Tar zxvf pcre-8.21.tar.gz
CD pcre-8.21
./configure
Make && make install
Cd.. |
2. Installation Nginx
| The code is as follows |
|
wget http://nginx.org/download/nginx-1.2.7.tar.gz
Tar zxvf nginx-1.2.7.tar.gz
CD nginx-1.2.7
./configure--user=www--group=www--prefix=/data/soft/nginx--with-http_ssl_module--with-http_stub_status_module- -with-http_gzip_static_module--with-http_realip_module--with-http_dav_module--with-http_flv_module--with-http_ Addition_module--with-http_sub_module
Make && make install
Cd.. |
3. Create Nginx configuration file
| The code is as follows |
|
|
Rm-f/data/soft/nginx/conf/nginx.conf
Vi/data/soft/nginx/conf/nginx.conf |
As follows:
| The code is as follows |
|
|
User www www.
Worker_processes 1;
Error_log/data/soft/nginx/logs/error.log Crit;
Pid/data/soft/nginx/conf/nginx.pid;
#Specifies the value for maximum file descriptors the can is opened by this process.
Worker_rlimit_nofile 65535;
Events
{
Use Epoll;
Worker_connections 10240;
}
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;
Include Server/*.txt;
Server
{
Listen 80;
server_name default;
Index index.php;
Root/data/www/test;
Location ~. *. (PHP|PHP5)? $
{
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Include fastcgi.conf;
}
}
} |
4, start the Nginx and test
| The code is as follows |
|
|
/data/soft/nginx/sbin/nginx-t
/data/soft/nginx/sbin/nginx
Mkdir-p/data/www/test
echo "<?php phpinfo ();? > ">/data/www/test/index.php
echo "/data/soft/nginx/sbin/nginx" >>/etc/rc.local |