1、環境部分:
javascript
[root@localhost ~ 00:17 &2]#cat /etc/redhat-release ;uname -r ;getenforce ;iptables -L CentOS release 5.10 (Final) #發行版本號 2.6.18-371.el5 #內核版本號 Disabled #selinux模式 Chain INPUT (policy ACCEPT) #防火牆狀態(能夠根據需求自個配置) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
2、MYSQL二進制免編譯安裝:(爲啥不是編譯?mysql沒這個必要嘛)
php
進入到cd /usr/local/src/下載安裝包並解壓css
[root@localhost src 01:13 &10]#wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz [root@localhost src 01:13 &11]#tar zxvf /usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
將解壓後的包mv到/usr/local/mysql下,mv的時候自動建立mysql目錄
html
[root@localhost src 01:13 &12]#mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql
安裝java
[root@localhost src 01:16 &14]#useradd -s /sbin/nologin mysql [root@localhost src 01:18 &15]#cd /usr/local/mysql [root@localhost mysql 01:19 &16]#mkdir -p /data/mysql [root@localhost mysql 01:19 &17]#chown -R mysql:mysql /data/mysql [root@localhost mysql 01:19 &18]#./scripts/mysql_install_db --user=mysql --datadir=/data/mysql #安裝後會出現兩個‘OK’ [root@localhost mysql 01:21 &19]#cp support-files/my-large.cnf /etc/my.cnf #問是否覆蓋?yes [root@localhost mysql 01:23 &20]#cp support-files/mysql.server /etc/init.d/mysqld [root@localhost mysql 01:23 &21]#chmod 755 /etc/init.d/mysqld [root@localhost mysql 01:24 &22]#vim /etc/init.d/mysqld #修改datadir爲datadir=/data/mysql [root@localhost mysql 01:25 &23]#chkconfig --add mysqld [root@localhost mysql 01:27 &24]#chkconfig mysqld on [root@localhost mysql 01:27 &25]#service mysqld start
3、編譯安裝PHP
node
進入到cd /usr/local/src/下載源碼包並解壓python
[root@localhost src 01:30 &27]#wget http://cn2.php.net/distributions/php-5.3.28.tar.gz [root@localhost src 18:11 &49]#tar zvxf php-5.3.28.tar.gz
安裝
mysql
[root@localhost src 18:11 &49]#useradd -s /sbin/nologin php-fpm [root@localhost src 18:14 &50]#cd php-5.3.28 [root@localhost php-5.3.28 18:52 &75]#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --enable-zend-multibyte --disable-ipv6 --with-pear --with-curl #若是安裝系統的時候沒加開發庫等,會報各類錯,能夠參考另一篇LNMP安裝報錯解決方案:http://zengweidao.blog.51cto.com/8342699/1535579 [root@localhost php-5.3.28 19:14 &76]#make && make install [root@localhost php-5.3.28 19:03 &77]#cp php.ini-production /usr/local/php/etc/php.ini [root@localhost php-5.3.28 19:14 &77]#vim /usr/local/php/etc/php-fpm.conf #增長如下 [global] pid = /usr/local/php/var/run/php-fpm.pid error_log = /usr/local/php/var/log/php-fpm.log [www] listen = /tmp/php-fcgi.sock user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024
檢查配置文件是否正確:linux
[root@localhost php-5.3.28 19:19 &78]#/usr/local/php/sbin/php-fpm -t
拷貝啓動腳本:
nginx
[root@localhost php-5.3.28 19:25 &79]#cp /usr/local/src/php-5.3.28/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@localhost php-5.3.28 19:27 &80]#chmod 755 /etc/init.d/php-fpm
添加到指定的服務程序,並加入開機啓動:
[root@localhost php-5.3.28 19:28 &81]#chkconfig --add php-fpm [root@localhost php-5.3.28 19:32 &82]#chkconfig php-fpm on
啓動PHP:
[root@localhost php-5.3.28 19:33 &83]#service php-fpm start
4、編譯安裝nginx
進入到cd /usr/local/src/下載源碼包並解壓:
[root@localhost src 19:37 &86]#wget http://nginx.org/download/nginx-1.4.4.tar.gz
[root@localhost src 19:40 &88]#tar zxvf nginx-1.4.4.tar.gz
安裝:
[root@localhost src 19:40 &88]#cd nginx-1.4.4 [root@localhost nginx-1.4.4 19:42 &90]#./configure --prefix=/usr/local/nginx --with-pcre #這裏也可能會報錯,請參考LNMP報錯解決方案:http://zengweidao.blog.51cto.com/8342699/1535579 [root@localhost nginx-1.4.4 19:45 &95]#make && make install
編輯啓動腳本:
[root@localhost nginx-1.4.4 19:45 &95]# vim /etc/init.d/nginx
增長如下內容:
#!/bin/bash # chkconfig: - 30 21 # description: http service. # Source Function Library . /etc/init.d/functions # Nginx Settings NGINX_SBIN="/usr/local/nginx/sbin/nginx" NGINX_CONF="/usr/local/nginx/conf/nginx.conf" NGINX_PID="/usr/local/nginx/var/nginx.pid" RETVAL=0 prog="Nginx" start() { echo -n $"Starting $prog: " mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL } reload(){ echo -n $"Reloading $prog: " killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL } restart(){ stop start } configtest(){ $NGINX_SBIN -c $NGINX_CONF -t return 0 } case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $"Usage: $0 {start|stop|reload|restart|configtest}" RETVAL=1 esac exit $RETVAL
修改啓動文件權限並加入開機啓動:
[root@localhost nginx-1.4.4 19:48 &96]#chmod 755 /etc/init.d/nginx [root@localhost nginx-1.4.4 19:55 &97]#chkconfig --add nginx [root@localhost nginx-1.4.4 19:55 &98]#chkconfig nginx on
更改Nginx配置文件:
[root@localhost nginx-1.4.4 19:56 &99]#vim /usr/local/nginx/conf/nginx.conf
內容以下:(把以前的清掉)
user nobody nobody; worker_processes 2; error_log /usr/local/nginx/logs/nginx_error.log crit; pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 6000; } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 3526; server_names_hash_max_size 4096; log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' '$host "$request_uri" $status' '"$http_referer" "$http_user_agent"'; sendfile on; tcp_nopush on; keepalive_timeout 30; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; connection_pool_size 256; client_header_buffer_size 1k; large_client_header_buffers 8 4k; request_pool_size 4k; output_buffers 4 32k; postpone_output 1460; client_max_body_size 10m; client_body_buffer_size 256k; client_body_temp_path /usr/local/nginx/client_body_temp; proxy_temp_path /usr/local/nginx/proxy_temp; fastcgi_temp_path /usr/local/nginx/fastcgi_temp; fastcgi_intercept_errors on; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 8k; gzip_comp_level 5; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css text/htm application/xml; server { listen 80; server_name localhost; index index.html index.htm index.php; root /usr/local/nginx/html; location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/tmp/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; } } }
測試php解析:
[root@localhost nginx-1.4.4 20:00 &101]#/usr/local/nginx/sbin/nginx -t [root@localhost nginx-1.4.4 20:33 &113]#service nginx start
編輯一個PHP文件:
[root@localhost nginx-1.4.4 20:37 &115]#vim /usr/local/nginx/html/1.php
加入如下內容:
<?php echo "測試php是否解析"; ?>
測試:
[root@localhost nginx-1.4.4 20:44 &117]#curl localhost/1.php 測試php是否解析