LAMP+LNMP安装注意问题及安装

智数幽篁引
• 阅读 2580

一、LAMP安装注意事项

  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才能生效

二、LNMP安装
必须开启 --enbale-fpm

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 改为想要的目录
打开一下 #

#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指 定义的根目录

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 =www

还要建立 /tmp/php-fcgi.sock; touch /tmp/php-fcgi.sock

chown www:www /tmp/php-fcgi.sock 赋予其权限

nginx -s reload

php-fpm 重启

配置文件 :


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;
        }

}
点赞
收藏
评论区
推荐文章
Stella981 Stella981
4年前
Nginx配置https
一、开启nginx的ssl模块1.未安装过nginx,编译安装配置参数如下:./configure\prefix/usr/local/nginx\withpcre\withhttp\_ssl\_modulessl模块\withhttp\_stub\_status\_module\wit
Stella981 Stella981
4年前
CentOS 6.4 安装 media wiki 1.23.6(转)
准备:CentOS6.4系统及Root或者sudo权限,系统正常连接网络使用到的软件:apache,mysqlserver,php,mediawiki,memcached软件包的安装首先,需要安装apache,php,mysqlserver,mysqlclient等相关软件包
Stella981 Stella981
4年前
Linux下php安装Redis扩展
1安装redis/usr/local/php/bin/phpize用phpize生成configure配置文件./configurewithphpconfig/usr/local/php/bin/phpconfig配置1make编译2makeinstall安装
Wesley13 Wesley13
4年前
PHP手动安装扩展
进入源码目录下的EXTcdphp/ext/使用PHP安装扩展工具phpize/usr/local/php/bin/phpize进入源码目录编译安装可以看到再EXT目录下生成里一些文件,执行./configureenablewithphpc
Stella981 Stella981
4年前
Centos6.8阿里云linux系统下配置LAMP运行环境
1.Apache安装apache软件yumyinstallhttpd启动httpd服务servicehttpdstart设置开机启动chkconfiglisthttpd查看chkconfighttpdon进入配置文件修改服务器名
Wesley13 Wesley13
4年前
Ubuntu 下 Apache2 和 PHP 服务器环境配置
Ubuntu下Apache2和PHP服务器环境配置1、简介本文主要是Ubuntu下Apache2和PHP服务器环境配置方法,同样适用于Debian系统:Ubuntu20.0.4注意:文中运行的命令基本上需要管理员权限2、安装Apache
Stella981 Stella981
4年前
Linux基础(day42)
11.14/11.15Apache和PHP结合配置httpd支持php目录概要httpd主配置文件/usr/local/apache2.4/conf/httpd.confvim/usr/local/apache2.4/conf/httpd.con
Wesley13 Wesley13
4年前
Ubuntu 下 Apache、php、mysql默认安装路径
apache:如果采用RPM包安装,安装路径应在/etc/httpd目录下apache配置文件:/etc/httpd/conf/httpd.confApache模块路径:/usr/sbin/apachectlweb目录:/var/www/html如果采用源代码安装,一般默认安装在/usr/local/apache2目录下
Wesley13 Wesley13
4年前
ubuntu16.04下 apache2.4和php7结合编译安装,并安裝PDOmysql扩展
1、编译安装apache2.4.201第一步:./configureprefix/usr/local/httpdenableso2第二步:make3第三步:sudomakeinstall2、编译安装libiconv   到这去下载,并编译安装    http://w
Stella981 Stella981
4年前
Apache用户认证命令解析
用户认证模块所用相关命令知识扩展要使用用户认证功能,你需要确保mod_authn_core或mod_authz_core模块在器在安装时就编译进了服务器内或者在apache主配置文件内加载上述2模块之一。root@localhost~grep"mod_authn_core"/usr/local/apache/co
dkll dkll
2星期前
2026商用版婚恋相亲交友APP系统源码,支持H5/小程序/APP,搭配安装手册搭建部署教程
后台安装步骤【简易版】1、在服务器里安装宝塔。下载www.bt.cn。宝塔安装完毕后,安装环境,Nginx或者Apache请选择PHP7.3数据库mysql5.6。2、进入宝塔添加网站,选择和数据库一起创建。3、添加网站后请配置一下网站,4、将后端PHP源