ubuntu中搭建lnmp环境部署laravel9框架项目流程步骤

2023-06-01 00:00:00 框架 部署 搭建

ubuntu系统中部署laravel9框架项目,centos7马上就要停止维护;

我打算后面可能用ubuntu替换,所以先搞两个项目跑跑测试测试;

不过后面的话基本也是用基于docke的dnmp环境了。

ubuntu版本:

[email protected]:~# lsb_release -a
LSB Version:core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID:Ubuntu
Description:Ubuntu 20.04.3 LTS
Release:20.04
Codename:focal


lnmp环境:LNMP一键安装包V1.8正式版

[email protected]:~# php -v
PHP 8.0.8 (cli) (built: Mar  2 2022 11:43:54) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.8, Copyright (c), by Zend Technologies
[email protected]:~# mysql -V
mysql  Ver 8.0.28 for Linux on x86_64 (Source distribution)
[email protected]:~# nginx -v
nginx version: nginx/1.20.1

安装好了 如下:

[email protected]:~# lnmp status
+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
|              https://lnmp.org             |
+-------------------------------------------+
nginx (pid 222682) is running...
php-fpm is runing!
● mysql.service - MySQL Community Server
     Loaded: loaded (/etc/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-03-02 13:13:24 CST; 2h 11min ago
    Process: 222699 ExecStart=/etc/init.d/mysql start (code=exited, status=0/SUCCESS)
   Main PID: 222714 (mysqld_safe)
      Tasks: 17 (limit: 19140)
     Memory: 171.1M
     CGroup: /system.slice/mysql.service
             ├─222714 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/var --pid-file=/usr/local/mysql/var/iZwz984fp76m12whtx8tpgZ.pid
             └─223225 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-err…
Mar 02 13:13:22 iZwz984fp76m12whtx8tpgZ systemd[1]: Starting MySQL Community Server...
Mar 02 13:13:22 iZwz984fp76m12whtx8tpgZ mysql[222699]: Starting MySQL
Mar 02 13:13:24 iZwz984fp76m12whtx8tpgZ mysql[222699]: .. *
Mar 02 13:13:24 iZwz984fp76m12whtx8tpgZ systemd[1]: Started MySQL Community Server.


安装opcache 

[email protected]:~/lnmp1.8# ./addons.sh install opcache 


注释掉fastcgi.conf中的open_basedir的配置,安全问题会出现500错误

/usr/local/nginx/conf/fastcgi.conf
#fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";



在php.ini配置文件中删除php禁用函数disable_functions

/usr/local/php/etc/php.ini 
proc_open,proc_get_status


创建laravel9项目nginx配置文件 做点简单配置

/usr/local/nginx/conf/vhost/laraver9.conf
server
    {
        listen 80;
        server_name laravel9.com;
index index.html index.htm index.php;
root  /home/www/laravel9/public;
        #error_page   404   /404.html;
        include enable-php.conf;
        location /nginx_status
        {
            stub_status off;
            access_log   off;
        }
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
      
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
access_log   off;
        }
        location ~ .*\.(js|css)?$
        {
           #expires      12h;
access_log   off;       
 }
        location ~ /\.
        {
            deny all;
        }
        access_log  /home/wwwlogs/laravel9.log;
}


拉取laravel9项目准备

因为我用的是阿里云ecs所以git,composer都默认装好了

[email protected]:~# git version
git version 2.25.1
[email protected]:~# composer -v
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.2.6 2022-02-04 17:00:38

新建laravel9项目存放目录/home/www

[email protected]:~# cd /home/www
[email protected]:/home/www# ll
total 8
drwxr-xr-x 2 root root 4096 Mar  2 12:37 ./
drwxr-xr-x 5 root root 4096 Mar  2 12:37 ../

composer拉取最新laravel9.2框架代码

[email protected]:/home/www# composer create-project --prefer-dist laravel/laravel laravel9
Creating a "laravel/laravel" project at "./laravel9"
Installing laravel/laravel (v9.1.0)
  - Installing laravel/laravel (v9.1.0): Extracting archive
Created project in /home/www/laravel9
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Lock file operations: 108 installs, 0 updates, 0 removals
  - Locking brick/math (0.9.3)
...
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 108 installs, 0 updates, 0 removals
  - Downloading doctrine/inflector (2.0.4)
...
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: spatie/laravel-ignition
Package manifest generated successfully.
78 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
No publishable resources for tag [laravel-assets].
Publishing complete.
> @php artisan key:generate --ansi
Application key set successfully.


最后统一重启lnmp服务 

[email protected]:~# lnmp restart

注意:

我这里是统一重启,之前的php配置文件修改也的单独重启php-fpm服务;

修改nginx配置文件也的热加载nginx配置文件 先检测后reload

[email protected]:~# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[email protected]:~# /usr/local/nginx/sbin/nginx -s reload


客户端修改一下hosts 本地解析一下域名

C:\Windows\System32\drivers\etc\hosts
10.0.1.180  laravel9.com


访问一下

laravel9.png


相关文章