ubuntu 18.04 部署 laravel(一键安装,超级便捷)

原稿来自无尘

vscode连接docker

每次关闭docker再重启后需要在docker中重启ssh服务
service ssh start

最新安装

docker 部署 nginx 需要注意:sudo DEBIAN_FRONTEND=noninteractive apt-get -y install [packagename]
如果需要运行级别 : RUNLEVEL=1

  • sudo DEBIAN_FRONTEND告知操作系统应该从哪儿获得用户输入。如果设置为”noninteractive”,你就可以直接运行命令,而无需向用户请求输入(所有操作都是非交互式的)

docker 安装php 一键指令:

apt update 
 && DEBIAN_FRONTEND=noninteractive apt install -y software-properties-common 
 && DEBIAN_FRONTEND=noninteractive add-apt-repository -y ppa:ondrej/php 
 && apt-get update && DEBIAN_FRONTEND=noninteractive RUNLEVEL=1 apt install -y php8.1 php8.1-cli php8.1-fpm php8.1-mbstring php8.1-xml php8.1-bcmath php8.1-curl php8.1-gd php8.1-mysql php8.1-opcache php8.1-zip php8.1-sqlite3 
 && php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
 && php composer-setup.php 
 && php -r "unlink('composer-setup.php');" 
 && cp composer.phar /usr/bin/composer 
 && composer -g config repo.packagist composer https://mirrors.aliyun.com/composer/       && apt update 
 && DEBIAN_FRONTEND=noninteractive apt install -y unzip 
 && composer global require laravel/installer

一键指令拆解解释

docker 安装composer 一键指令

下载安装脚本 - composer-setup.php - 到当前目录

php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"

执行安装过程

php composer-setup.php

删除安装脚本

php -r "unlink('composer-setup.php');"

更换源

composer -g config repo.packagist composer https://mirrors.aliyun.com/composer/

安装laravel

composer global require laravel/installer
laravel new example-app
cd example-app

开启外部访问

php artisan serve --host 0.0.0.0

创建laravel项目

早期安装(手动单指令)

sudo apt update
sudo apt upgrade

安装nginx

 sudo apt install nginx -y
 nginx -v
 sudo apt install -y software-properties-common
 sudo add-apt-repository -y ppa:ondrej/php
 sudo apt-get update
 sudo apt install -y php7.4 php7.4-cli php7.4-fpm php7.4-mbstring php7.4-xml php7.4-bcmath php7.4-curl php7.4-gd php7.4-mysql php7.4-opcache php7.4-zip php7.4-sqlite3
 php -v 

安装MYSQL

 sudo apt-get install mysql-server
 apt-get install mysql-client
 sudo apt-get install libmysqlclient-dev
 sudo mysql -u root -p
 (默认回车)
 create user 'test'@'localhost' identified by '123456';
  (外网访问)
 create user 'test'@'%' identified by '123456';
 (刷新权限)
 flush privileges;
 quit;

redis

 apt install redis -y

git

 sudo apt install -y git
 sudo git --version

安装composer

 sudo apt-get install composer
 composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
 composer global require hirak/prestissimo

管理程序

 sudo systemctl start nginx
 systemctl status nginx

解压缩文件

 sudo apt install unzip -y

进入目录安装laravel

 composer create-project laravel/laravel docs
  • 或者 下载laravel安装器
  1. composer global require laravel/installer
  2. laravel new blog

部署nginx配置文件

 cd /etc/nginx/sites-available
 touch laravel
 sudo vim laravel
 里面内容:详情见ubuntu部署laravel.txt
 sudo vim /etc/nginx/nginx.conf
 末尾添加 include /etc/nginx/sites-enabled/*;

重启服务

  systemctl reload nginx

进入框架目录 开始框架服务

 php artisan serve --host=192.168.0.98 --port=8000

注意事项、

  • 一.报错一
- Cannot create cache directory /home/atlas/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
  • 解决办法(添加用户权限):
 sudo chown -R $USER ~/.composer/

  • 二.报错二
 Warning from https://packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/
  • 解决办法:
1. apt-get purge composer
2. php -r "copy('https://getcomposer.org/installer','composer-setup.php');"
3. sudo php composer-setup.php --install-dir=/usr/bin --filename=composer;
4. composer self-update

  • 三、出现问题
 Failed to decode zlib stream
  • 解决办法:
 sudo apt-get install -y zlibc 

你可能感兴趣的:(ubuntu,laravel,php)