当前位置: 首页 > 后端技术 > PHP

ubuntu16.04上快速安装LNMP

时间:2023-03-29 20:17:18 PHP

ubuntu16默认安装LNMP(nginx:1.10php:7.0mysql:5.7)1.更新ubuntu软件源:apt-getupdate2。安装nginx:apt-getinstallnginx访问ip可以看到WelcomeNginx界面,说明nginx安装成功3.安装mysql:apt-getinstallmysql-servermysql-client4。安装php:apt-getinstallphpphp-gdphp-xmlphp-mbstringphp-curlphp-mysqlphp-mongodb5.nginx简单配置:vim/etc/php/7.0/fpm/pool.d/www.conf#修改php-fpm配置文件listen=/run/php/php7.0-fpm.sock#listen=127.0.0.1:9000php-fpm7.0-t#检查配置文件是否有错误servicephp7.0-fpmrestart#Restartphp-fpm7.0vim/etc/nginx/sites-enabled/default#修改nginx配置文件root/var/www;#如果你使用的是PHPindex,则在列表中添加index.phpindex.phpindex.htmlindex.htmindex.htmlnginx-debian.html;location~\.php${#socket方法必须和php-fpm设置的监听路径一致#Withphp7.0-fpm:fastcgi_passunix:/run/php/php7.0-fpm。短袜;#单独使用php7.0-cgi:#fastcgi_pass127.0.0.1:9000;}nginx-t#检查配置文件是否有错误servicenginxrestart#重启nginx6。网站测试:mkdir/var/www/testecho'/var/www/test/index.phpchown-Rwww-data:www-data/var/www/test&&chmod-R755/var/www/testcd/etc/nginx/conf.dvimtest.conf写入以下内容:server{listen80default_server;听[::]:80默认服务器;根/var/www/测试;indexindex.phpindex.htmlindex.htm;服务器名称_;#禁止执行PHP目录。位置~.*(Images|images|Img|img|Template|template|Upload|upload|Public|public)/.*\.php${denyall;}#设置图片缓存为30天,暂时注释掉location~.*\.(gif|jpg|jpeg|png|bmp|swf)${expires30d;}#设置js和css缓存为12小时,暂时注释掉location~.*\.(js|css)?${expires12h;}location/{try_files$uri$uri/=404;}location~\.php${fastcgi_passunix:/var/run/php/php7.0-fpm.sock;fastcgi_indexindex.php;包括fastcgi_params;}}servicenginx重启浏览器访问http:ip地址/index.php![image](https://image-static.segmentfault.com/187/290/1872904387-6017b9333f0f3)见上页意思是网站搭建成功后,可以去万网,阿里云或者腾讯云购买域名,修改nginx配置,然后使用域名访问7.扩展安装(mongodb,php扩展前面4步已经安装好了):apt-getinstallmongodb