Description
PHP in the compilation of the installation, Nginx to be able to invoke PHP to provide dynamic PHP format of the Web page, must be implemented with FASTCGI, but fastcgi is only a framework to achieve FASTCGI framework PHP-FPM, But for the 5.2.x version of PHP, the default is not support PHP-FPM, need to hit the php-fpm patch, for the 5.3.2 version of the patch is also required, and the process of patching is more troublesome. Fortunately 5.3.3 version of the PHP-FPM is directly into the source code package, when compiling the installation only need to enable the PHP-FPM function.
However, if you want to use PHP-FPM, you will also need to provide the following features:
- You need to provide documents that can parse XML format, and you need to install both LIBXML2 and libxml2-devel packages, both of which are installed by default after the development environment is installed.
- Need to install Libevent and after 1.4.12 version, unfortunately rhel5.4 version of this package is before 1.4.12, need to install the package from a new manual compilation.
- Libiconv is a functional component that provides network connectivity for faster network access, which is not installed on the system and needs to be manually compiled and installed.
Build the compilation environment:
Yum-y install gcc openssl-devel zlib-devel pcre-develyum groupinstall "developement Tools" "Development Libraries"-yt
First install Nginx:
wget http://nginx.org/download/nginx-1.0.14.tar.gztar zxvf nginx-1.0.14.tar.gz #useradd-S/SBIN/NOLOGIN-M Nginxcd nginx-1.0.14./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/ nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log -- Pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_ Gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/ tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/make && make install
To create an Nginx startup script:
Vim/etc/init.d/nginxd
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 5152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610 7108109110111112113114115116117118119120121122123124125126 |
#!/bin/sh## nginx-this script starts and stops the Nginx daemon## chkconfig:-15# Description:nginx is an HTTP (S ) server, HTTP (S) Reverse # Proxy and imap/pop3 proxy server# processname:nginx# config:/etc/nginx/ng inx.conf# config:/etc/sysconfig/nginx# pidfile:/var/run/nginx.pid # Source function Library. /etc/rc.d/init.d/functions # Source Networking configuration: /etc/sysconfig/network # Check that networking are up. ["$NETWORKING" = "no"] && exit 0 nginx= "/usr/sbin/nginx" prog=$ (basename $nginx) nginx_conf_file= "/ etc/nginx/nginx.conf " [-f/etc/sysconfig/nginx" &&. /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs () {# Make required directories user= ' Nginx -V 2>&1 | grep "Configure arguments:" | Sed ' s/[^*]*--user=\ ([^]*\). */\1/g '-' options= ' $nginx-v 2>&1 | grep ' Configure arguments: ' for opt in $options; do if [' Echo $opt | grep '. *-temP-path "]; Then value= ' echo $opt | Cut-d "="-F 2 ' if [!-D "$value"]; Then # echo "Creating" $value mkdir-p $value && chown-r $user $value fi Fi Done} start () {[-X $nginx] | | Exit 5 [-F $NGINX _conf_file] | | Exit 6 make_dirs echo-n $ "St Arting $prog: "Daemon $nginx-C $NGINX _conf_file retval=$? echo [$retval-eq 0] && touch $lockfile return $retval} stop () {echo-n $ "stopping $prog:" Ki Llproc $prog-quit retval=$? echo [$retval-eq 0] && rm-f $lockfile return $retval} restart () {configtest | | return $? Stop sleep 1 start} reload () {configtest | | return $? Echo-n $ "Reloading $prog:" Killproc $nginx-hup retval=$? Echo} force_reload () {restart} configtest () {$nginx-T-C $NGINX _conf_file} rh_status () {Status $ Prog} rh_status_q () {rh_status >/dev/null 2>&1} case "$" in start) Rh_status_q && exit 0 $;; Stop) rh_status_q | | Exit 0 $;; Restart|configtest) \ n; Reload) Rh_status_q | | Exit 7 $;; Force-reload) force_reload;; status) Rh_status;; Condrestart|try-restart) rh_status_q | | Exit 0;; *) echo $ "Usage: $ start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2esac |
chmod +x/etc/init.d/nginxd #给予脚本执行权限chkconfig--add nginxd #加入开机启动选项中chkconfig nginxd on # Set boot automatically start service nginxd start #启动nginx Services
Test access:
Install MySQL:
Download:
wget Http://mysql.mirrors.hoobly.com/Downloads/MySQL-5.5/mysql-5.5.22.tar.gztar ZXVF MYSQL-5.5.22.TAR.GZCD Mysql-5.5.22-linux2.6-i686/usr/sbin/groupadd MySQL #添加mysql用户/usr/sbin/useradd-g mysql mysql #添加mysql组
Compile:
./configure--prefix=/usr/local/mysql/--enable-assembler--with-extra-charsets=complex-- Enable-thread-safe-client--with-big-tables--with-readline--with-ssl--with-embedded-server--enable-local-infile --with-plugins=partition,innobase,myisammrgmake&&make Install
An error occurred at compile time:
.. /depcomp:line 571:exec:g++: Not foundmake[1]: * * [MY_NEW.O] Error 127make[1]: Leaving directory '/root/lnmpsrc/mysql-5 .1.62/mysys ' Make: * * * [all-recursive] Error 1
On other servers where g++ is installed, see which package g++ belongs to:
[[email protected] ~]# Find/-name g++/usr/bin/g++[[email protected] ~]# rpm-qf/usr/bin/g++gcc-c++-4.4.6-3.el6.i686
It can be seen that g++ belongs to Gcc-c++ pack
Install gcc-c++:
[[Email protected] ~] #yum Install gcc-c++-y
Recompile:
./configure--prefix=/usr/local/mysql/--enable-assembler--with-extra-charsets=complex-- Enable-thread-safe-client--with-big-tables--with-readline--with-ssl--with-embedded-server--enable-local-infile --with-plugins=partition,innobase,myisammrgmake&&make Install
To change the/usr/local/mysql directory user and genus Group:
Chown-r Mysql.mysql/usr/local/mysql
Create MySQL database, log storage directory
Mkdir/mysql/{data,binlog,relaylog}-pchown-r Mysql.mysql/mysql
To create a data table with MySQL account:
/usr/local/mysql/bin/mysql_install_db--basedir=/usr/local/mysql--datadir=/mysql/data--user=mysql
To create a MySQL configuration file:
Vim/mysql/my.cnf
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 66676869707172737475767778798081828384858687888990 |
[Client] character-set-server = Utf8port = 3306socket =/tmp/mysql.sock [mysqld]character-set-server = utf8r eplicate-ignore-db = mysqlreplicate-ignore-db = testreplicate-ignore-db = Information_schemauser = Mysqlport = 3306s Ocket =/tmp/mysql.sockbasedir =/usr/local/mysqldatadir =/mysql/datalog-error =/mysql/mysql_error.logpid-file =/mysq L/mysql.pidopen_files_limit = 10240back_log = 600max_connections = 5000max_connect_errors = 6000table_cache = 614extern al-locking = Falsemax_allowed_packet = 32msort_buffer_size = 1mjoin_buffer_size = 1mthread_cache_size = 300#thread_ concurrency = 8query_cache_size = 512mquery_cache_limit = 2mquery_cache_min_res_unit = 2kdefault-storage-engine = Myisamthread_stack = 192ktransaction_isolation = Read-committedtmp_table_size = 246mmax_heap_table_size = 246Mlong_ Query_time = 3log-slave-updateslog-bin =/mysql/data/binlogbinlog_cache_size = 4mbinlog_format = MIXEDmax_binlog_cache _size = 8mmax_binlog_size = 1grelay-log-index =/mySql/relaylog/relaylogrelay-log-info-file =/mysql/relaylog/relaylogrelay-log =/mysql/relaylog/relaylogexpire_logs _days = 30key_buffer_size = 256mread_buffer_size = 1mread_rnd_buffer_size = 16mbulk_insert_buffer_size = 64Mmyisam_sort_ Buffer_size = 128mmyisam_max_sort_file_size = 10gmyisam_repair_threads = 1myisam_recover interactive_timeout = 120wait_timeout = 120 skip-name-resolve#master-connect-retry = 10slave-skip-errors = 1032,1062,126,1114,1146,1048,1396 #master-host = 192.168.1.1#master-user = Username#master-password = P Assword#master-port = 3306 server-id = 1 innodb_additional_mem_pool_size = 16Minnodb_buffer_pool_size = 512 Minnodb_data_file_path = Ibdata1:256m:autoextendinnodb_file_io_threads = 4innodb_thread_concurrency = 8innodb_flush_ Log_at_trx_commit = 2innodb_log_buffer_size = 16minnodb_log_file_size = 128minnodb_log_files_in_group = 3innodb_max_ dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_file_per_table = 0 #loG-slow-queries =/mysql/slow.log#long_query_time = 10 [mysqldump]quickmax_allowed_packet = 32M |
Manage MySQL scripts:
Vim/mysql/mysqld
123456789101112131415161718192021222324252627282930313233343536373839404142 |
#!/bin/shmysql_port=3306mysql_username= "admin" #帐号密码可以自行创建mysql_password = "Rootisnosafe" function_start_ MySQL () {printf "starting mysql...\n"/bin/sh/usr/local/mysql/bin/mysqld_safe--defaults-file=/mysql/my.cnf 2&g T;&1 > /dev/null &} function_stop_mysql () {printf "stoping mysql...\n"/usr/local/mysql/bin/mysqladmin-u ${mysql_username}-p${my Sql_password}-s/tmp/mysql.sock Shutdown} function_restart_mysql () {printf "Restarting MySQL...\n" Function_st Op_mysql Sleep 5 function_start_mysql} function_kill_mysql () {kill-9 $ (ps-ef | grep ' Bin/mysqld_safe ' | gr EP ${mysql_port} | awk ' {printf} ') kill-9 $ (ps-ef | grep ' Libexec/mysqld ' | grep ${mysql_port} | awk ' {printf} ')} if ["$" = "Start"]; Then Function_start_mysqlelif ["$" = "Stop"]; Then Function_stop_mysqlelif ["$" = "restart"]; Thenfunction_restart_mysqlelif ["$" = "kill"]; Thenfunction_kill_mysqlelse printf "Usage:/mysql/mysqld {start|stop|restart|kill}\n "fi |
Give script execution permissions:
chmod +x/mysql/mysqld
Start MySQL
/mysql/mysqld start
command line to manage MySQL:
/usr/local/mysql/bin/mysql-u root-p-s/tmp/mysql.sock
Create a user with root privileges: admin, password is Rootisnosafe
GRANT all privileges on * * to ' admin ' @ ' localhost ' identified by ' Rootisnosafe '; GRANT all privileges on * * to ' admin ' @ ' 127.0.0.1 ' identified by ' Rootisnosafe ';
Install PHP:
Install Libevent and Libiconv first:
wget Https://github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gztar ZXVF LIBEVENT-1.4.14B-STABLE.TAR.GZCD Libevent-1.4.14b-stable./configure&&make&&make Installwget http ://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gztar zxvf libiconv-1.14.tar.gzcd libiconv-1.14./ Configuremakemake installln-sf/usr/local/lib/libiconv.so.2/usr/lib/libiconv.so.2
Now install PHP:
wget http://cn.php.net/distributions/php-5.4.0.tar.gztar zxvf php-5.4.0.tar.gzcd php-5.4.0./configure--prefix=/usr /local/php--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl-- ENABLE-FPM --enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/ usr--enable-xml--with-iconv-dir=/usr/localmake zend_extra_libs= '-liconv ' #因为-liconv directory is not in/usr/ Local so you need to manually specify make install when installing
which
The path to –with-mysql and –with-mysqli is your MySQL specific directory
–ENABLE-FPM start FPM. Others are basic options that are easy to understand
CP Php.ini-production/usr/local/php/etc/php.ini
To modify a configuration file:
Vim/usr/local/php/etc/php-fpm.conf
1234 |
Pm.max_children = 50pm.start_servers = 10pm.min_spare_servers = 5pm.max_spare_servers = 35 |
Start:
/USR/LOCAL/PHP/SBIN/PHP-FPM &
Check for normal Startup:
Netstat-tunlp|grep 9000tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 7826/php-fpm
Add/USR/LOCAL/PHP/SBIN/PHP-FPM & to Rc.local:
Echo '/USR/LOCAL/PHP/SBIN/PHP-FPM & ' >>/etc/rc.local
To configure the Fastcgi_params file:
Vim/etc/nginx/fastcgi_params
Replace the content with the following:
12345678910111213141516171819 |
fastcgi_param gateway_interface cgi/1.1;fastcgi_param server_software nginx;fastcgi_param QUERY_S TRING $query _string;fastcgi_param request_method $request _method;fastcgi_param content_type $content _typ E;fastcgi_param content_length $content _length;fastcgi_param script_filename $document _root$fastcgi_script_name;f Astcgi_param script_name $fastcgi _script_name;fastcgi_param request_uri $request _uri;fastcgi_param DOCUME Nt_uri $document _uri;fastcgi_param document_root $document _root;fastcgi_param server_protocol $server _prot Ocol;fastcgi_param remote_addr $remote _addr;fastcgi_param remote_port $remote _port;fastcgi_param SERVER_A DDR $server _addr;fastcgi_param server_port $server _port;fastcgi_param server_name $server _name;# PH P only, required if PHP is built with--enable-force-cgi-redirectfastcgi_param Redirect_status;
|
Finally, modify the nginx.conf configuration file:
12345678910111213 |
Vim/etc/nginx/nginx.conflocation ~ \.php$ { root /www; Fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Fastcgi_param script_filename /scripts$fastcgi_script_name; Include fastcgi_params; } location/{ root /www; Index index.php index.html index.htm; } |
Save exit.
Start Nginx:
Service Nginxd Start
Edit/www/index.php:
Access test:
To test the database connection:
Editor:/www/index.php
12345 |
<?php $link =mysql_connect ("localhost", "admin", "Rootisnosafe"); if ($link) echo "OK"; else echo "FAIL";? > |
Refresh Access.
If the OK word appears, the connection is normal.
Unless noted, the article is (CSZ) original, reproduced please indicate the address of this article
This address: http://www.cszhi.com/20120403/lnmp.html
Compiling and installing LNMP