LNMP
一、安装MySQL
参照本博配置LAMP文章 http://www.cnblogs.com/frankielf0921/articles/5371611.html
=====================我是分割线。========================
二、安装php
针对Nginx的php安装和针对apache的php安装是有区别的,
因为Nginx中的php是以fastcgi的方式结合nginx的,
可以理解为nginx代理了php的fastcgi,
而apache是把php作为自己的模块来调用的。
[rot@localhost ~]# cd /usr/local/src [root@localhost src]# wget http://am1.php.net/distributions/php-5.3.27.tar.gz [root@localhost src]# tar zxf php-5.3.27.tar.gz [root@localhost src]# cd php-5.3.27 [root@localhost php-5.3.27]# ./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 \ --with-openssl [root@localhost php-5.3.27]# make [root@localhost php-5.3.27]# make install [root@localhost php-5.3.27]# cp php.ini-production /usr/local/php/etc/php.ini //拷贝配置文件 //此配置文件全为注释,可以留着查看 //也可将其清空后再添加新内容 [root@localhost php-5.3.27]# > /usr/local/php/etc/php-fpm.conf [root@localhost php-5.3.27]# vim /usr/local/php/etc/php-fpm.conf //写入以下内容 [global] // pid设置,默认在安装目录中的var/run/php-fpm.pid,建议开启 pid = /usr/local/php/var/run/php-fpm.pid // 错误日志,默认在安装目录中的var/log/php-fpm.log error_log = /usr/local/php/var/log/php-fpm.log [www] // fpm监听端口,即nginx中php处理的地址,一般默认值即可。可用格式为: ‘ip:port’, ‘port’, ‘/path/to/unix/socket’. 每个进程池都需要设置. listen = /tmp/php-fcgi.sock // 启动进程的帐户和组 user = php-fpm group = php-fpm // 对于专用服务器,pm可以设置为static。 pm = dynamic // 子进程最大数 pm.max_children = 50 // 启动时的进程数 pm.start_servers = 20 // 保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程 pm.min_spare_servers = 5 // 保证空闲进程数最大值,如果空闲进程大于此值,此进行清理 pm.max_spare_servers = 35 // 设置每个子进程重生之前服务的请求数. 对于可能存在内存泄漏的第三方模块来说是非常有用的. 如果设置为 ’0′ 则一直接受请求. 等同于 PHP_FCGI_MAX_REQUESTS 环境变量. 默认值: 0. pm.max_requests = 500 // 设置文件打开描述符的rlimit限制. 默认值: 系统定义值默认可打开句柄是1024,可使用 ulimit -n查看,ulimit -n 2048修改。 rlimit_files = 1024 [root@localhost php-5.3.27]# /usr/local/php/sbin/php-fpm -t //检测配置文件是否有错误 //出现诸如 “test is successful” 字样,说明配置没有问题。 [root@localhost php-5.3.27]# cp /usr/local/src/php-5.3.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //拷贝启动脚本 [root@localhost php-5.3.27]# chmod 755 /etc/init.d/php-fpm //修改权限 [root@localhost php-5.3.27]# groupadd php-fpm [root@localhost php-5.3.27]# useradd -g php-fpm -s /sbin/nologin php-fpm //账号用来运行php-fpm服务 [root@localhost php-5.3.27]# service php-fpm start //启动php-fpm [root@localhost php-5.3.27]# chkconfig php-fpm on [root@localhost php-5.3.27]# ps aux |grep php-fpm
安装php会遇到的错误:--其他错误可查看LAMP配置文章
// 编译时遇到的错误 1. /usr/bin/ld: cannot find -lltdl collect2: ld returned 1 exit status make: *** [sapi/fpm/php-fpm] --> yum install -y libtool-ltdl-devel
2. error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
--> yum install -y libcurl-devel
// 修改配置文件后,检测是否正确时的错误 [03-Mar-2016 01:23:38] ERROR: [/usr/local/php/etc/php-known entry 'pid' [03-Mar-2016 01:23:38] ERROR: failed to load configurar/local/php/etc/php-fpm.con [03-Mar-2016 01:23:38] ERROR: FPM initialization failed --> cd /usr/local/php/etc --> ls pear.conf php-fpm.conf.default php-fpm.conf php.ini --> mv php-fpm.conf.default php-fpm.conf 是否覆盖"php-fpm.conf"? y OR --> rm -rf /usr/local/php/etc/php-fpm.conf.default
//启动php-fpm服务时的错误
Starting php-fpm [11-Apr-2016 04:40:06] ERROR: [pool www] cannot get uid for user 'php-fpm'
--> 漏掉了 useradd -s /sbin/nologin php-fpm 这一步 执行即可
=====================我是分割线。========================
三、安装nginx -- 如果Apache正在运行,把Apache停掉。 { 有时两者会进行干扰 }
[root@localhost ~]# cd /usr/local/src [root@localhost src]# wget http://nginx.org/download/nginx-1.4.4.tar.gz [root@localhost src]# tar zxvf nginx-1.4.4.tar.gz [root@localhost src]# cd nginx-1.4.4 [root@localhost nginx-1.4.4]# ./configure \ --prefix=/usr/local/nginx \ --with-http_realip_module \ --with-http_sub_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --with-pcre [root@localhost nginx-1.4.4]# make [root@localhost nginx-1.4.4]# make install [root@localhost nginx-1.4.4]# 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/logs/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]# chmod 755 /etc/init.d/nginx [root@localhost nginx-1.4.4]# chkconfig --add nginx [root@localhost nginx-1.4.4]# chkconfig nginx on [root@localhost nginx-1.4.4]# > /usr/local/nginx/conf/nginx.conf [root@localhost nginx-1.4.4]# 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; } } } [root@localhost nginx-1.4.4]# /usr/local/nginx/sbin/nginx -t //检测配置文件是否正确 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 [root@localhost nginx-1.4.4]# service nginx start [root@localhost nginx-1.4.4]# ps aux|grep nginx
安装nginx会遇到的错误:
//编译安装时遇到的错误 1. ./configure: error: the HTTP rewrite module requires the PCRE library. --> yum -y install pcre-devel 如果此方法没办法解决,则需要去网上下载pcre的gz包 然后在nginx编译的时候加上 --with-pcre=../pcre-7.8.tar.gz(包名) 2. /configure: error: the HTTP cache module requires md5 functions from OpenSSL library. You can either disable the module by using --without-http-cache option, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-http_ssl_module --with-openssl=<path> options. --> yum -y install openssl openssl-devel
=====================我是分割线。========================
四、测试是否解析php文件---虽说nginx和php都启动了,但要想两者结合,必须配置
[root@localhost nginx]# vim /usr/local/nginx/html/2.php //加入以下内容 <?php echo "php works"; ?> [root@localhost nginx]# curl localhost/2.php php works[root@localhost nginx]#