Ubuntu 18.04 deploy Web platform (Apache + PHP and Nginx + PHP)

First, the experimental environment Description

jia @ test: ~ $ lsb_release -a // Check system version

jia @ test: ~ $ uname -a // Check the system is 64-bit or 32-bit

2. Package Release Notes

    Apache2:2.4.29

    Nginx:1.14.0

    PHP:7.2.19

    PHP-fpm:7.2

 

Second, install Apache + Php Web platform

  1. Install the software Php and Php-fpm

    jia @ test: ~ $ sudo apt install php // Php installation package

  Since non-user user ROOT, ROOT permissions need to perform the installation, use solid sudo here to install, to use in particular sudo omitted here

  Enter the current user password

   Enter "y", allows the mounting operation

   See what the picture that is successfully installed

 

    Ubuntu server system comes with the appropriate version of the software to install Apache2 above Php software, so this Apache + Php is already installed, and only need to test

 

  2. Test Apache + Php Web platform

  jia @ test: ~ $ ps aux | grep apache // Check Apache service is started

  The following screen appears indicating the service to start direct access, access address: http: // This server IP

 

    If the command is executed, the following screen, the Apache service does not start before they can be started manually after a visit

    jia @ test: ~ $ systemctl start apache2 // start the Apache service

  Enter the user's password here to use

    The following screen to start the service that is successful

    View the Apache server process again

   It has started successfully, access the Web page to access the address: http: // IP address of this server;

   PHP write test code to see if you can parse PHP code

  jia @ test: / var / www / html $ sudo echo "<php ​​phpinfo ();??>"> index.html // cover page html content

  

  jia@test:/var/www/html$ sudo mv index.html index.php    //修改主页名称,修改为index.php

  

    再次访问,看到以下画面即PHP测试代码解析成功  Apache+Php即完成搭建

  

 

 

   三、安装Nginx+Php Web平台

   1.安装Nginx和php-fpm软件

   jia@test:~$ sudo apt-get install nginx  //安装Nginx软件包
    输入当前用户密码

    输入“y”,同意进行下载安装

 

     看到以下画面表示已经安装成功,但是有一个警告,警告提示“Nginx服务未启动,原因是80端口被占用”,出现这个警告原因是之前Apache2服务未关闭造成的

 

    jia@test:~$ sudo systemctl  stop apache2    //关闭Apache2服务  

    jia@test:~$ sudo systemctl start nginx    //启动Nginx服务

    使用浏览器访问一下,浏览器显示Nginx欢迎页面即表示,安装成功

    jia@test:~$ sudo apt-get install php-fpm    //安装php-fpm中间连接软件

 

    下载安装完成,在使用之前还需要配置一些东西,首先需要修改Php的配置文件,php.ini这个文件

  jia@test:~$ sudo vim /etc/php/7.2/fpm/php.ini   //使用VI打开php.ini文件进行编辑

    找到“cgi.fix_pathinfo=1”,将值“1”改为值“0”

 

    更改后

    还需要对pool.d目录下面的www.conf这个文件进行编辑,修改方法使用以上方法进行修改即可,有些参数仅仅只是删除前面的分号“;”注释

  修改参数:

    listen =127.0.0.1:9000

    listen.allowed_clients  = 127.0.0.1

    pm.max.children = 50

    pm.max_requests = 500

    request_terminate_timout = 0

    rlimit_files = 1024

  修改完成以上参数后,启动php-fpm

  jia@test:~$ systemctl start php7.2-fpm    //启动php-fpm

    启动成功后会启动相关进程和端口

    jia@test:~$ netstat -anpt | grep 9000  \\查看相关端口

 

 

   二、配置Nginx支持Php

   /etc/nginx/sites-available/下面的default文件中增加一下内容

      location ~ \.php$ {
      root html;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
      include fastcgi_params;

      

  注意:添加的内容一定要在Server这个大的容器内

      在index行添加index.php为首选项

 

      OK,修改完成保存后重新加载Nginx服务

    jia@test:~$ systemctl reload nginx    \\重新加载Nginx配置

  加载完成后使用浏览器访问页面,访问的连接地址:http://本服务器IP/index.php  访问连接后面加index.php是为了防止加载Nginx安装时自带的欢迎页面

Guess you like

Origin www.linuxidc.com/Linux/2019-10/160949.htm