Centos 6.3/6.4/+ nginx + mysql5.5 + php5.3.14

Source: Internet
Author: User
Tags imagemagick mcrypt zts install perl openldap
1. Install the required software package yum-yinstallgccgcc-c ++ autoconflibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develzlibzlib-develglibcglibc-develglib2glib2-develbzip2bzip2-develncursesncurses-develcurl

1. install the required software package yum-y install gcc-c ++ autoconf libjpeg-devel libpng-devel freetype-devel libxml2 libxml2-devel zlib-devel glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses-devel curl

1. install required software packages
Yum-y install gcc-c ++ autoconf libjpeg-devel libpng-devel freetype-devel libxml2 libxml2-devel zlib-devel glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses- devel curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn-devel openssl-devel openldap-devel nss_ldap openldap-clients openldap-servers
Ii. Install the extension Library
1. Download libiconv
Wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
After the download is complete
Tar-zxvf libiconv-1.14.tar.gz & cd libiconv-1.14
./Configure -- prefix =/usr/local
Make & make install
2. Install libmcrypt
Wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz? R = http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/&ts=1304912647&use_mirror=nchc

After the download is complete
Tar-zxvf libmcrypt-2.5.8.tar.gz & cd libmcrypt-2.5.8
./Configure & make install
/Sbin/ldconfig & cd libltdl
./Configure -- enable-ltdl-install
Make & make install

3. Install mhash
Wget http://acelnmp.googlecode.com/files/mhash-0.9.9.9.tar.gz
After completion
Tar-zxvf mhash-0.9.9.9.tar.gz & cd mhash-0.9.9.9
./Configure & make install
4. Soft links
Ln-s/usr/local/lib/libmcrypt. la/usr/lib64/libmcrypt. la
Ln-s/usr/local/lib/libmcrypt. so/usr/lib64/libmcrypt. so
Ln-s/usr/local/lib/libmcrypt. so.4/usr/lib64/libmcrypt. so.4
Ln-s/usr/local/lib/libmcrypt. so.4.4.8/usr/lib64/libmcrypt. so.4.4.4.8
Ln-s/usr/local/lib/libmhash. a/usr/lib64/libmhash.
Ln-s/usr/local/lib/libmhash. la/usr/lib64/libmhash. la
Ln-s/usr/local/lib/libmhash. so/usr/lib64/libmhash. so
Ln-s/usr/local/lib/libmhash. so.2/usr/lib64/libmhash. so.2
Ln-s/usr/local/lib/libmhash. so.2.0.1/usr/lib64/libmhash. so.2.0.1
Ln-s/usr/local/bin/libmcrypt-config/usr/bin/libmcrypt-config

5. Install mcrypt
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/after finishing now/
./Configure & make install

Iii. Install MySQL
Wget http://downloads.skysql.com/archives/mysql-5.5/mysql-5.5.25.tar.gz
Tar-zxvf mysql-5.5.25.tar.gz
Cd mysql-5.5.25
/Usr/sbin/groupadd mysql
/Usr/sbin/useradd-g mysql-M-s/sbin/nologin mysql
To prevent the following error:

Cocould NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)

CMake Error at cmake/readline. cmake: 83 (MESSAGE ):

Curses library not found. Please install appropriate package,

Remove CMakeCache.txt and rerun cmake. On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.

First install:
Yum-y install ncurses-devel

Cmake-DCMAKE_INSTALL_PREFIX =/your_path/mysql /\

-DMYSQL_DATADIR =/yourpath/mysqldata /\

-DSYSCONFDIR =/etc/mysqld /\

-DDEFAULT_CHARSET = utf8 \

-DEXTRA_CHARSETS = all \

-DDEFAULT_COLLATION = utf8_general_ci \

-DWITH_EXTRA_CHARSETS: STRING = utf8, gbk, all \

-DWITH_MYISAM_STORAGE_ENGINE = 1 \

-DWITH_INNOBASE_STORAGE_ENGINE = 1 \

-DWITH_ARCHIVE_STORAGE_ENGINE = 1 \

-DWITH_MEMORY_STORAGE_ENGINE = 1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE = 1 \

-DWITH_FEDERATED_STORAGE_ENGINE = 1 \

-DWITH_PARTITION_STORAGE_ENGINE = 1 \

-DWITH_PERFSCHEMA_STORAGE_ENGINE = 1 \

-DWITH_READLINE = 1 \

-DENABLED_LOCAL_INFILE = 1 \

-DMYSQL_USER = mysql \

-DMYSQL_TCP_PORT = 3306 \

-DMYSQL_UNIX_ADDR =/yourpath/mysql/run/mysql. sock
Make & make install
Chmod + w/usr/local/mysql/
Chown-R mysql. mysql/usr/local/mysql/
Cd ..
/Your_install_path/mysql/bin/mysql_install_db -- basedir =/your_path/mysql -- datadir =/your_path/data -- user = mysql

Cp./support-files/mysql. server/etc/init. d/mysqld
Chkconfig -- add mysqld
Chmod u + x/etc/init. d/mysqld
Vi/etc/init. d/mysqld
Basedir =
Datadir =
Changed:
Basedir =/your_path/mysql
Datadir =/your_path/data

Conf =/etc/my. cnf
Changed:
Conf =/your_conf_path/my. cnf

Vi/usr/local/mysql/my. cnf
# Add the following content
[Client]
Character-set-server = utf8
Port = 3306
Socket =/tmp/mysql. sock

[Mysqld]
Character-set-server = utf8
Replicate-ignore-db = mysql
Replicate-ignore-db = test
Replicate-ignore-db = information_schema
User = mysql
Port = 3306
Socket =/tmp/mysql. sock
Basedir =/usr/local/mysql
Datadir =/data0/mysql/3306/data
Log-error =/data0/mysql/3306/mysql_error.log
Pid-file =/data0./mysql/3306/mysql. pid
Open_files_limit = 10240
Back_log = 600
Max_connections = 5000
Max_connect_errorrs = 6000
Table_cache = 614
External-locking = FALSE
Max_allowed_packet = 32 M
Sort_buffer_size = 1 M
Join_buffer_size = 1 M
Thread _ cache_size = 300
# Thread_concurrency = 8
Query_cache_size = 512 M
Query_cache_limit = 2 M
Query_cache_min_res_unit = 2 k
Default-storage-engine = MyISAM
Thread_stack = 192 K
Transaction_isolation = READ-COMMITTED
Tmp_table_size = 246 M
Max_heap_table_size = 246 M
Long_query_time = 3
Log-slave-updates
Log-bin =/data0/mysql/3306/binlog
Binlog_cache_size = 4 M
Binlog_format = MIXED
Max_binlog_cache_size = 8 M
Max_binlog_size = 1G
Relay-log-index =/data0/mysql/3306/relaylog
Relay-log-info-file =/data0/mysql/3306/relaylog
Relay-log =/data0/mysql/3306/relaylog
Expire_logs_days = 30
Key_buffer_size = 256 M
Read_buffer_size = 1 M
Read_buffer_size = 1 M
Read_rnd_buffer_size = 16 M
Bulk_insert_buffer_size = 64 M
Myisam_sort_buffer_size = 128 M
Myisam_max_sort_file_size = 10G
Myisam_repair_threads = 1
Myisam_recover

Interactive_timeout = 120
Wait_timeout = 120

Skip-name-resolve
# Master-connect-retry = 10
Slave-skip-errors = 1396

# Master-host = 192.168.1.2
# Master-user = username
# Master-password = password
# Master-ports = 3306

Server-id = 1

Innodb_additional_mem_pool_size = 16 M
Innodb_buffer_pool_size = 512 M
Innodb_data_file_path = ibdata1: 256 M: autoextend
Innodb_file_io_threads = 4
Innodb_thread_concurrency = 8
Innodb_flush_log_at_trx_commit = 2
Innodb_log_buffer_size = 16 M
Innodb_log_file_size = 128 M
Innodb_log_files_in_group = 3
Innodb_max_dirty_pages_pct = 90
Innodb_lock_wait_timeout = 120
Innodb_file_per_table = 0

# Log-slow-queries =/data0/mysql/3306/slow. log
# Long_query_time = 10

[Mysqldump]
Quick
Max_allowed_packet = 32 M


Start MySQL
Service mysqld start

4. install PHP and extensions

1. install php
The 64-bit operating system first copies LDAP and runs the following command:
Cp/usr/lib64/libldap */usr/lib/

Tar jxvf php-5.3.14.tar.bz2 & cd php-5.3.14
./Configure -- prefix =/usr/local/php \
-- With-iconv-dir =/usr/local \
-- With-freetype-dir \
-- With-mysql =/usr/local/mysql \
-- With-mysqli =/usr/local/mysql/bin/mysql_config \
-- With-jpeg-dir \
-- With-png-dir \
-- With-zlib \
-- With-mhash \
-- Enable-sockets \
-- Enable-ftp \
-- With-libxml-dir \
-- Enable-xml \
-- Disable-rpath \
-- Enable-safe-mode \
-- Enable-bcmath \
-- Enable-shmop \
-- Enable-sysvsem \
-- Enable-inline-optimization -- with-curl \
-- With-curlwrappers \
-- Enable-mbregex \
-- Enable-mbstring \
-- With-mcrypt \
-- With-gd \
-- Enable-gd-native-ttf \
-- With-openssl \
-- With-mhash \
-- Enable-pcntl \
-- Enable-sockets \
-- With-ldap \
-- With-ldap-sasl \
-- Enable-fpm \
-- With-xmlrpc \
-- Enable-zip \
-- Enable-soap \
-- Without-pear

Make ZEND_EXTRA_LIBS = '-liconv'
Make install
Cp php. ini-production/usr/local/php/etc/php. ini

2. Install the PHP extension module
Wget http://vps.googlecode.com/files/memcache-2.2.5.tgz
Tar zxvf memcache-2.2.5.tgz & cd memcache-2.2.5
/Usr/local/php/bin/phpize
./Configure--- with-php-config =/usr/local/php/bin/php-config
Make & make install
Cd ../


Wget http://acelnmp.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
/Usr/local/php/bin/phpize
./Configure -- enable-eaccelerator = shared -- with-php-config =/usr/local/php/bin/php-config
Make & make install
Cd ../

Wget http://vps.googlecode.com/files/PDO_MYSQL-1.0.2.tgz
Tar zxvf PDO_MYSQL-1.0.2.tgz & cd PDO_MYSQL-1.0.2
/Usr/local/php/bin/phpize
./Configure -- with-php-config =/usr/local/php/bin/php-config -- with-pdo-mysql =/usr/local/mysql
Make & make install
Cd ../

# Install perl-CPAN first to prevent the following errors:
Yum-y install perl-CPAN
The error is as follows:
Perl/usr/lib/perl5/usr/share/perl5.) at Makefile. PL line 24.
BEGIN failed -- compilation aborted at Makefile. PL line 24.
Make [1]: *** [PerlMagick/Makefile] Error 2
Make [1]: Leaving directory '/data0/software/ImageMagick-6.5.1-2'
Make: *** [all] Error 2


Wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
Tar zxvf ImageMagick.tar.gz & cd ImageMagick-6.5.1-2
./Configure
Make & make install
Cd ../


Wget http://pecl.php.net/get/imagick-3.1.0RC2.tgz
Tar zxvf imagick-3.1.0.tgz & cd imagick-3.1.0
/Usr/local/php/bin/phpize
./Configure -- with-php-config =/usr/local/php/bin/php-config
Make & make install
Cd ../

3. Modify the php. ini file

Sed-I's # extension_dir = ". /"# extension_dir ="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"\ nextension =" memcache. so "\ nextension =" pdo_mysql.so "\ nextension =" imagick. so "\ n # '/usr/local/php/etc/php. ini
Sed-I's # output_buffering = Off # output_buffering = On # '/usr/local/php/etc/php. ini
Sed-I "s #; always_populate_raw_post_data = On # g"/usr/local/php/etc/php. ini
Sed-I "s #; cgi. fix_pathinfo = 0 # cgi. fix_pathinfo = 0 # g"/usr/local/php/etc/php. ini

4. Configure eAccelerator Acceleration
Mkdir/your/path/
Vi/usr/local/php/etc/php. ini
Add the following content at the end:
[Eaccelerator]
Zend_extension = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator. so"
Eaccelerator. shm_size = "64"
Eaccelerator. cache_dir = "/data0/mysql/3306/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"

5. Create users, groups, and virtual directories
/Usr/sbin/groupadd www
/Usr/sbin/useradd-g www
Mkdir/data0/www/html-p
Chmod + w/data0/www/html/& chown www. www/data0/www/html/-R

Cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
6/usr/local/php/etc/php-fpm.conf
Remove the following comments
Pm. max_children = 64
Pm. start_servers = 20
Pm. min_spare_servers = 5
Pm. max_spare_servers = 35
Pm. max_requests = 1024
User = www
Group = www

Test
/Usr/local/php/sbin/php-fpm-t
If the following message is displayed, the operation is successful.
NOTICE: configuration file/usr/local/php/etc/php-fpm.conf test is successful
Start
/Usr/local/php/sbin/php-fpm &

5. Install Nginx

1. Install pcre
Wget http://nchc.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.tar.gz
Tar zxvf pcre-8.10.tar.gz & cd pcre-8.10
./Configure
Make & make install
Cd ..

Wget http://nginx.org/download/nginx-0.8.46.tar.gz
Tar zxvf nginx-0.8.46.tar.gz & cd nginx-0.8.46
./Configure -- user = www -- group = www -- prefix =/usr/local/nginx -- with-http_stub_status_module -- with-http_ssl_module
Make & make install
Cd ../
Create a log storage directory
Mkdir/data0/logs
Chmod + w/data0/logs/& chown www. www/data0/logs/
Vi/usr/local/nginx/conf/nginx. conf
# Add the following content
User www;

Worker_processes 8;

Error_log/data0/logs/nginx_error.log crit;

Pid/usr/local/nginx. pid;

# Specifies the value for maximum file descriptors that can be opened by this process.
Worker_rlimit_nofile 65535;

Events
{
Use epoll;
Worker_connections 65535;
}

Http
{
Include mime. types;
Default_type application/octet-stream;

# Charset gb2312;

Server_names_hash_bucket_size 128;
Client_header_buffer_size 32 k;
Large_client_header_buffers 4 32 k;
Client_max_body_size 8 m;

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 64 k;
Fastcgi_buffers 4 64 k;
Fastcgi_busy_buffers_size 128 k;
Fastcgi_temp_file_write_size 128 k;

Gzip on;
Gzip_min_length 1 k;
Gzip_buffers 4 16 k;
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 10 m;

Server
{
Listen 80;
Server_name test.com;
Index index.html index.htm index. php;
Root/data0/www/html;

# 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;
Fcinclude gi. conf;
}

Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $
{
Expires 30d;
}

Location ~ . * \. (Js | css )? $
{
Expires 1 h;
}

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/data0/logs/access. log access;
}


Server
{
Listen 80;
Server_name status.test.com;

Location /{
Stub_status on;
Access_log off;
}
}
}

Vi/usr/local/nginx/conf/fcgi. conf
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;

Start Nginx
/Usr/local/nginx/sbin/nginx
Add to auto-start
/Usr/local/nginx/sbin/nginx
/Usr/local/php/sbin/php-fpm


Vi. kernel Optimization

Vi/etc/sysctl. conf
######################################## #########################
#
# Optimizing Kernel Parameters
#
######################################## #########################
# Add the following:
# Maximum number of packets that can be sent to the queue when each network interface receives packets faster than the kernel processes these packets;
Net. core. netdev_max_backlog = 32768

# By default, the backlog of the linten function in the web application will limit the net. core. somaxconn of kernel parameters to 128.
# NGX_LISTEN_BACKLOG the default value is 511, so it is necessary to adjust this value;
Net. core. somaxconn = 32768

Net. core. wmem_default = 8388608
Net. core. rmem_default = 8388608
Net. core. rmem_max = 16777216
Net. core. wmem_max = 16777216

# Timestamp can avoid serial number winding. A 1 Gbps link will certainly encounter a previously used serial number. The timestamp can make the kernel accept this "exception"
#. You need to disable the data packet here.
Net. ipv4.tcp _ timestamps = 0

# In order to enable the peer connection, the kernel needs to send a SYN with an ACK that responds to the previous SYN, that is, the second handshake in the three-way handshake.
#. This setting determines the number of SYN + ACK packets sent before the kernel disconnects;
Net. ipv4.tcp _ synack_retries = 2

# Number of SYN packets sent before the kernel is abandoned;
Net. ipv4.tcp _ syn_retries = 2

# When a SYN wait queue overflows, cookies are enabled to prevent a small number of SYN attacks. The default value is 0, indicating that the process is disabled;
Net. ipv4.tcp _ syncookies = 1

# Enable quick collection of TIME_WAIT scokets in TCP connections. The default value is 0, indicating that the collection is disabled;
Net. ipv4.tcp _ tw_recycle = 1

# Net. ipv4.tcp _ tw_len = 1

# Allow TIME-WAIT sockets to re-use the new TCP connection. The default value is 0, indicating that the TCP connection is disabled;
Net. ipv4.tcp _ tw_reuse = 1

Net. ipv4.tcp _ mem = 94500000 915000000 927000000
Net. ipv4.tcp _ max_orphans = 3276800

# Default TIMEOUT time;
# Net. ipv4.tcp _ fin_timeout = 30
# The frequency of sending keeplive messages over TCP when keeplive is in use. The default value is 2 hours, which can be changed to 2 minutes;
# Net. ipv4.tcp _ keepalive_time = 1200

# Indicates the port range used for external connection. The default value is 32768--61000, Which is changed to 1024--65000.
Net. ipv4.ip _ local_port_range = 1024 65535

# Indicates the length of the SYN queue. The default value is 1024, which is increased to 65536 to accommodate more network connections waiting for connection;
Net. ipv4.tcp _ max_syn_backlog = 65536

# The system maintains the maximum number of TIME_WAIT instances at the same time. If this number is exceeded, TIME_WAIT is immediately cleared and the warning is printed,
# The default value is 180000, Which is changed to 5000. For servers such as Apache and Nginx, the parameters in the previous lines can greatly reduce the number of TIME_WAIT sockets,
# Squid is ineffective. This parameter can control the maximum number of TIME_WAIT instances to avoid the Squid server being overloaded by a large number of TIME _
# WAIT dragging;
Net. ipv4.tcp _ max_tw_buckets = 5000

Vi/etc/security/limits. conf
# Add the following content
* Soft nofile 65536
* Hard nofile 65536

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.