Linux environment: Debian 6 Stable
Program Version selection:
Taobao produced, based on Nginx and introduced a number of new features
The latest version of the 5.1 series. The reason for not 5.5 is that 5.5 started compiling using CMake, and the data is relatively small. (In fact, Wangyan's script uses 5.5, but I haven't seen it yet ...). ）
A few days ago just out of the current stable, with FPM, and nginx with good.
The main reference to the Lnmp script and Wangyan lanmp script. The script used by the military is very wide and has a good reputation, but the software version is older. Wangyan's LANMP script insists on using the latest version of the software (PHP directly grabs the current stable version number from the Web page and downloads it), and the code structure is awesome, and it's very clear to read.
1. Pre-Installation Preparation
The first is to install the required packages:
Apt-get install build-essential OpenSSL libssl0.9 Libssl-dev
In fact, because it is a retrospective so the specific needs of the package I also remember not clear ... That's basically it. In fact, do not worry about what will be, do configure when there will be a hint, the lack of what to install what can be.
Then prepare users and directories:
useradd-m-s/usr/sbin/nologin-g www www
2. Compile and install Pcre
Tar zxf pcre-8.21.tar.gz
Make && Make install
3. Compile and install Tengine
Tar zxf tengine-1.4.2.tar.gz
Make && Make install
The compilation parameters are copied by the military brother's script. There are many more parameters to be used in Wangyan scripts. Just for now, I think that's enough.
4. Configure Tengine
Configuration files are mainly referred to the nginx.conf written by the military, the fcgi.conf for fastcgi configuration is completely copied. The specific parameters I have not studied the role, and so on when free time to see.
My nginx.conf (main configuration file) is as follows, there are some of the parameters are Tengine unique, part of the configuration is my environment to add changes, are annotated.
User www www.
Worker_processes Auto; #auto这个值是tengine添加的, the original nginx does not exist. can automatically determine the number of worker per CPU core
#Specifies the value for maximum file descriptors the can is opened by this process.
Large_client_header_buffers 4 32k;
Fastcgi_buffers 4 64k;
Gzip_buffers 4 16k;
#limit_zone crawler $binary _remote_addr 10m;
Log_format access ' $remote _addr-$remote _user [$time _local] ' $request '
' $status $body _bytes_sent ' $http _referer '
' $http _user_agent ' $http _x_forwarded_for ';
Server #此段server是禁止通过ip/Not configured domain name access, quite useful
server_name site domain name;
Index index.html index.htm index.php;
Location ~. *\. (PHP|PHP5)? $
Try_files $uri = 404;
Fastcgi_pass Unix:/tmp/php-fpm.sock; #我的php-fpm configured to work with UNIX sockets, if it is a listening port remember to modify the configuration
Include fcgi.conf; #此处fcgi. conf configuration fastcgi related parameters, I use the military version of Nginx, the default is fastcgi.conf
Location ~. *\. (gif|jpg|jpeg|png|bmp|swf) $
Location ~. *\. (JS|CSS)? $
Include vhost/*.conf; #将其它虚拟主机的配置文件置于vhost子文件夹下即可通过此语句自动生效
5. Configure Startup scripts
Nginx startup scripts are very versatile, and I'll just borrow the script provided by the military:
Update-rc.d-f Nginx Defaults
Configuration complete. At this time casually to wwwroot under the cat >> index.html point content can access the test. Direct access to http://domain/status can also be able to see the Tengine state module.
1. Pre-installation configuration
The same is the first installation of the use of the package, and then configure the user ... Then again I also put the specific dependencies on which to forget =. = still need nothing to fill what on it.
Apt-get Install LIBNCURSES5 Libncurses5-dev
Useradd-m-s/usr/sbin/nologin-g MySQL MySQL
2. Compile and install MySQL
Let's spit out a groove ... MySQL Source package download address is really hard to find, I was finally released from the news on the 5.1.66 found, the official website I turned over a half-day Leng did not turn to the direct address.
Tar zxf mysql-5.1.66.tar.gz
./configure--prefix=/usr/local/mysql--with-extra-charsets=complex--enable-thread-safe-client--enable-assembler --with-mysqld-ldflags=-all-static--with-charset=utf8--enable-thread-safe-client--with-big-tables-- With-readline--with-ssl--with-embedded-server--enable-local-infile
Make && Make install
MySQL compiled for a long time, it is recommended to open screen compilation and then go for a cup of coffee and so on ... You can see from the configuration parameters that I did not install InnoDB. You need to add-with-plugins=innobase if you want to pretend. The early MySQL default is to compile the version with debug information, since 5.1.16 the default version of the release without debug information (if you need to add-with-debug). The performance gap between the two is said to be 5%-10%. In addition,-with-mysqld-ldflags=-all-static is also an important parameter for performance improvement.
3. Configure MySQL
Sed-i ' s/skip-locking/skip-external-locking/g '/etc/my.cnf
The primary configuration file. The second sentence of the role is to change the skip-locking to skip-external-locking. MySQL5.5 will discard the skip-locking option, and there will be an error. And now the 5.1 series will suggest replacing with skip-external-locking.
Next, install the MySQL database:
To configure startup scripts:
Perform security installation cleanup:
There is no password for the mysql,root just after the installation. Executing this script will help you set the password for root and delete the anonymous account and test database in the database.
Then clean up the permissions and symbolic links, this part from the military Lnmp script, the specific role I am not very clear:
Cat > /etc/ld.so.conf.d/mysql.conf<< Eof
MySQL installation completed, you can use/etc/init.d/mysql start to test it.
All right, here's the big play. This part of me is basically a line that executes according to Wangyan's script, not much of what I try to do. And as before, the specific need to install which packages I also forget ...
1. Installation Preparation
Apt-get-y Install ZLIBC zlib1g Zlib1g-dev
Apt-get-y Install Libfreetype6 Libfreetype6-dev
Apt-get-y Install LIBXML2 Libxml2-dev
Apt-get-y Install LIBMHASH2 Libmhash-dev
Apt-get-y Install Curl Libcurl3 Libcurl4-openssl-dev
Apt-get-y Install LIBXMLRPC-CORE-C3 Libxmlrpc-core-c3-dev
2. Compile dependent
Need to compile the dependence mainly includes libpng, Libjpeg, Libiconv (these three GD to use), Libmcrypt, Mhash, MCrypt. The compilation process is very consistent:
Wget Source Package Address
Tar zxf Source Pack
CD Source Directory
Make && Make install
Where the address is:
Http://src-mirror.googlecode.com/files/libpng-1.5.13.tar.gz http://src-mirror.googlecode.com/files/ jpegsrc.v8d.tar.gz http://src-mirror.googlecode.com/files/libiconv-1.14.tar.gz http://src-mirror.googlecode.com/ files/libmcrypt-2.5.8.tar.gz http://src-mirror.googlecode.com/files/mhash-0.9.9.9.tar.gz http:// Src-mirror.googlecode.com/files/mcrypt-2.6.8.tar.gz
Mhash a ldconfig must be executed once the compilation is complete.
3. Compiling PHP
Because the selected version is 5.4.9, so php-fpm support is self-contained, do not need to be like the version before 5.3 to download Php-fpm-diff manual patch source code.
The installation process is as follows:
Tar zxf php-5.4.9
./configure--prefix=/usr/local/php--with-curl--with-curlwrappers--with-freetype-dir--with-gettext- With-iconv-dir--with-jpeg-dir--with-libxml-dir--with-mcrypt--with-mhash--with-mysql=/usr/local/mysql-- With-mysqli=/usr/local/mysql/bin/mysql_config--with-openssl--with-pear--with-png-dir--with-xmlrpc--with-zlib-- Enable-bcmath--enable-calendar--enable-exif--enable-fpm--enable-ftp--enable-gd-native-ttf-- Enable-inline-optimization--enable-mbregex--enable-mbstring--enable-pcntl--enable-shmop--enable-soap-- Enable-sockets--enable-sysvsem--enable-sysvshm--enable-xml--enable-zip
Make zend_extra_libs= '-liconv '
The long configure command has wood. Wangyan original Script The parameters are divided into one line with the continuation line, a screen shows only this command ...
The specific parameter meaning I do not speak, basically can see from the name. The more critical-enable-fpm don't leak.
4. Install part of PHP extension
Includes PDO MySQL and memcache extensions.
PHP extensions are installed in a very uniform manner, all in the specified directory to perform the phpize, and then the general compile installation can be.
The following command starts before the working directory is in the PHP source directory.
Make && Make install
Cd.. /.. /..
Tar zxf memcache-2.2.6.tgz
Make && Make install
Continue to copy the Wangyan script. Configuration consists of two aspects, one is php.ini configuration, the other is PHP-FPM configuration
For i in ' ls/usr/local/php/bin '; Do ln-s/usr/local/php/bin/$i/usr/bin/$i; Done #为php的执行文件做软连接
CP Php-*/php.ini-production/usr/local/php/lib/php.ini #此处的php-* refers to the PHP source directory, adjusted according to the situation
Sed-i ' s#; Extension_dir = "./" #extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/" \nextension = " memcache.so "\nextension =" pdo_mysql.so "\n#g '/usr/local/php/lib/php.ini #修改扩展的目录, enabling Memcache and Pdo_mysql
Sed-i ' S/short_open_tag = Off/short_open_tag = On/g '/usr/local/php/lib/php.ini
Sed-i ' s/disable_functions =/disable_functions = system,passthru,exec,shell_exec,popen,symlink,dl/g '/usr/local/php /lib/php.ini
Sed-i ' s/max_execution_time = 30/max_execution_time = 300/g '/usr/local/php/lib/php.ini
Sed-i ' s/post_max_size = 8m/post_max_size = 80m/g '/usr/local/php/lib/php.ini
Sed-i ' S/MAGIC_QUOTES_GPC = OFF/MAGIC_QUOTES_GPC = On/g '/usr/local/php/lib/php.ini
Sed-i ' s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g '/usr/local/php/lib/php.ini
Sed-i ' s/upload_max_filesize = 2m/upload_max_filesize = 20m/g '/usr/local/php/lib/php.ini
#sed-i ' s#;d ate.timezone = #date. TimeZone = Asia/shanghai#g '/usr/local/php/lib/php.ini #这句被我去掉是因为我并不想使用上海时区
Sed-i ' S#;sendmail_path = #sendmail_path =/usr/sbin/sendmail-t-i#g '/usr/local/php/lib/php.ini
The next step is to configure the PHP-FPM. PHP-FPM's profile I use the Wangyan version, and his php-fpm.conf content is here, copied to the/usr/local/php/etc/directory. The configuration of the listen parameter, which he uses to provide the FASTCGI service in the form of a 9000-port listener, I modified it to/tmp/php-fpm.sock UNIX socket form to be consistent with my nginx configuration. In addition, his default running users and groups is also www and www, if there are different needs to be modified according to the environment.
Then configure the PHP-FPM startup script (source code)
CP php-5.4.*/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm #此处的php-* refers to the PHP source directory, which needs to be adjusted according to the situation
Update-rc.d-f PHP-FPM Defaults
At this point the installation is basically complete, you can write a php file under Wwwroot to fill in phpinfo () to test whether the work is normal.
6. Installation of Zend Guard Loader
Although I write this, but in fact PHP5.4 is not Zend Guard Loader (before Zend Optimizer), officially provided only until 5.3. Wangyan's script is copied and configured, but it can't actually be loaded. After consulting some information, we find that the new version of the ZGL will wait a long time to Zend.
Because of its dependence on PHP is not very small, so other XCache, APC and other accelerators and I did not install, this is the end of the
So far, a complete NGINX+MYSQL+PHP-FPM environment has been compiled and installed. I hung up on some of the monitoring scripts to test, the functions are very normal.
Wangyan's Lanmp script is very, very beautiful, much more readable than the Lnmp script of the army. Suggested that interested children's shoes all go to have a look.