ubuntu 安装LNMP


  1. 安装 nginx

    $ sudo apt-get install nginx

    安装完毕,默认已经启动,如果未启动, 可以使用sudo service nginx start 命令手动启动.

    $ ps aux | grep nginx
    root      8860  0.0  0.0 135800  1508 ?        Ss   22:19   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;

    打开http://localhost/ ,可以看到nginx的欢迎界面, 即表示安装成功.

  2. 安装php-fpm,

    $ sudo apt install php7.0-fpm
  3. 修改ng配置, 在index中添加index.php, 开启 php解析的注释

    $ sudo vim /etc/nginx/sites-available/default
    server {
     ...
     root /var/www/html;
       # Add index.php to the list if you are using PHP
       index index.php index.html index.htm index.nginx-debian.html;
     ...
     location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         # With php-fpm (or other unix sockets):
         fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
         # With php-cgi (or other tcp sockets):
         # fastcgi_pass 127.0.0.1:9000;
     }
     ...
    }

    重启nginx, $ sudo service nginx restart

  4. /var/www/html中,创建test.php测试文件,打开http://localhost/test.php,查看是否设置成功.

    <?php
    echo phpinfo();
  5. 安装mysql, 设置用户密码, 注意:命令行屏幕注意不要缩的太小,否则无法设置root密码

    $ sudo apt install mysql-client-5.7 mysql-server-5.7
  6. 安装phpmyadmin, 会默认安装一些必备的php依赖的, 所以无需自己手动安装php7.0-mysql

    $ sudo apt install phpmyadmin
  7. 至此, LNMP已经安装完毕.

参考文档


Author: Itaken
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Itaken !
  TOC目录