GVKun编程网logo

LAMP(Apache+Nginx+Php)

30

本文将带您了解关于LAMP(Apache+Nginx+Php)的新内容,另外,我们还将为您提供关于nginx优化突破十万并发nginxapachenginxphpnginxrewrite、NGINX使

本文将带您了解关于LAMP(Apache+Nginx+Php)的新内容,另外,我们还将为您提供关于nginx 优化突破十万并发 nginx apache nginx php nginx rewrite、NGINX 使用 nginx apache nginx php nginx rewrite、Nginx 多个版本都适用的伪静态配置 nginx apache nginx php nginx rewrite、nginx 多个站点配置 nginx apache nginx php nginx rewrite的实用信息。

本文目录一览:

LAMP(Apache+Nginx+Php)

LAMP(Apache+Nginx+Php)

一、LAMP应用平台概述:

1.概述:LAMP是目前最成熟的一种企业网站应用模式,可以提供动态web站点应用及开发环境,其构成linux、apache、MysqL、PHP或python或perl等语言,优势:成本低、易于开发、方便易用、安全稳定;
2.网站分类:
静态:有纯html标签语言编写而成的页面,无论在什么环境,什么身份访问都不会发生变化;
动态:由网页的编程语言编写,例:java、PHP、.net、python语言,的动态页面,动态页面是由动态页面和html组成为一个网页页面,可以与数据库进行交互,可以通过动态页面对服务器构成操作;
3.PHP(超文本预处理语言):是一种服务器端html嵌入式语言,支持windows、linux、unix等多平台;

二、LAMP工作原理:

1.LAMP的处理流程:
apache:提供web的访问,客户端和服务器之间网页的传输;
PHP:提供.PHP页面的运行环境;
MysqL:提供.PHP页面或者用户数据存放和写入位置;

三、案例:部署LAMP应用平台;

案列环境

1.apache安装

apache 组件
httpd-2.4.29.tar.gzt apr-1.6.2.tar.gz apr-util-1.6.0.tar.gz (跨平台工具组件包)

1.准备apache安装包

tar xf /mnt/apr-1.6.2.tar.gz -C /opt #将跨平台组件包解压到/opt目录下
tar xf /mnt/apr-util-1.6.0.tar.gz -C /opt #将跨平台组件包解压到/opt目录下
tar xf /mnt/httpd-2.4.29.tar.bz2 -C /opt #解压apache安装包
mv /opt/apr-1.6.2 /opt/httpd-2.4.29/srclib/apr #将跨平台组件包剪切到 /httpd-2.4.29/srclib目录并且更名为 apr
mv /opt/apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util 

2.装备环境包

yum -y install \
gcc \  #C语言编译器
gcc-c++ \ #C++编译器
make \ #make工具(把源代码文件转换成二进制可执行文件)
pcre-devel \ #pcre语言的开发
expat-devel \  #解析html文件
perl #pace编辑器

3.配置apache

cd /opt/httpd-2.4.29 #cd到httpd-2.4.29目录
./configure \
--prefix=/usr/local/httpd \ #--prefix 自定将httpd服务程序安装到哪个目录
--enable-so \  #--enable-so 启用动态模块支持,使httpd具备进一步扩展功能的能力
--enable-rewrite \ #--enable-rewrite 启用网页地址重写功能,用于网站优化及目录迁移维护
--enable-charset-lite \ #--enable-chaset-lite 启用字符支持 以便使用各种字符集编码的网页
--enable-cgi #启用CGI脚本程序支持,便于扩展网站的应的应用访问能力

4.编译与安装

[root@hui httpd-2.4.29]# make #将源代码转换为可执行的程序
[root@hui httpd-2.4.29]# make install #安装

5.添加httpd系统服务(配置启动脚本,建立可以控制住的服务脚本)

[root@hui ~]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd  #将apachetcl(启动脚本)复制为/etc/init.d/httpd
`[root@hui ~]# sed -i -e '1 a# chkconfig: 35 85 21 ' -e '2 i # description: Apache is a World Wide Web server' /etc/init.d/httpd`  #在文件开头添加chkconfig 识别配置, chkconfig:35 85 21 //服务识别参数,在级别3,5中启动;启动和关闭的顺序分别85、21 
[root@hui ~]# chkconfig --add httpd  #将httpd添加为系统服务

6.确定网站名称、IP地址,配置httpd服务

[root@hui ~]sed -i '/#ServerName www.example.com.com:80/s/example/yum/ '/usr/local/httpd/conf/httpd.conf #修改网站名称

[root@hui ~]sed -i -e '/Listen 80/s/^/#/' -e  '/#Listen 12.34.56.78:80/s/#Listen 12.34.56.78:80/Listen 192.168.242.157/' /usr/local/httpd/conf/httpd.conf #修改web主机的IP地址

7.优化执行路径--通过源码编译安装的httpd服务,程序路径并不在默认的搜索路径中,为了是该服务在使用时更加方便,可以为相关程序怎加符号链接。

[root@hui ~]ln -s /usr/local/httpd/conf/httpd.conf /etc/  #
[root@hui ~]ln -s /usr/local/httpd/bin/* /usr/local/bin/

8.关闭防火墙,启动服务
systemctl stop firewalld.service
setenforce 0
service httpd start

二.安装MysqL

1.安装环境包
[root@hui ~]# yum install -y ncurses-devel autoconf cmake
2.源码编译以及安装
(1)解包

[root@hui mnt]# tar /mnt/mysql-5.6.26.tar.gz -C /opt

(2)配置
[root@hui mysql-5.6.26]# cd /opt/mysql-5.6.26/

[root@hui mysql-5.6.26]cmake  \
-DCMAKE_INSTALL_PREFIX=/usr/local/MysqL \ #指定将MysqL数据库程序安装到目录下
-DDEFAULT_CHARSET=utf8 \  #指定默认使用的字符集编码
-DDEFAULT_COLLATION=utf8_general_ci \ #指定默认使用的字符集校验对规则
-DEXTRA_CHARSETS=all \ #拓展字符集
-DSYSCONFIDIR=/etc \ #指定初始化参数文件目录
-DMysqL_DATADIR=/home/MysqL/ \
-DMysqL_UNIX_ADDR=/home/MysqL/MysqL.sock  #连接数据库文件

(3)编译安装
<br/>[root@hui mysql-5.6.26]# make && make install

3.添加系统服务和建立配置文件(添加MysqL系统服务,以便通过chkconfig进行管理,可以直接使用源码包中提供的服务脚本。找到support-files文件夹下的MysqL.server 脚本文件,将其复制到/etc/init.d/目录下,改名为MysqLd)

[root@hui mysql-5.6.26]#cp -f support-files/my-default.cnf /etc/my.cnf # 把配置文件复制到/etc/目录下,并且改名为my.cnf
[root@hui mysql-5.6.26]# cp support-files/MysqL.server /etc/init.d/MysqLd #把启动文件复制到/etc/init.d/目录下 ,并且改名为MysqLd。
[root@hui mysql-5.6.26]# chmod 755 /etc/init.d/MysqLd     #设置可执行权限
[root@hui mysql-5.6.26]# chkconfig --add /etc/init.d/MysqLd #通过chkconfig命令将其添加为MysqLd系统服务,这样可以用service工具控制MysqL数据库服务
[root@hui mysql-5.6.26]#chkconfig  MysqLd --level 235 on

4.设置环境变量--为了方便在任何目录下使用MySQL命令,需要在/etc/profile 设置环境变量。

[root@hui mysql-5.6.26]#echo "PATH=$PATH:/usr/local/MysqL/bin" >> /etc/profile #设置MySQL命令的环境变量
[root@hui mysql-5.6.26]#source /etc/profile #立即执行

5.关键运行用户--为了加强数据库服务的权限控制,建议使用专门的运行用户,如MysqL。此用户不需要直接登录到系统
[root@hui mysql-5.6.26]# useradd -s /sbin/nologin MysqL #创建MysqL用户
[root@hui mysql-5.6.26]# chown -R MysqL:MysqL /usr/local/mysq 对数据库目录进行权限设置
6.初始化数据库--为了能够正常时候用MysqL数据库系统,应以运行用户MysqL的身份执行初始化脚本MysqL_install_db,指定数据存放目录等

/usr/local/MysqL/scripts/MysqL_install_db \
--user=MysqL \
--ldata=/var/lib/MysqL \
--basedir=/usr/local/MysqL \
--datadir=/home/MysqL

7.

[root@hui mysql-5.6.26]# ln -s /var/lib/MysqL/MysqL.sock  /home/MysqL/MysqL.sock
[root@hui mysql-5.6.26]# sed -i -e '/basedir=/c basedir=/usr/local/MysqL' -e 'datadir=/c datadir=/home/MysqL' /etc/init.d/MysqLd

[root@hui mysql-5.6.26]#service MysqLd start
[root@hui mysql-5.6.26]#MysqLadmin -u root -p password "abc123" //给root账号设置密码

三.安装PHP

1.装备环境

[root@localhost ~]yum -y install \
gd \   #图像化处理库
libpng \ #支持png图片
libpng-devel \
pcre \ #支持正则表达式
pcre-devel \ #支持正则表达式
libxml2-devel \ #支持解析html语言
libjpeg-devel #支持jpeg图片

2.编译安装PHP
(1).解压


[root@localhost ~]tar xf PHP-5.6.11.tar.bz2 -C /opt
[root@localhost opt]# cd /opt/PHP-5.6.11/

(2).配置

[root@localhost PHP-5.6.11]#./configure \
--prefix=/usr/local/PHP5 \ #指定安装路径
--with-gd \ #gd库
--with-zlib \ #压缩
--with-apxs2=/usr/local/httpd/bin/apxs \ #设置Apache HTTPServer 提供的apxs模块支持程序的文件位置
--with-MysqL=/usr/local/MysqL \ #设置MysqL数据库服务程序的安装位置
--with-config-file-path=/usr/local/PHP5 \ #设置PHP的配置文件PHP.ini将要存放的位置
--enable-mbstring #启用多字节字符串功能,以便支持中文代码

(3)编译与安装

[root@localhost PHP-5.6.11]# make
[root@localhost PHP-5.6.11]# make install

3.设置LAMP组件环境
设置LAMP组件环境,主要包括对PHP的配置文件PHP.ini、Apche的配置文件httpd.conf的调整。前者用来确定PHP的运行参数,后者用来加载libPHP5.so模块,以便支持PHP网页。
(1)调整配置文件

[root@localhost PHP-5.6.11]# cp PHP.ini-development /usr/local/PHP5/PHP.ini #复制配置文件到 /usr/local/PHP5/ 目录下并且取名为:PHP.ini
[root@localhost PHP-5.6.11]# ln -s /usr/local/PHP5/bin/* /usr/local/bin/  #对/usr/local/PHP5/bin/*  命令做软连接,便于系统识别

(2).调整httpd.conf配置
要使httpd服务器支持PHP网页解析功能,需要通过LoadModule配置加载PHP程序的模块文件,并通过AddType配置项添加对“.PHP”类型网页文件的支持。

[root@localhost ~]#sed -i '/DirectoryIndex index.html/ c  DirectoryIndex index.html index.PHP' /etc/httpd.conf # 修改**DirectroryIndex**配置行 ,添加index.PHP,来识别常见的PHP首页文件
[root@localhost ~]# sed -i '393 a AddType application/x-httpd-PHP .PHP' /etc/httpd.conf  #设置对.PHP文件的支持

[root@localhost ~]# sed -i '394 a AddType application/x-httpd-PHP-source .PHPs' /etc/httpd.conf #
[root@localhost ~]cat >>/usr/local/httpd/htdocs/index.PHP <<-EOF
> <?PHP
> PHPinfo();
> ?>
> EOF

[root@localhost ~]# sed -i '394 a AddType application/x-httpd-PHP-source .PHPs' /etc/httpd.conf #
[root@localhost ~]cat >>/usr/local/httpd/htdocs/index.PHP <<-EOF

<?PHP
PHPinfo();
?>
EOF

nginx 优化突破十万并发 nginx apache nginx php nginx rewrite

nginx 优化突破十万并发 nginx apache nginx php nginx rewrite

NGINX 使用 nginx apache nginx php nginx rewrite

NGINX 使用 nginx apache nginx php nginx rewrite

Nginx 多个版本都适用的伪静态配置 nginx apache nginx php nginx rewrite

Nginx 多个版本都适用的伪静态配置 nginx apache nginx php nginx rewrite

nginx 多个站点配置 nginx apache nginx php nginx rewrite

nginx 多个站点配置 nginx apache nginx php nginx rewrite

服务器地址:192.168.1.231

域名:test1.com 目录:/www/test1.com

域名:test2.com 目录:/www/test2.com

该配置思路

把2个站点 test1.com, test2.com 放到 nginx 可以访问的目录 /www/
给每个站点分别创建一个 nginx 配置文件 test1.com.conf,test2.com.conf, 并把配置文件放到 /etc/nginx/vhosts/
然后在 /etc/nginx.conf 里面加一句 include 把步骤2创建的配置文件全部包含进来(用 * 号)
重启 nginx

实际操作:

[root@localhost ~]# mkdir /www/test1.com
[root@localhost ~]# mkdir /www/test2.com
[root@localhost ~]# cd /etc/nginx/
[root@localhost nginx]# mkdir vhosts
[root@localhost nginx]# cd vhosts/
[root@localhost vhosts]# vi test1.com.conf 
#增加以下内容
server {
        listen  80;
        server_name  test1.com www.test1.com;
        access_log  /www/access_test1.log  main;
        location / {
            root   /www/test1.com;
            index  index.php index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.html;
            fastcgi_param  SCRIPT_FILENAME  /www/test1.com/$fastcgi_script_name;
            include        fastcgi_params;
        }
        location ~ /.ht {
            deny  all;
        }
}
[root@localhost vhosts]# vi test2.com.conf 
#增加以下内容
server {
        listen  80;
        server_name  test2.com www.test2.com;

        access_log  /www/access_test2.log  main;

        location / {
            root   /www/test2.com;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.html;
            fastcgi_param  SCRIPT_FILENAME  /www/test2.com/$fastcgi_script_name;
            include        fastcgi_params;
        }

        location ~ /.ht {
            deny  all;
        }
}
登录后复制

修改nginx.conf

备份配置文件

立即学习“PHP免费学习笔记(深入)”;


[root@localhost ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf20160425
[root@localhost ~]# vi /etc/nginx/nginx.conf.
#修改成以下内容
user  nginx;
worker_processes  1;

# main server error log
error_log       /var/log/nginx/error.log ;
pid     /var/run/nginx.pid;
events {
        worker_connections  1024;
}
# main server config
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"'';
        sendfile        on;
        #tcp_nopush     on;
        #keepalive_timeout  0;
        keepalive_timeout  65;
        gzip  on;
        server {
                listen         80;
                server_name     _;
                access_log      /var/log/nginx/access.log main;
                server_name_in_redirect  off;
                location / {
                        root  /usr/share/nginx/html;
                        index index.html;
                }
        }
    # 这一行是加载上面的配置文件
    include /etc/nginx/vhosts/*;
}

重起nginx服务
[root@localhost ~]# service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[root@localhost ~]# 
登录后复制

下面我们进行测试是否成功

将nginx默认页面/usr/html/index.html 分别拷备到/www/test1.com和/www/test2.com里面

然后将index.html里面的内容分别改成test1.com和test2.com

测试机为windowns

修改host文件

# localhost name resolution is handled within DNS itself.

#    127.0.0.1       localhost

#    ::1             localhost

192.168.1.231    www.test1.com

192.168.1.231    www.test2.com

在该服务器上分别打开www.test1.com

test1.com

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.

Commercial support is available at nginx.com.

Thank you for using nginx.

在该服务器上分别打开www.test2.com

test2.com

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.

Commercial support is available at nginx.com.

Thank you for using nginx.

测试成功!!!!!


以上就介绍了nginx 多个站点配置,包括了nginx方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

今天关于LAMP(Apache+Nginx+Php)的讲解已经结束,谢谢您的阅读,如果想了解更多关于nginx 优化突破十万并发 nginx apache nginx php nginx rewrite、NGINX 使用 nginx apache nginx php nginx rewrite、Nginx 多个版本都适用的伪静态配置 nginx apache nginx php nginx rewrite、nginx 多个站点配置 nginx apache nginx php nginx rewrite的相关知识,请在本站搜索。

本文标签: