如何在Ubuntu 18.04 LTS上安装Laravel Framework

本文详细介绍了如何在Ubuntu 18.04 LTS服务器上安装Laravel框架,包括安装Apache Web服务器、PHP 7.2、Composer,以及配置Apache和测试Laravel网站的步骤。
摘要由CSDN通过智能技术生成

In this guide, we look at how to install Laravel framework on Ubuntu 18.04 server. Laravel is a free and open source PHP web framework. It was created in 2011 by Taylor Otwell and has since been used for development of robust mobile applications using the MVC model.

在本指南中,我们研究如何在Ubuntu 18.04服务器上安装Laravel框架。 Laravel是一个免费的开源PHP Web框架。 它由Taylor Otwell于2011年创建,此后已用于使用MVC模型开发强大的移动应用程序。

Let’s dive in and see how we can install Laravel framework on Ubuntu 18.04 LTS Server.

让我们深入研究一下如何在Ubuntu 18.04 LTS Server上安装Laravel框架。

Before we install Laravel framework, let’s first install the prerequisite packages that will be required.

在安装Laravel框架之前,让我们首先安装将需要的必备软件包。

系统先决条件 (System prerequisites)

Your system will need to satisfy the requirements below before proceeding.

您的系统将需要满足以下要求,然后才能继续。

  • Apache Web server

    Apache Web服务器
  • PHP >= 7.1.3 with OpenSSL, PDO, Mbstring, Tokenizer, XML, Ctype and JSON PHP Extensions.

    PHP> = 7.1.3,带有OpenSSL,PDO,Mbstring,Tokenizer,XML,Ctype和JSON PHP扩展。
  • Composer – an application-level package manager for the PHP

    Composer – PHP的应用程序级程序包管理器

1.安装Apache Web服务器和PHP 7.2 (1. Install Apache Web server and PHP 7.2)

We are going to add a third party PHP repository. Even though Ubuntu’s own repository has its own PHP, a third party repository is very much recommended because it gets more frequently updated.

我们将添加第三方PHP存储库。 即使Ubuntu自己的存储库具有自己PHP,也还是强烈建议您使用第三方存储库,因为它会更频繁地更新。

To add the repository execute the command:

要添加存储库,请执行以下命令:

$ sudo add-apt-repository ppa:ondrej/php

Sample Output

样本输出

Next, update your system’s repositories.

接下来,更新系统的存储库。

$ sudo apt update

Sample Output

样本输出

Next, install Apache and PHP 7.2 alongside other prerequisites.

接下来,与其他先决条件一起安装Apache和PHP 7.2。

$ sudo apt-get install apache2 libapache2-mod-php7.2 php7.2 php7.2-xml php7.2-gd php7.2-opcache php7.2-mbstring

Sample Output

样本输出

2.安装Composer (2. Install Composer)

Before we embark on the installation, we will first install a few useful tools. These are git version control, curl and unzip packages.

在开始安装之前,我们将首先安装一些有用的工具。 这些是git版本控制,curl和解压缩软件包。

$ sudo apt install curl git unzip

Sample Output

样本输出

Next, we need to install composer. The composer is another useful tool that handles dependency management in PHP and allows you to package the required libraries associated with a package as one. Composer will download and install all the packages required to run the Laravel framework.

接下来,我们需要安装作曲家。 编写器是另一个有用的工具,可处理PHP中的依赖关系管理,并允许您将与程序包关联的所需库打包为一个程序。 Composer将下载并安装运行Laravel框架所需的所有软件包。

To install Composer, execute the following commands

要安装Composer,请执行以下命令

$ cd /opt
$ curl -sS https://getcomposer.org/installer | php

Sample Output

样本输出

The curl command downloads Composer to the /opt directory. Since we need composer running globally, we must move it to the /usr/local/bin directory under 'composer' name.

curl命令将Composer下载到/opt目录。 由于我们需要在全球范围内运行的作曲家,因此必须将其移动到'composer'名称下的/usr/local/bin目录中。

$ mv composer.phar /usr/local/bin/composer

This will allow us to run composer from anywhere.

这将使我们能够在任何地方运行作曲家。

3.安装Laravel框架 (3. Install Laravel Framework)

Now, let’s navigate to the public_html directory of our Ubuntu System. To install Laravel, we will navigate to the /var/www/html directory.

现在,让我们导航到Ubuntu系统的public_html目录。 要安装Laravel,我们将导航到/var/www/html目录。

cd /var/www/html

Next, we will create a directory “your-project” with Laravel installation. The composer will proceed to use Git to download and install all packages and modules that Laravel requires for functioning.

接下来,我们将使用Laravel安装创建一个目录“您的项目”。 作曲家将继续使用Git下载并安装Laravel运行所需的所有软件包和模块。

$ sudo composer create-project laravel/laravel your-project --prefer-dist

Sample Output

样本输出

4.为Laravel配置Apache Web服务器 (4. Configure Apache Web Server for Laravel)

The next step is to configure our Apache Web server. We need to assign the necessary permissions to the project directory which will allow access to it from the www-data group and give it write permissions to the storage directory. To get this done, run the following commands.

下一步是配置我们的Apache Web服务器。 我们需要为项目目录分配必要的权限,这将允许从www-data组对其进行访问,并为其授予对存储目录的写入权限。 为此,请运行以下命令。

# sudo chgrp -R www-data /var/www/html/your-project
# sudo chmod -R 775 /var/www/html/your-project/storage

Now let’s navigate to /etc/apache2/sites-available directory and run the command below to create a configuration file for our Laravel install.

现在,让我们导航到/etc/apache2/sites-available目录,并运行以下命令为我们的Laravel安装创建一个配置文件。

$ vim /etc/apache2/sites-available/laravel.conf

Add the following content:

添加以下内容:

ServerName localhost

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/your-project/public

AllowOverride All

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Save the file and Exit.

保存文件并退出。

Finally, we are going to enable the newly created laravel.conf file. But before that, let’s disable the default config file.

最后,我们将启用新创建的laravel.conf文件。 但是在此之前,让我们禁用默认配置文件。

$ sudo a2dissite 000-default.conf

Sample Output

样本输出

Next, enable the Laravel config file.

接下来,启用Laravel配置文件。

$ sudo a2ensite laravel.conf

Sample Output

样本输出

Then enable rewrite mode:

然后启用重写模式:

$ sudo a2enmod rewrite

Sample Output

样本输出

Lastly, restart the Apache service.

最后,重新启动Apache服务。

$ sudo systemctl restart apache2

To verify that Apache is running execute the command:

要验证Apache是​​否正在运行,请执行以下命令:

systemctl status apache2

Sample Output

样本输出

5.测试Laravel网站 (5. Test Laravel Website)

At this point, You have successfully installed Laravel on your Ubuntu 18.04 LTS System. To confirm that the installation went as expected visit your server’s IP address.

至此,您已经在Ubuntu 18.04 LTS系统上成功安装了Laravel。 要确认安装是否按预期进行,请访问服务器的IP地址。

https://server-IP-address

In my case, the server’s IP is https://38.76.11.149

就我而言,服务器的IP为https://38.76.11.149

We hope that this guide has been helpful. Feel free to leave your feedback at the comment section.

我们希望本指南对您有所帮助。 随时将您的反馈留在评论部分。

翻译自: https://www.journaldev.com/26623/install-laravel-on-ubuntu

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值