LAMP+LNMP安裝注意問題及安裝

1、LAMP安裝注意事項php

  1. 必須先安裝apache再安裝 php,apache支持php須要生成libphp5.so 文件,須要編譯時添加該語句 --with-apxs2=/usr/local/apache/bin/apxs
  2. apache配置文件修改注意事項
    2.1. AllowOverride None  #修改成:AllowOverride All (容許.htaccess)
    2.2.DirectoryIndex index.html #修改成:DirectoryIndex index.html index.htm Default.html Default.htm index.php(設置默認首頁文件,增長index.php)
    2.3.MaxKeepAliveRequests 500 #添加MaxKeepAliveRequests 500 (增長同時鏈接數)
    2.4.設置工做目錄 #說明: 搜索DocumentRoot, 修改成 DocumentRoot "/var/www/html" 搜索<Directory "/usr/local/apache2//htdocs">, 修改成 <Directory
    "/var/www/html">
    2.5. 設置默認文檔 : 索<IfModule dir_module>, 修改成 DirectoryIndex index.html index.php
    2.6.增長php類型 AddType application/x-gzip .gz .tgz在後面添加 AddType application/x-httpd-php .html .php
    2.6.#修改配置文件 vi /etc/httpd/httpd.conf
    #查找ServerName,將註釋去掉 ServerName www.example.com:80 www.example.com->須要改的ip
    2.7.#添加到自啓動
    echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit #將apache添加到系統服務中
    cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
    vi /etc/rc.d/init.d/httpd
    #在#!/bin/sh後添加下面兩行(包含"#")
    # chkconfig:2345 85 15
    # description:Apache
    #添加執行權限 chmod 755 /etc/init.d/httpd
    #添加到系統服務中 chkconfig --add httpd
    #開啓apache service httpd start

*注:設置SELinux爲permissive模式 命令行下 setenforce 0 當即生效,重啓失效 修改配置文件後, 重啓apache才能生效 css

2、LNMP安裝
必須開啓 --enbale-fpmhtml

groupadd www
useradd -s /sbin/nologin -g www www

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module  

make && make install
   軟鏈接
ln -sf /usr/local/nginx/sbin/nginx /usr/bin/nginx

修改配置文件支持php
可把 root 改成想要的目錄
打開一下 #nginx

#location ~ \.php$ {
#            root           /home/wwwroot/;
#            fastcgi_pass   127.0.0.1:9000;
#            fastcgi_index  index.php;
#            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
#            include        fastcgi_params;
#        }

like this:


 location ~ \.php$ {
            root           /home/wwwroot/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

也能夠把給段配置改成改
*$document_root指 定義的根目錄redis

location ~\.php{
fastcgi_pass unix:/tmp/php-fcgi.sock; //下面解釋
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}

*fastcgi_pass 裏的 127.0.0.1:9000; 可改成unix:/tmp/php-fcgi.sock;
須要更改 php-fpm.conf 須要添加
group=www
user=www
listen=/tmp/php-fcgi.sock
listen.owner= www
listen.group =wwwapache

還要創建 /tmp/php-fcgi.sock; touch /tmp/php-fcgi.socksession

chown www:www /tmp/php-fcgi.sock 賦予其權限

nginx -s reload

php-fpm 重啓

配置文件 :app


server{

listen 8080;
server_name 192.168.139.134:8080;
index  index.html index.htm index.php;
root   /home/wwwroot/demo;

location ~\.php{

fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;

}

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp4)$
        {
            expires    30d;

        }

        location ~ .*\.(js|css)?$
        {
            expires    12h;
        }

***************************************************

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /home/wwwroot/;
            index  index.html index.htm index.php;
   }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /home/wwwroot/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
 #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

include vhost/*.conf;
}

//nginx 負載均衡 反相代理負載均衡

upstream redis { //redis自定義的 和下面 proxy_pass http://redis;名稱對應
    server 192.168.244.129:8080;
     server 192.168.244.109:8080;
     #ip_hash;//
}
server {
    listen      8787; //主機端口
    server_name 192.168.0.123:8787; 主機端口 ip
    location / {
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://redis;

    }

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp4)$
        {
            expires    30d;

        }

        location ~ .*\.(js|css)?$
        {
            expires    12h;
        }

}
相關文章
相關標籤/搜索