lemp wp_如何在Ubuntu 18.04上使用LEMP安装和配置Laravel

lemp wp

介绍 (Introduction)

Laravel is an open-source PHP framework that provides a set of tools and resources to build modern PHP applications. With a complete ecosystem leveraging its built-in features, Laravel’s popularity has grown rapidly in the past few years, with many developers adopting it as their framework of choice for a streamlined development process.

Laravel是一个开放源代码PHP框架,提供了用于构建现代PHP应用程序的一组工具和资源。 凭借其内置功能的完整生态系统 ,Laravel的受欢迎程度在过去几年中Swift增长,许多开发人员将其用作简化开发过程的首选框架。

In this guide, you’ll install and configure a new Laravel application on an Ubuntu 18.04 server, using Composer to download and manage the framework dependencies. When you’re finished, you’ll have a functional Laravel demo application pulling content from a MySQL database.

在本指南中,您将在Ubuntu 18.04服务器上安装和配置新的Laravel应用程序,并使用Composer下载和管理框架依赖项。 完成后,您将拥有一个功能正常的Laravel演示应用程序,可从MySQL数据库中提取内容。

先决条件 (Prerequisites)

In order to complete this guide, you will first need to perform the following tasks on your Ubuntu 18.04 server:

为了完成本指南,您首先需要在Ubuntu 18.04服务器上执行以下任务:

第1步-安装必需PHP模块 (Step 1 — Installing Required PHP modules)

Before you can install Laravel, you need to install a few PHP modules that are required by the framework. We’ll use apt to install the php-mbstring, php-xml and php-bcmath PHP modules. These PHP extensions provide extra support for dealing with character encoding, XML and precision mathematics.

在安装Laravel之前,您需要安装框架所需的一些PHP模块。 我们将使用apt安装php-mbstringphp-xmlphp-bcmath PHP模块。 这些PHP扩展为处理字符编码,XML和精确数学提供了额外的支持。

If this is the first time using apt in this session, you should first run the update command to update the package manager cache:

如果这是此会话中第一次使用apt ,则应首先运行update命令来更新程序包管理器缓存:

  • sudo apt update

    sudo apt更新

Now you can install the required packages with:

现在,您可以通过以下方式安装所需的软件包:

  • sudo apt install php-mbstring php-xml php-bcmath

    sudo apt安装php-mbstring php-xml php-bcmath

Your system is now ready to execute Laravel’s installation via Composer, but before doing so, you’ll need a database for your application.

您的系统现在可以通过Composer执行Laravel的安装了,但是在这样做之前,您需要为应用程序提供数据库。

第2步-为应用程序创建数据库 (Step 2 — Creating a Database for the Application)

To demonstrate Laravel’s basic installation and usage, we’ll create a sample travel list application to show a list of places a user would like to travel to, and a list of places that they already visited. This can be stored in a simple places table with a field for locations that we’ll call name and another field to mark them as visited or not visited, which we’ll call visited. Additionally, we’ll include an id field to uniquely identify each entry.

为了演示Laravel的基本安装和用法,我们将创建一个示例旅行列表应用程序,以显示用户想要旅行的地方列表以及他们已经访问过的地方列表。 这可以存储在一个简单的位置表中,其中有一个我们称之为名称的位置的字段和一个将它们标记为已访问或未访问的字段,我们称之为访问 。 此外,我们将包含一个ID字段,以唯一标识每个条目。

To connect to the database from the Laravel application, we’ll create a dedicated MySQL user, and grant this user full privileges over the travel_list database.

要从Laravel应用程序连接到数据库,我们将创建一个专用MySQL用户,并授予该用户对travel_list数据库的完全特权。

To get started, log in to the MySQL console as the root database user with:

首先,以root数据库用户身份登录MySQL控制台:

  • sudo mysql

    须藤MySQL

To create a new database, run the following command from your MySQL console:

要创建新数据库,请从MySQL控制台运行以下命令:

  • CREATE DATABASE travel_list;

    创建数据库travel_list ;

Now you can create a new user and grant them full privileges on the custom database you’ve just created. In this example, we’re creating a user named travel_user with the password password, though you should change this to a secure password of your choosing:

现在,您可以创建一个新用户,并向他们授予您刚创建的自定义数据库的全部特权。 在此示例中,我们将使用密码password创建一个名为travel_userpassword ,尽管您应将其更改为您选择的安全密码:

  • GRANT ALL ON travel_list.* TO 'travel_user'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

    GRANT ALL ON travel_list * TO 'travel_user 'IDENTIFIED BY ' 密码 ' WITH GRANT OPTION @' localhost'的。

This will give the travel_user user full privileges over the travel_list database, while preventing this user from creating or modifying other databases on your server.

这将为travel_user用户提供对travel_list数据库的完全特权,同时阻止该用户在服务器上创建或修改其他数据库。

Following this, exit the MySQL shell:

接下来,退出MySQL shell:

  • exit

    出口

You can now test if the new user has the proper permissions by logging in to the MySQL console again, this time using the custom user credentials:

现在,您可以使用自定义用户凭据再次登录到MySQL控制台,以测试新用户是否具有适当的权限:

  • mysql -u travel_user -p

    mysql -u travel_user -p

Note the -p flag in this command, which will prompt you for the password used when creating the travel_user user. After logging in to the MySQL console, confirm that you have access to the travel_list database:

请注意此命令中的-p标志,它将提示您输入创建travel_user用户时使用的密码。 登录到MySQL控制台后,确认您有权访问travel_list数据库:

  • SHOW DATABASES;

    显示数据库;

This will give you the following output:

这将为您提供以下输出:


   
   
Output
+--------------------+ | Database | +--------------------+ | information_schema | | travel_list | +--------------------+ 2 rows in set (0.01 sec)

Next, create a table named places in the travel_list database. From the MySQL console, run the following statement:

接下来,在travel_list数据库中创建一个名为places的表。 在MySQL控制台中,运行以下语句:

  • CREATE TABLE travel_list.places (

    创建表travel_list 。 地方 (

  • id INT AUTO_INCREMENT,

    ID INT AUTO_INCREMENT,
  • name VARCHAR(255),

    名称VARCHAR(255),
  • visited BOOLEAN,

    参观了BOOLEAN,
  • PRIMARY KEY(id)

    主键(id)
  • );

    );

Now, populate the places table with some sample data:

现在,用一些示例数据填充places表:

  • INSERT INTO travel_list.places (name, visited)

    插入到travel_list中 。 地点 (名称,访问过的地点)

  • VALUES ("Tokyo", false),

    值(“ Tokyo ”, false ),

  • ("Budapest", true),

    (“ 布达佩斯 ”, 是的 ),

  • ("Nairobi", false),

    (“ 内罗毕 ”, 假 ),

  • ("Berlin", true),

    (“ 柏林 ”, 是 ),

  • ("Lisbon", true),

    (“ 里斯本 ”, 是 ),

  • ("Denver", false),

    (“ 丹佛 ”, false ),

  • ("Moscow", false),

    (“ 莫斯科 ”, 假 ),

  • ("Olso", false),

    (“ Olso ”, false ),

  • ("Rio", true),

    (“ Rio ”, 是 ),

  • ("Cincinnati", false),

    (“ 辛辛那提 ”, 假 ),

  • ("Helsinki", false);

    (“ 赫尔辛基 ”, 假 );

To confirm that the data was successfully saved to your table, run:

要确认数据已成功保存到表中,请运行:

  • SELECT * FROM travel_list.places;

    选择* FROM travel_list 。 地方 ;

You will see output similar to this:

您将看到类似于以下的输出:


   
   
Output
+----+-----------+---------+ | id | name | visited | +----+-----------+---------+ | 1 | Tokyo | 0 | | 2 | Budapest | 1 | | 3 | Nairobi | 0 | | 4 | Berlin | 1 | | 5 | Lisbon | 1 | | 6 | Denver | 0 | | 7 | Moscow | 0 | | 8 | Oslo | 0 | | 9 | Rio | 1 | | 10 | Cincinnati| 0 | | 11 | Helsinki | 0 | +----+-----------+---------+ 11 rows in set (0.00 sec)

After confirming that you have valid data in your test table, you can exit the MySQL console:

确认测试表中有有效数据后,可以退出MySQL控制台:

  • exit

    出口

You’re now ready to create the application and configure it to connect to the new database.

现在,您可以创建应用程序并将其配置为连接到新数据库了。

步骤3 —创建一个新的Laravel应用程序 (Step 3 — Creating a New Laravel Application)

You will now create a new Laravel application using the composer create-project command. This Composer command is typically used to bootstrap new applications based on existing frameworks and content management systems.

现在,您将使用composer create-project命令创建一个新的Laravel应用程序。 该Composer命令通常用于基于现有框架和内容管理系统来引导新应用程序。

Throughout this guide, we’ll use travel_list as an example application, but you are free to change this to something else. The travel_list application will display a list of locations pulled from a local MySQL server, intended to demonstrate Laravel’s basic configuration and confirm that you’re able to connect to the database.

在本指南中,我们将使用travel_list作为示例应用程序,但是您可以随意将其更改为其他内容。 travel_list应用程序将显示从本地MySQL服务器提取的位置列表,以演示Laravel的基本配置并确认您能够连接到数据库。

First, go to your user’s home directory:

首先,转到用户的主目录:

  • cd ~

    光盘〜

The following command will create a new travel_list directory containing a barebones Laravel application based on default settings:

以下命令将基于默认设置创建一个新的travel_list目录,其中包含准系统Laravel应用程序:

  • composer create-project --prefer-dist laravel/laravel travel_list

    作曲者create-project --prefer-dist laravel / laravel travel_list

You will see output similar to this:

您将看到类似于以下的输出:


   
   
Output
Installing laravel/laravel (v5.8.17) - Installing laravel/laravel (v5.8.17): Downloading (100%) Created project in travel_list > @php -r "file_exists('.env') || copy('.env.example', '.env');" Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 80 installs, 0 updates, 0 removals - Installing symfony/polyfill-ctype (v1.11.0): Downloading (100%) - Installing phpoption/phpoption (1.5.0): Downloading (100%) - Installing vlucas/phpdotenv (v3.4.0): Downloading (100%) - Installing symfony/css-selector (v4.3.2): Downloading (100%) ...

When the installation is finished, access the application’s directory and run Laravel’s artisan command to verify that all components were successfully installed:

安装完成后,访问应用程序的目录并运行Laravel的artisan命令以验证是否成功安装了所有组件:

  • cd travel_list

    cd travel_list

  • php artisan

    PHP工匠

You’ll see output similar to this:

您将看到类似于以下的输出:


   
   
Output
Laravel Framework 5.8.29 Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question --env[=ENV] The environment the command should run under -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug (...)

This output confirms that the application files are in place, and the Laravel command-line tools are working as expected. However, we still need to configure the application to set up the database and a few other details.

此输出确认应用程序文件到位,并且Laravel命令行工具按预期工作。 但是,我们仍然需要配置应用程序以设置数据库和其他一些细节。

步骤4 —配置Laravel (Step 4 — Configuring Laravel)

The Laravel configuration files are located in a directory called config, inside the application’s root directory. Additionally, when you install Laravel with Composer, it creates an environment file. This file contains settings that are specific to the current environment the application is running, and will take precedence over the values set in regular configuration files located at the config directory. Each installation on a new environment requires a tailored environment file to define things such as database connection settings, debug options, application URL, among other items that may vary depending on which environment the application is running.

Laravel配置文件位于应用程序根目录内名为config的目录中。 另外,在将Laravel与Composer一起安装时,它会创建一个环境文件 。 该文件包含特定于应用程序正在运行的当前环境的设置,并且将优先于位于config目录的常规配置文件中设置的值。 在新环境中进行的每次安装都需要一个定制的环境文件来定义诸如数据库连接设置,调试选项,应用程序URL之类的内容,这些其他内容可能会根据应用程序运行的环境而有所不同。

Warning: The environment configuration file contains sensitive information about your server, including database credentials and security keys. For that reason, you should never share this file publicly.

警告 :环境配置文件包含有关服务器的敏感信息,包括数据库凭据和安全密钥。 因此,您永远不应公开共享此文件。

We’ll now edit the .env file to customize the configuration options for the current application environment.

现在,我们将编辑.env文件,以自定义当前应用程序环境的配置选项。

Open the .env file using your command line editor of choice. Here we’ll use nano:

使用您选择的命令行编辑器打开.env文件。 在这里,我们将使用nano

  • nano .env

    纳米.env

Even though there are many configuration variables in this file, you don’t need to set up all of them now. The following list contains an overview of the variables that require immediate attention:

即使此文件中有许多配置变量,您现在也不需要全部设置。 以下列表概述了需要立即注意的变量:

  • APP_NAME: Application name, used for notifications and messages.

    APP_NAME :应用程序名称,用于通知和消息。

  • APP_ENV: Current application environment.

    APP_ENV :当前应用程序环境。

  • APP_KEY: Used for generating salts and hashes, this unique key is automatically created when installing Laravel via Composer, so you don’t need to change it.

    APP_KEY :用于生成盐和哈希,通过Composer安装Laravel时会自动创建此唯一密钥,因此您无需更改它。

  • APP_DEBUG: Whether or not to show debug information at client side.

    APP_DEBUG :是否在客户端显示调试信息。

  • APP_URL: Base URL for the application, used for generating application links.

    APP_URL :应用程序的基本URL,用于生成应用程序链接。

  • DB_DATABASE: Database name.

    DB_DATABASE :数据库名称。

  • DB_USERNAME: Username to connect to the database.

    DB_USERNAME :连接到数据库的用户名。

  • DB_PASSWORD: Password to connect to the database.

    DB_PASSWORD :连接数据库的密码。

By default, these values are configured for a local development environment that uses Homestead, a prepackaged Vagrant box provided by Laravel. We’ll change these values to reflect the current environment settings of our example application.

默认情况下,这些值是为使用Homestead的本地开发环境配置的, Homestead是Laravel提供的预包装的Vagrant框。 我们将更改这些值以反映示例应用程序的当前环境设置。

In case you are installing Laravel in a development or testing environment, you can leave the APP_DEBUG option enabled, as this will give you important debug information while testing the application from a browser. The APP_ENV variable should be set to development or testing in this case.

如果要在开发测试环境中安装Laravel,则可以将APP_DEBUG选项保持启用状态,因为这将为您从浏览器测试应用程序时提供重要的调试信息。 在这种情况下,应将APP_ENV变量设置为developmenttesting

In case you are installing Laravel in a production environment, you should disable the APP_DEBUG option, because it shows to the final user sensitive information about your application. The APP_ENV in this case should be set to production.

如果要在生产环境中安装Laravel,则应禁用APP_DEBUG选项,因为它向最终用户显示有关应用程序的敏感信息。 在这种情况下, APP_ENV应该设置为production

The following .env file sets up our example application for development:

以下.env文件设置了用于开发的示例应用程序:

Note: The APP_KEY variable contains a unique key that was auto generated when you installed Laravel via Composer. You don’t need to change this value. If you want to generate a new secure key, you can use the php artisan key:generate command.

注意APP_KEY变量包含一个唯一密钥,该密钥是通过Composer安装Laravel时自动生成的。 您不需要更改此值。 如果要生成新的安全密钥,可以使用php artisan key:generate命令。

/var/www/travel_list/.env
/var/www/travel_list/.env
APP_NAME=TravelList
APP_ENV=development
APP_KEY=APPLICATION_UNIQUE_KEY_DONT_COPY
APP_DEBUG=true
APP_URL=http://domain_or_IP

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=travel_list
DB_USERNAME=travel_user
DB_PASSWORD=password

...

Adjust your variables accordingly. When you are done editing, save and close the file to keep your changes. If you’re using nano, you can do that with CTRL+X, then Y and Enter to confirm.

相应地调整变量。 完成编辑后,保存并关闭文件以保留更改。 如果您使用的是nano ,则可以使用CTRL+X ,然后使用YEnter进行确认。

Your Laravel application is now set up, but we still need to configure the web server in order to be able to access it from a browser. In the next step, we’ll configure Nginx to serve your Laravel application.

现在,您的Laravel应用程序已设置,但是我们仍然需要配置Web服务器,以便能够从浏览器访问它。 在下一步中,我们将配置Nginx为您的Laravel应用程序提供服务。

步骤5 —设置Nginx (Step 5 — Setting Up Nginx)

We have installed Laravel on a local folder of your remote user’s home directory, and while this works well for local development environments, it’s not a recommended practice for web servers that are open to the public internet. We’ll move the application folder to /var/www, which is the usual location for web applications running on Nginx.

我们已将Laravel安装在远程用户的主目录的本地文件夹上,虽然这对于本地开发环境非常有效,但对于向公共Internet开放的Web服务器,不建议这样做。 我们将应用程序文件夹移动到/var/www ,这是在Nginx上运行的Web应用程序的常用位置。

First, use the mv command to move the application folder with all its contents to /var/www/travel_list:

首先,使用mv命令将应用程序文件夹及其所有内容移动到/var/www/travel_list

  • sudo mv ~/travel_list /var/www/travel_list

    须藤MV〜 / travel_list / var / www / travel_list

Now we need to give the web server user write access to the storage and cache folders, where Laravel stores application-generated files:

现在,我们需要为Web服务器用户提供对storagecache文件夹的写访问权,Laravel在其中存储应用程序生成的文件:

  • sudo chown -R www-data.www-data /var/www/travel_list/storage

    须藤chown -R www-data.www-data / var / www / travel_list / storage

  • sudo chown -R www-data.www-data /var/www/travel_list/bootstrap/cache

    须藤chown -R www-data.www-data / var / www / travel_list / bootstrap / cache

The application files are now in order, but we still need to configure Nginx to serve the content. To do this, we’ll create a new virtual host configuration file at /etc/nginx/sites-available:

现在,应用程序文件已经整理好了,但是我们仍然需要配置Nginx来提供内容。 为此,我们将在/etc/nginx/sites-available创建一个新的虚拟主机配置文件:

  • sudo nano /etc/nginx/sites-available/travel_list

    须藤纳米/ etc / nginx / sites-available / travel_list

The following configuration file contains the recommended settings for Laravel applications on Nginx:

以下配置文件包含Nginx上Laravel应用程序的建议设置:

/etc/nginx/sites-available/travel_list
/ etc / nginx / sites-available / travel_list
server {
    listen 80;
    server_name server_domain_or_IP;
    root /var/www/travel_list/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Copy this content to your /etc/nginx/sites-available/travel_list file and, if necessary, adjust the highlighted values to align with your own configuration. Save and close the file when you’re done editing.

将此内容复制到您的/etc/nginx/sites-available/ travel_list文件中,并在必要时调整突出显示的值以符合您自己的配置。 完成编辑后,保存并关闭文件。

To activate the new virtual host configuration file, create a symbolic link to travel_list in sites-enabled:

要激活新的虚拟主机配置文件, travel_listsites-enabled创建指向travel_list的符号链接:

  • sudo ln -s /etc/nginx/sites-available/travel_list /etc/nginx/sites-enabled/

    sudo ln -s / etc / nginx / sites-available / travel_list / etc / nginx / sites-enabled /

Note: If you have another virtual host file that was previously configured for the same server_name used in the travel_list virtual host, you might need to deactivate the old configuration by removing the corresponding symbolic link inside /etc/nginx/sites-enabled/.

注意 :如果您先前已为travel_list虚拟主机中使用的同一server_name配置了另一个虚拟主机文件,则可能需要通过删除/etc/nginx/sites-enabled/的相应符号链接来停用旧配置。

To confirm that the configuration doesn’t contain any syntax errors, you can use:

要确认配置不包含任何语法错误,可以使用:

  • sudo nginx -t

    须藤Nginx -t

You should see output like this:

您应该看到如下输出:

Output
输出量
  • nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

    nginx:配置文件/etc/nginx/nginx.conf语法正常
  • nginx: configuration file /etc/nginx/nginx.conf test is successful

    nginx:配置文件/etc/nginx/nginx.conf测试成功

To apply the changes, reload Nginx with:

要应用更改,请使用以下命令重新加载Nginx:

  • sudo systemctl reload nginx

    须藤systemctl重新加载nginx

Now go to your browser and access the application using the server’s domain name or IP address, as defined by the server_name directive in your configuration file:

现在转到浏览器,使用服务器的域名或IP地址访问应用程序,该域名或IP地址由配置文件中的server_name指令定义:

http://server_domain_or_IP

You will see a page like this:

您将看到如下页面:

That confirms your Nginx server is properly configured to serve Laravel. From this point, you can start building up your application on top of the skeleton provided by the default installation.

这确认您的Nginx服务器已正确配置为服务Laravel。 至此,您可以在默认安装提供的框架之上开始构建应用程序。

In the next step, we’ll modify the application’s main route to query for data in the database using Laravel’s DB facade.

在下一步中,我们将修改应用程序的主要路线,以使用Laravel的DB外观查询数据库中的DB

第6步-自定义主页 (Step 6 — Customizing the Main Page)

Assuming you’ve followed all the steps in this guide so far, you should have a working Laravel application and a database table named places containing some sample data.

假设到目前为止,您已经按照本指南中的所有步骤进行操作,那么您应该有一个可运行的Laravel应用程序和一个名为places的数据库表,其中包含一些示例数据。

We’ll now edit the main application route to query for the database and return the contents to the application’s view.

现在,我们将编辑主要的应用程序路由以查询数据库,并将内容返回到应用程序的view

Open the main route file, routes/web.php:

打开主路由文件, routes/web.php

  • nano routes/web.php

    纳米路线/ web.php

This file comes by default with the following content:

该文件默认带有以下内容:

routes/web.php
路线/web.php
<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Routes are defined within this file using the static method Route::get, which receives a path and a callback function as arguments.

路由是使用静态方法Route::get在此文件中定义的,该方法接收路径回调函数作为参数。

The following code replaces the main route callback function. It makes 2 queries to the database using the visited flag to filter results. It returns the results to a view named travel_list, which we’re going to create next. Copy this content to your routes/web.php file, replacing the code that is already there:

以下代码替换了主路由回调函数。 它使用visited标志对数据库进行2次查询以过滤结果。 它将结果返回到一个名为travel_list的视图中,我们接下来将创建该视图。 将此内容复制到您的routes/web.php文件中,替换已存在的代码:

routes/web.php
路线/web.php
<?php

use Illuminate\Support\Facades\DB;

Route::get('/', function () {
  $visited = DB::select('select * from places where visited = ?', [1]); 
  $togo = DB::select('select * from places where visited = ?', [0]);

  return view('travel_list', ['visited' => $visited, 'togo' => $togo ] );
});

Save and close the file when you’re done editing. We’ll now create the view that will render the database results to the user. Create a new view file inside resources/views:

完成编辑后,保存并关闭文件。 现在,我们将创建将数据库结果呈现给用户的视图。 在resources/views内创建一个新的视图文件:

  • nano resources/views/travel_list.blade.php

    纳米资源/视图/travel_list.blade.php

The following template creates two lists of places based on the variables visited and togo. Copy this content to your new view file:

以下模板根据visited的变量和togo创建两个场所列表。 将此内容复制到新的视图文件中:

resources/views/travel_list/blade.php
资源/视图/travel_list/blade.php
<html>
<head>
    <title>Travel List</title>
</head>

<body>
    <h1>My Travel Bucket List</h1>
    <h2>Places I'd Like to Visit</h2>
    <ul>
      @foreach ($togo as $newplace)
        <li>{{ $newplace->name }}</li>
      @endforeach
    </ul>

    <h2>Places I've Already Been To</h2>
    <ul>
          @foreach ($visited as $place)
                <li>{{ $place->name }}</li>
          @endforeach
    </ul>
</body>
</html>

Save and close the file when you’re done. Now go to your browser and reload the application. You’ll see a page like this:

完成后,保存并关闭文件。 现在转到浏览器并重新加载应用程序。 您会看到这样的页面:

You have now a functional Laravel application pulling contents from a MySQL database.

您现在有了一个功能正常的Laravel应用程序,它从MySQL数据库中提取内容。

结论 (Conclusion)

In this tutorial, you’ve set up a new Laravel application on top of a LEMP stack (Linux, Nginx, MySQL and PHP), running on an Ubuntu 18.04 server. You’ve also customized your default route to query for database content and exhibit the results in a custom view.

在本教程中,您已经在LEMP堆栈(Linux,Nginx,MySQL和PHP)之上建立了一个新的Laravel应用程序,该应用程序在Ubuntu 18.04服务器上运行。 您还自定义了默认路由,以查询数据库内容并将结果显示在自定义视图中。

From here, you can create new routes and views for any additional pages your application needs. Check the official Laravel documentation for more information on routes, views, and database support. If you’re deploying to production, you should also check the optimization section for a few different ways in which you can improve your application’s performance.

在这里,您可以为应用程序需要的任何其他页面创建新的路线和视图。 请查阅Laravel官方文档以获取有关路线视图数据库支持的更多信息。 如果要部署到生产环境,则还应该检查“ 优化”部分 ,以了解几种可以提高应用程序性能的不同方法。

For improved security, you should consider installing an TLS/SSL certificate for your server, allowing it to serve content over HTTPS. To this end, you can follow our guide on how to secure your Nginx installation with Let’s Encrypt on Ubuntu 18.04.

为了提高安全性,您应该考虑为服务器安装TLS / SSL证书,使其可以通过HTTPS提供内容。 为此,您可以遵循我们的指南, 了解如何在Ubuntu 18.04上使用Let's Encrypt保护Nginx安装的安全

翻译自: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-laravel-with-lemp-on-ubuntu-18-04

lemp wp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值