Lnmp environment setup, detailed tutorial

Source: Internet
Author: User
Tags mcrypt zts openldap

| Install various dependent packages

Yum-y install

GCC gcc-C ++ Autoconf automake bison flex FreeType-devel fontconfig-devel gettext-devel libjpeg-devel libpng-devel libxml2 libxml2-devel libtool-ltdl tool lib- ltdl-devel LibTIFF -devel libxpm-devel libicu-devel libidn-devel libxslt-devel zlib-devel glibc-devel glib2 glib2-devel kernel bzip2-devel ncurses-devel curl-devel kernel e2fsprogs-devel Kernel krb5-devel OpenSSL-devel OpenLDAP openldap-devel nss_ldap openldap-clients openldap-servers PCRE-devel Pam-devel vim-enhanced mysql-devel

 

| Other dependent packages that need to be compiled for source code Installation

Libivonv

Wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

Tar-xzvf libiconv-1.14.tar.gz

./Configure

Make & make install

 

Libmcrypt

Wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/old/libmcrypt-2.5.7.tar.gz

Tar-xzvf libmcrypt-2.5.7.tar.gz

./Configure

Make & make install

/Sbin/ldconfig

CD libltdl/

./Configure -- enable-ltdl-install

Make

Make install

 

Mhash

Wget http://ncu.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2

Tar-xjvf mhash-0.9.9.9.tar.bz2

./Configure

Make

Make install

CD ../

Ln-S/usr/local/lib/libmcrypt. [la | so | so.4 | so.4.4.8]/usr/lib/libmcrypt. [la | so | so.4 | so.4.4.8]

Ln-S/usr/local/lib/libmhash. [A | la | so | so.2 | so.2.0.1]/usr/lib/libmhash. [A | la | so | so.2 | so.2.0.1]

/Sbin/ldconfconfig

 

Mcrypt

Wget http://ncu.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz

Tar-xzvf mcrypt-2.6.8.tar.gz

./Configure

Make

Make install

 

 

| Compile and install MySQL

 

| Compile and install PHP fast-CGI Mode

Wget http://cn2.php.net/distributions/php-5.2.17.tar.bz2

Tar-xjvf php-5.2.17.tar.bz2

Wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz

Gzip-CD php-5.2.17-fpm-0.5.14.diff.gz | patch-D php-5.2.17-P1 (Here is the number 1, Non-lLowercase)

CD php-5.2.17/

. /Configure -- prefix =/usr/local/PHP -- With-config-file-Path =/usr/local/PHP/etc -- With-mysql =/usr/local/MySQL -- with-mysqli =/usr/local/MySQL/bin/mysql_config -- With-iconv-Dir =/usr/-- 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-Gd -- enable-Gd-native-TTF -- With-OpenSSL -- With-mhash -- enable-pcntl -- enable-sockets -- With-LDAP =/usr -- With-LDAP-sasl -- With-XMLRPC -- enable-zip -- enable-soap -- without-Pear

 

# Add the zend_extra_libs = '-liconv' parameter during make because the iconv library is required during compilation, but it is not written to makefile during Configure. Another method is to directly modify makefile, add-liconv to the Link Library (which should be around 100 rows)

Make zend_extra_libs = '-liconv'

Make install

Cp php. ini-Dist/usr/local/PHP/etc/PHP. ini

 

| Compile and install PHP extensions

| Memcache

| Install the dependency package libevent

1. Yum install libevent

2. wget http://cloud.github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gz

Tar-xzvf libevent-1.4.14b-stable.tar.gz

CD libevent-1.4.14b-stable

./Configure-Prefix =/usr/local/libevent

Make & make install

 

| Wget http://memcached.googlecode.com/files/memcached-1.4.10.tar.gz

Tar-xzvf memcached-1.4.10.tar.gz

CD memcached-1.4.10

./Configure -- prefix =/usr/local/memcached -- With-libevent =/usr/local/libevent

Make

Make install

 

| Wget http://lcmp.googlecode.com/files/memcache-2.2.6.tgz

Tar-xzvf memcache-2.2.6.tgz

CD memcache-2.2.6

/Usr/local/PHP/bin/phpize

./Configure -- prefix =/usr/local/memcache -- With-PHP-Config =/usr/local/PHP/bin/PHP-config -- enable-memcache

Make

Make install

The following prompt is displayed after the installation is successful:

Installing shared extensions:/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20060613/

 

Modify the php. ini file

Vim/usr/local/PHP/etc/PHP. ini

Extension_dir = "./" è extension _ DIR = "/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20060613"

Extension = "memcache. So"

 

| Install eaccelerator

| Eaccelerator is a free and open source PHP accelerator. It optimizes and dynamically caches content, improves the cache performance of PHP scripts, and enables PHP scripts to be compiled, the server overhead is almost completely eliminated. It also optimizes scripts to accelerate execution efficiency. Improves PHP code execution efficiency by 1-10 times

| Eaccelerator caches compiled PHP code to the shared memory and calls the Code directly during user access to accelerate the process efficiently. It is highly efficient, and the process from creating shared memory to searching compiled code is completed in a very short time. For files and code that cannot be cached into the shared memory, the eaccelerator can also cache them to the system disk.

| Eaccelerator only supports PHP installed using mod_php or FastCGI Mode

Wget http://nchc.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.zip

Unzip eaccelerator-0.9.6.1.zip

CD eaccelerator-0.9.6.1

/Usr/local/PHP/bin/phpize

./Configure -- prefix =/usr/local/eaccelerator -- enable-eaccelerator = shared -- With-PHP-Config =/usr/local/PHP/bin/PHP-config

Make

Make install

The following prompt is displayed after the installation is successful:

Installing shared extensions:/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20060613/

Then, modify the php. ini file:

Vim/usr/local/PHP/etc/PHP. ini

Find extension_dir and add

Extension = "eaccelerator. So"

Configure eaccelerator to accelerate PHP:

[Eaccelerator]

Zend_extension = "/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20060613/eaccelerator. So"

Eaccelerator. shm_size = "16" # shared memory settings, in MB. The default value is 0.

Eaccelerator. cache_dir = "/tmp/eaccelerator" # cache directory

Eaccelerator. Enable = "1" # enable or disable eaccelerator, 1 = on, 0 = off; default value: 1

Eaccelerator. optimizer = "1" # enable or disable the internal optimizer. The default value is 1.

Eaccelerator. check_mtime = "1" # Start or close the PHP file modification check. The default value is 1.

Eaccelerator. DEBUG = "0" # enable or disable high Logging

Eaccelerator. Filter = "" # determine which PHP files must be cached. You can specify the cached and non-cached file types (for example, "*. php *. phtml"). If the parameter is set "! ", Files matching these parameters are ignored. The default value is ""; that is, all PHP files will be cached.

Eaccelerator. shm_max = "0" # when using the "eaccelerator_put ()" function, it is prohibited to store excessive files in the shared memory. This parameter specifies the maximum value that can be stored, in bytes (10240, 10 K, 1 m ). "0" is unlimited. The default value is "0 ".

Eaccelerator. shm_ttl = "0" # When the eaccelerator fails to obtain the shared memory size of the new script, it will delete all script caches that have not been accessed in the last "shm_ttl" seconds from the shared memory. The default value is "0". That is, no cached files are deleted from the shared files in the spring.

Eaccelerator. prune_period = "0" # When eaccelerator fails to obtain the shared memory size of the new script, it will try to delete the cache script earlier than "shm_prune_period" from the shared memory. The default value is "0". That is, no cached files are deleted from the shared files in the spring.

Eaccelerator. shm_only = "0" # Allow or disable caching compiled scripts on disks. This option is invalid for session data and content caching. The default value is "0", that is, cache with disk and shared memory.

Eaccelerator. Compress = "1" # Allow or disable content caching. The default value is "1", that is, compression is allowed.

Eaccelerator. compress_level = "9" # specify the compression level of the content cache. The default value is 9, which is the highest level.

Eaccelerator. Keys = "disk_only"

Eaccelerator. Session = "disk_only"

Eaccelerator. content = "disk_only"

### Set the content cache storage location:

Shm_and_disk in shared cache and hard disk (default)

SHM has shared memory by default. If the shared memory is full or the size exceeds the value of "eaccelerator. shm_max", it is saved to the hard disk.

Shm_only is stored only in the shared memory.

Disk_only is stored on the hard disk

None

 

Eaccelerator. allowed_admin_path = "/var/www/html/21andy.com/eaccelerator"

### This is a control in the control panel address installation package. PHP: You can copy it to any directory on the website and use it to view and manage it. This must be specified. Otherwise, an error occurs when you view the cached content.

 

| Configure PHP-FPM

Nginx + PhP requires PHP to generate executable files. Therefore, FastCGI technology should be used to integrate nginx with PHP. This is as long as FastCGI is enabled for installation. here, we use PHP-FPM to manage FastCGI (PHP-FPM has been added to PhP as a patch ).

Edit the configuration file:

Vim php-fpm.conf.

About 63 rows. Remove the corresponding comments and specify the user for FastCGI. You can use the default nobody or specify it separately.

 

UNIX user of processes

<Value name = "user"> nobody </value>

 

UNIX group of processes

<Value name = "group"> nobody </value>

 

 

 

| Start the PHP-CGI process

Ulimit-shn 65535

/Usr/local/PHP/sbin/PHP-FPM start

 

####

| Ulimit [-acdfhlmnpsstvw] [size]
Parameter introduction:
-H: Set hardware resource limits.
-S: Set software resource limits.
-A: displays all current resource limits.
-C size: sets the maximum value of the core file. Unit: Blocks
-D size: sets the maximum value of the data segment. Unit: Kbytes
-F size: sets the maximum value of the file to be created. Unit: Blocks
-L size: sets the maximum value of the locked process in the memory. Unit: Kbytes
-M size: sets the maximum value of resident memory that can be used. Unit: Kbytes
-N size: sets the maximum value of the file descriptor that the kernel can open at the same time. Unit: N
-P size: sets the maximum value of the MPs queue buffer. Unit: Kbytes
-S size: sets the maximum value of the stack. Unit: Kbytes
-T size: sets the maximum CPU usage time. Unit: seconds
-V Size: sets the maximum value of virtual memory. Unit: Kbytes 5, simple instance:

 

 

 

| Compile and install nginx

Wget http://nginx.org/download/nginx-1.0.10.tar.gz

Tar-xzvf nginx-1.0.10.tar.gz

CD nginx-1.0.10

./Configure -- prefix =/usr/local/nginx -- with-http_stub_status_module -- with-http_ssl_module

Make

Make install

 

| Nginx. conf configuration

# User nobody;

Worker_processes 1;

 

# Error_log logs/error. log;

# Error_log logs/error. Log notice;

# Error_log logs/error. Log Info;

 

# PID logs/nginx. PID;

 

Worker_rlimit_nofile 65535;

Events {

Use epoll;

Worker_connections 1024;

}

 

 

HTTP {

Include mime. types;

Default_type application/octet-stream;

 

Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'

'$ Status $ body_bytes_sent "$ http_referer "'

'"$ Http_user_agent" "$ http_x_forwarded_for "';

 

# Access_log logs/access. Log main;

# Charset utf8;

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;

Tcp_nodelay on;

# Keepalive_timeout 0;

Keepalive_timeout 65;

 

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 9;

Gzip_types text/plain application/X-JavaScript text/CSS application/XML;

Gzip_vary on;

 

Server {

Listen 80;

SERVER_NAME localhost;

# Charset koi8-r;

Access_log logs/localhost. Access. Log main;

Root HTML;

Index index.html index.htm index. php;

# Configure nginx to support PHP

Location ~ . * \. (PhP | PhP5 )? $

{

# Fastcgi_pass Unix:/tmp/php-cgi.sock;

Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_index index. php;

Include FastCGI. conf;

}

# Cache Images

Location ~ . * \. (GIF | JPG | JPEG | PNG | BMP | SWF) $

{

Expires 30d;

}

# Cache JS/CSS related information

Location ~ . * \. (JS | CSS )? $

{

Expires 1 h;

}

# Error_page 404/404 .html;

# Redirect server error pages to the static page/50x.html

#

Error_page 500 502 503 x.html;

Location =/50x.html {

Root HTML;

}

}

}

 

| FastCGI. conf configuration (do not modify the content of this file)

Fastcgi_param script_filename $ document_root $ fastcgi_script_name;

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_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 gateway_interface cgi/1.1;

Fastcgi_param server_software nginx/$ nginx_version;

 

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;

 

| Start nginx

/Usr/local/nginx/sbin/nginx

 

| Configure nginx + PHP-FPM to start upon startup

Vim/etc/rc. Local

Add at the end:

Ulimit-shn 65535

/Usr/local/PHP/sbin/PHP-FPM start

/Usr/local/nginx/sbin/nginx

Save and exit

 

| Smoothly change the nginx configuration without stopping the nginx Service

After modifying the configuration file nginx. conf, run the following command to check whether the configuration file is correct:

/Usr/local/nginx/sbin/nginx-T

If the following message is displayed, the modification is successful:

 

Nginx: the configuration file/usr/local/nginx/CONF/nginx. conf syntax is OK

Nginx: configuration file/usr/local/nginx/CONF/nginx. conf test is successful

 

 

Run the following command to view the nginx master process number:

PS aux | grep "nginx: Master process" | grep-V "grep" | awk '{print $2 }'

Or

CAT/usr/local/nginx/logs/nginx. PID

After finding the main process number, run the following command to make the configuration file take effect:

Kill-HUP master process number

Or

Kill-HUP 'ps aux | grep "nginx: Master process" | grep-V "grep" | awk '{print $2 }''

Kill-HUP 'cat/usr/local/nginx/logs/nginx. pid'

 

############

The acceptable signals of nginx are as follows:

Term, int terminate the server immediately
Quit stop the server
Hup configuration changes, start new workers, graceful stop of old workers
Usr1 reopen log files
Usr2 upgrade the server executable
Winch graceful stop (parent process advise the children to Exit)
Kill-hup pid re-apply the configuration file
Kill-usr1 PID refresh log

 

 

| Log polling

Cat log_rotation.sh

#! /Bin/bash

Log_dir = "/usr/local/nginx/logs"

Data_dir = 'date + % Y % m % d'

/Bin/mkdir-p $ log_dir/$ data_dir>/dev/null 2> & 1

/Bin/mv $ log_dir/access. Log $ log_dir/$ data_dir/access. Log

Kill-usr1 'cat/usr/local/nginx/logs/nginx. pid'

 

Set log_rotation.sh to run at 00:00:00 every day:

Crontab-e

59 23 ***/bin/bash log_rotation.sh

 

From: http://blog.chinaunix.net/uid-23354495-id-3063696.html

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.