Lnamp environment installation record will be used by Open source software: Apache [must, Web dynamic scripting server, do nginx reverse proxy 8080 Port]tengine [must, Web static file server 80 port]mysql [must be]php [must]1. Apache Install a.apr install wget-c HTTP://MIRROR.BJTU.EDU.CN/APACHE/APR/APR-1.5.1.TAR.GZTAR-ZXVF apr-1. 5.TAR.GZCD apr-1.5.1./configure--prefix=/usr/local/aprmakemake installb.apr-util install wget-c wget/HTTP/ MIRROR.BJTU.EDU.CN/APACHE/APR/APR-UTIL-1.5.4.TAR.GZTAR-ZXVF APR-UTIL-1.5.4.TAR.GZCD Apr-util-1.5.4./configure-- Prefix=/usr/local/apr-util--with-apr=/usr/local/aprmakemake installc.pcre Installation wget-c ftp://ftp.csx.cam.ac.uk/pub/ SOFTWARE/PROGRAMMING/PCRE/PCRE-8.36.TAR.GZTAR-ZXVF PCRE-8.36.TAR.GZCD pcre-8.36./configure--prefix=/usr/local/ Pcremakemake Installd.apache Installation Wget-c HTTP://MIRROR.SYMNDS.COM/SOFTWARE/APACHE//HTTPD/HTTPD-2.4.10.TAR.GZTAR-ZXVF HTTPD-2.4.10.TAR.GZCD httpd-2.4.10./configure--prefix=/usr/local/apache--enable-so-rewrite=shared--with-mpm= Prefork
--WITH-APR=/USR/LOCAL/APR--with-apr-util=/usr/local/apr-util--with-pcre=/usr/local/pcre If you are prompted for OpenSSL (Legacy), run Yum Install openssl-develyum update opensslmakemake install E. Add Apache to system service, boot from boot cp/usr/local/apache/bin/apachectl /etc/init.d/httpdvim/etc/init.d/httpd# beyound# chkconfig:35 15# Description:apache is a world Wide Web server. chmod +x/etc/init.d/httpd/sbin/chkconfig--add httpd/sbin/chkconfig--list httpdln-s/sbin/chkconfig/usr/bin/ Chkconfigln-s/sbin/service/usr/bin/service2. MySQL installation A. Prepare to install some necessary software: Yum install cmake automake autoconf libtool gcc g++ bisonyum install ncurses-devel mkdir-p/data/ Mysqlmkdir-p/var/run/mysqldgroupadd MySQL//Add a MySQL standard group useradd-g mysql mysql//add MySQL user and added to MySQL group B. Download and install the WGET-C Http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.11.tar.gz/from/http://cdn.mysql.com/tar-zxvf MYSQL-5.6.11.TAR.GZCD Mysql-5.6.11cmake-dcmake_install_prefix=/usr/local/mysql #安装路径-dmysql_datadir=/data/mysql/ #数据文件存放位置-DSYSCONFDIR=/etc #my. CNF path-dwith_myisam_storage_engine=1 #支持MyIASM引擎-dwith_innobase_storage_eng ine=1 #支持InnoDB引擎-dwith_memory_storage_engine=1 #支持InnoDB引擎-dwith_readline=1 #快捷键功能 (I didn't use)-dmysql_unix_addr=/tmp/mysqld.sock #连接数据库socket路径-dmysql_tcp_port=3306 #端口-dena bled_local_infile=1 #允许从本地导入数据-dwith_partition_storage_engine=1 #安装支持数据库分区-dwith_extra_charsets : STRING=UTF8,GBK #安装需要的字符集-ddefault_charset=utf8 #默认字符-ddefault_collation=utf8_general_ci #默认字符集-dmysql_user=mysql If an error occurred during installation, remove the CMakeCache.txt file Makemake install C. Configuration before re-cmake after resolving errors In this step of the configuration file, it is important to note that the MY.CNF load order, the Linux priority from high to low
/etc/my.cnf->/etc/mysql/my.cnf->sysconfdir/my.cnf-> $MYSQL _home/my.cnf,
The high priority MY.CNF setting overrides the low priority my.cnf, so it is common to copy the config file to etc. #如果/etc without MY.CNFCP support-files/my-medium.cnf/etc/my.cnfvim/etc/my.cnf [client]default-character-set=utf8port= 3306 [Mysqld_safe]log-error=/var/log/www/mysql/mysqld.logpid-file=/var/run/mysqld/mysqld.pid [mysqld]datadir=/ var/lib/mysql#socket=/var/lib/mysql/mysql.socksocket=/tmp/mysqld.sockuser=mysql# Disabling Symbolic-links is Recommended to prevent assorted security riskssymbolic-links=0 wait-timeout = 30max_connections = 512max_allowed_packet= 64mslow_query_logslow_query_log_file=/var/log/www/mysql/slow.loglog-error =/var/log/www/mysql/error.log # Permissions for Data Catalog Chown mysql.mysql-r/data/mysqlchown-r mysql:mysql/var/run/mysqldchmod +x/usr/local/mysqlchown-r mysql.mysql /usr/local/mysql #数据初始化/usr/local/mysql/scripts/mysql_install_db--defaults-file=/etc/my.cnf
--basedir=/usr/local/mysql--datadir=/data/mysql--user=mysql #设置软连接使mysql, mysqldump, Mysqladmin These three bin commands can be run directly in the shell ln-s/usr/local/mysql/bin/mysql/usr/binln-s/usr/local/mysql/bin/mysqldump/usr/ Binln-s/usr/local/mysql/bin/mysqladmin/usr/bin #启动MySQL/usr/local/mysql/bin/mysqld_safe--defaults-file=/etc/ My.cnf
--user=mysql--datadir=/data/mysql & #配置开机自启动vim/etc/rc.local Add/usr/local/mysql/bin/mysqld_safe
--DEFAULTS-FILE=/ETC/MY.CNF--user=mysql--datadir=/data/mysql & #修改mysql密码UPDATE user SET Password=password (" NewPassword ") WHERE user= ' root '; FLUSH privileges; Create Database db_test; B. Creating a new user to manage the Db_test database insert into Mysql.user (Host,user,password)
VALUES ("localhost", "admin", Password ("NewPassword")); flush privileges; C. Grant all privileges-db_test.* to [e-mail protected] identified by ' newpassword '; 3.tengine[nginx] Install a. Preparations need to download something wget-c http://zlib.net/zlib-1.2.8.tar.gztar-zxvf zlib-1.2.8.tar.gz wget-c http://www.openssl.org/ SOURCE/OPENSSL-1.0.1E.TAR.GZTAR-ZXVF openssl-1.0.1e.tar.gz wget http://labs.frickle.com/files/ngx_cache_ Purge-2.3.tar.gz tar zxvf ngx_cache_purge-2.3.tar.gz groupadd www//Add a WWW standard group useradd-g www www//Add www user and add to www group B . Download Install wget-c http://tengine.taobao.org/download/tengine-2.1.0.tar.gztar-zxvf tengine-2.1.0.tar.gzcd tengine-2.1.0. /configure--user=www--group=www--prefix=/usr/local/nginx
--with-http_stub_status_module--with-http_sub_module--with-http_realip_module
--with-http_flv_module--with-http_dav_module--with-http_gzip_static_module
--with-http_addition_module--with-http_ssl_module
--with-openssl=. /openssl-1.0.1h
--with-pcre=. /pcre-8.36
--with-zlib=. /zlib-1.2.8
--add-module=/usr/local/src/ngx_cache_purge-2.3make make install C. Configure Vim/etc/init.d/nginx #! /bin/sh # Author:rui Ding # modified:geoffrey grosenbach http://topfunky.com # modified:clement NEDELCU # reproduced WI TH express authorization from its contributors set-e path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/ Bin desc= "Nginx daemon" Name=nginx daemon=/usr/local/nginx/sbin/$NAME scriptname=/etc/init.d/$NAME # If The daemon file is not found, terminate the script. Test-x $DAEMON | | Exit 0 start () {$DAEMON | | echo-n "already Running"} stop () {$DAEMON-S quit | | echo-n "not Running"} Reloa D () {$DAEMON-S reload | | echo-n "could not reload"} case "$" in start) echo-n "Starting $DESC: $NAME" Start echo "." ;; Stop) echo-n "stopping $DESC: $NAME" Stop echo "." ;; Reload) echo-n "Reloading $DESC configuration ..." Reload echo "Reloaded."; Restart) echo-n "Restarting $DESC: $NAME" Stop # Sleep for both seconds before starting again, this should give the # Nginx daemon some time to perform a graceful stop. Sleep 2 start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2 exit 3;; ESAC Exit 0 chmod +x/etc/init.d/nginx service nginx startservice nginx reloadservice nginx restartservice nginx Stop vim/etc/rc.local Add a line/usr/local/nginx/sbin/nginx & 4.PHP Compile install A.yum install related Library package yum install gd-devel Php-gdyum Install zlib Zlib-develyum Install freetype-devel freetype-demos freetype-utilsyum install libpng libpng-devel libpng10 libpng10 -develyum Install libjpeg libjpeg-develyum install Imagemagickyum install flexyum install Imagemagick-develyum install Li BXML2 Libxml2-develyum Install libxml2 Curl curl-develyum-y install libtool Libtool-ltdl-develyum Install Mhash-develyum Install patch B. Packages that may require source code compilation Wget-c Ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gztar- ZXVF LIBMCRYPT-2.5.7.TAR.GZCD libmcrypt-2.5.7./configure--prefix=/usr/local/libmcryptmake && make install wget-c http://iweb.dl.sourceforge.net/ PROJECT/MHASH/MHASH/0.9.9.9/MHASH-0.9.9.9.TAR.GZTAR-ZXVF MHASH-0.9.9.9.TAR.GZCD mhash-0.9.9.9./configure--prefix =/usr/local/libmhashmake && make install C. Compile installation wget-c http://cn2.php.net/get/php-5.6.6.tar.gz/from/this/ MIRRORTAR-ZXVF php-5.6.6.tar.gzcd php-5.6.6./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-apxs2=/usr/local/apache/bin/apxs
--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-sysvshm--enable-sysvmsg--enable-inline-optimization
--with-curl--with-curlwrappers--enable-mbregex--enable-fpm
--enable-fastcgi--enable-force-cgi-redirect
--enable-mbstring--with-mcrypt=/usr/local/libmcrypt
--WITH-GD--enable-gd-native-ttf--with-openssl
--with-mhash--enable-pcntl--enable-sockets
--with-ldap--WITH-LDAP-SASL--with-xmlrpc--enable-zip--enable-soap
--enable-ftp--enable-sigchild
--with-pear--enable-cli--enable-exif
--enable-calendar--with-bz2--enable-pdo--with-pdo-mysql--enable-freetype--disable-fileinfo configure:error: Cannot find Ldap.hyum install Openldapyum install openldap-devel Configure:error:Please Reinstall the BZIP2 distribution Centos:yum Install bzip2 bzip2-devel error: Configure:error:Cannot Find LDAP Libraries In/usr/lib workaround: cp-frp/usr/lib64/l ibldap*/usr/lib/Error: configure:error:Unable to find your MySQL installation workaround: ln-s/usr/local/mysql/bin/mysql_config /usr/bin/mysql_config compile error, you need to make a clean and make Makemake install to modify the Apache configuration file httpd.conf vim/usr/local/apache/conf /httpd.conf then add LoadModule php5_module to the last face of the text modules/libphp5.so
(Note that in the Apache installation directory, modules under the libphp5.so, which is added in PHP installation, if not, PHP, you need to reload) AddType application/x-httpd-php. PHP (. Preceded by a space) AddType application/x-httpd-php. html CP php.ini-production/usr/local/p Hp/etc/php.ini 5. Environmental Integration A. Integration of Apache Mkdir-p/home/www/test.comchown-r www.www/home/www Apache will be the Nginx agent, Therefore, change the default listening port of Apache to 8080 vim/usr/local/apache/conf/httpd.conf to direct the hosts to the Include Conf/extra/httpd-vhosts.conflisten 8080 User wwwgroup www <ifmodule dir_module> directoryindex index.php index.html index.htm</ifmodule> vim/ Usr/local/apache/conf/extra/httpd-vhosts.conf *:80 all the inside into yourdomain.name:8080 and add virtual hosts <virtualhost *:8080 > ServerAdmin [email protected] documentroot "/home/www/test.com" DirectoryIndex index.php index.html ServerName a.test.com <directory "/home/www/a.test.com" > allowoverride None Options None Require all granted </Directory> errorlog "/var/log/www/apache/a.test.com-error_log" Customlog "/var/loG/www/apache/a.test.com-access_log "Common</virtualhost> vim/home/www/test.com/phpinfo.php <?phpphpinfo ( ); Service httpd start, Access http://a.test.com:8080/phpinfo.php B. Configure PHP-FPM CP/USR/LOCAL/PHP/ETC/PHP-FPM.CONF.DEFAULT/USR /local/php/etc/php-fpm.conf# Open php-fpm Slow script log request_slowlog_timeout = 30slowlog =/var/log/www/php/php-fpm.log.slow # Script Wait Time Request_terminate_timeout = + pid =/usr/local/php/var/run/php-fpm.piderror_log =/var/log/www/php/ Php-fpm.log.errorlog_level = Notice user = Wwwgroup = www Listen = 127.0.0.1:9000pm = Dynamicpm.max_children = 100pm.start _servers = 10pm.min_spare_servers = 5pm.max_spare_servers = 100pm.max_requests = 1000/usr/local/php/sbin/php-fpm # The PHP-FPM Synthesis system service VIM/ETC/INIT.D/PHP-FPM #! /bin/sh### BEGIN INIT info# provides:php-fpm# required-start: $remote _fs $network # required-stop: $remote _fs $network # default-start:2 3 4 AA default-stop:0 1 6# short-description:starts php-fpm# Description: Starts the PHP FASTCGI Process Manager daemon### END INIT INFO Prefix=/usr/local/phpexec_prefix=${prefix} php_fpm_bin=${exec_prefix}/sbin/ Php-fpmphp_fpm_conf=${prefix}/etc/php-fpm.confphp_fpm_pid=${prefix}/var/run/php-fpm.pid php_opts= "--fpm-config $ Php_fpm_conf "Wait_for_pid () {try=0 while Test $try-lt, do case" $ "in ' created ') If [-F "$"]; Then try= "Break fi;; ' Removed ') if [!-F "$"]; Then try= "Break fi;; Esac Echo-n. try= ' expr $try + 1 ' sleep 1 done} case "$" in start) echo-n "Starting php-fpm" $php _fpm_b In $php _opts if ["$?"! = 0]; Then echo "Failed" Exit 1 fi wait_for_pid created $php _fpm_pid if [-N ' $try " ] ; Then echo "Failed" Exit 1 else echo "Done" fi ;; Stop) echo-n "Gracefully shutting down php-fpm" if [! -R $php _fpm_pid]; Then echo "Warning, no PID file found-php-fpm are not running?" Exit 1 fi kill-quit ' cat $php _fpm_pid ' wait_for_pid removed $php _fpm_pid if [-N ' $try "] ; Then echo "failed. Use Force-quit "Exit 1 else echo" done "FI;; Force-quit) echo-n "terminating php-fpm" if [! -R $php _fpm_pid]; Then echo "Warning, no PID file found-php-fpm are not running?" Exit 1 fi kill-term ' cat $php _fpm_pid ' wait_for_pid removed $php _fpm_pid if [-N ' $try "] ; Then echo "Failed" Exit 1 else echo ' done ' fi;; Restart) $ stop $ start; Reload) echo-n "Reload service php-fpm" if [! -R $php _fpm_pid]; Then echo "WarniNg, no PID file found-php-fpm is not running? " Exit 1 fi kill-usr2 ' cat $php _fpm_pid ' echo ' done ';; *) echo "Usage: $ start|stop|force-quit|restart|reload}" exit 1;; ESAC chmod +x/etc/init.d/php-fpm service php-fpm startservice php-fpm stopservice php-fpm reloadservice php-fpm Restart # Boot vim/etc/rc.local Add a line/usr/local/php/sbin/php-fpm & C.nginx Integration mkdir/usr/local/nginx/conf/vhosts vim/usr/ local/nginx/conf/nginx.conf user www www;worker_processes 8; Error_log/var/log/www/nginx/error.log crit, #error_log/var/log/www/nginx/error.log notice; #error_log/var/log/www/ Nginx/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"; 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; Tcp_nodelay on; Keepalive_timeout 65; 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; Proxy_set_header Host $host; Proxy_set_header X-real-ip $remote _addr; Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; 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; Include vhosts/*.conf;} Vim/usr/local/nginx/conf/vhosts/a.test.com.conf #反向代理Upstream www.test {a.test.com:8080;} server {Listen 80; server_name www.test.com; CharSet Utf-8; Root/home/www/www.test; Location/{index index.php index.html index.htm;if (!-e $request _filename) {#rewrite ^ (. *) $ /index.php?s=$1 last; #break; }} #error_page 404/404.html; # REDIRECT Server error pages to the static page/50x.html # Error_page 502 503 504/50x.html; Location =/50x.html {root html; } location ~ \.php$ {#開啟支持php Fastcgi_pass 127.0.0.1:9000; #php fastcgi service address and Port Fastcgi_index index.php; Fastcgi_param script_filename $document _root$fastcgi_script_name; Include Fastcgi_params; }} service Nginx reload d.apache+nginx+php reverse proxy vim/usr/local/nginx/conf/vhosts/a.test.com.conf #反向代理upstream www.test {sErver a.test.com:8080;} server {Listen 80; server_name www.test.com; CharSet Utf-8; root/home/www/test.com; Location/{index index.php index.html index.htm; } #error_page 404/404.html; # REDIRECT Server error pages to the static page/50x.html # Error_page 502 503 504/50x.html; Location =/50x.html {root html; } location ~ \.php$ {#fastcgi_pass 127.0.0.1:9000; #php fastcgi service address and Port #fastcgi_index index.php; #fastcgi_param script_filename $document _root$fastcgi_script_name; #include fastcgi_params; Proxy_pass http://www.test; #apache反向代理 Proxy_pass_header user-agent; Proxy_redirect off; Proxy_set_header Host $host; Proxy_set_header X-real-ip $remote _addr; Proxy_set_heAder x-forwarded-for $proxy _add_x_forwarded_for; Client_max_body_size 10m; Client_body_buffer_size 128k; Proxy_connect_timeout 90; Proxy_send_timeout 90; Proxy_read_timeout 90; Proxy_buffer_size 512k; Proxy_buffers 4 512k; Proxy_busy_buffers_size 512k; Proxy_temp_file_write_size 512k; }} service Nginx reload re-access http://www.test.com/phpinfo.php For example, the system has used Apache to parse the dynamic request, the reverse proxy configuration is completed correctly
Lnamp full version [linux+apache2.4+php5.5.6+mysql5.6]