


PHP framework laravel installation and configuration instructions
This article mainly introduces the installation and configuration instructions of the PHP framework laravel. Interested friends can refer to it. I hope it will be helpful to everyone.
Laravel is a simple and elegant PHP web development framework. This article will introduce in detail how to configure Laravel
Configuration instructions
Download the framework , but if we want to use it well, we may still need to know something, which is configuration. The configuration related to the project is in the app/config folder, but there are some configurations besides here that we may need. As a basic tutorial, I will not introduce them one by one. I will just choose some places where everyone has more configurations to explain.
Configuration instructions in app/config
There are generally two files that are often configured in the app/config folder: app.php and database.php Files, one of them is for configuring miscellaneous projects and the other is for configuring the database. Let me explain the common configurations inside:
First is the app.php file
// app/config/app.php 文件 return array( /* |-------------------------------------------------------------------------- | Laravel 的 debug 模块 |-------------------------------------------------------------------------- | 当设置为 'true' 的时候为开启状态(下面这种设置是默认设置,为开启状态) | 'false' 为关闭状态。开启的时候当程序出现错误会显示错误信息, | 而关闭的时候,程序一旦错误,则会跳转到错误页面(一般为404页) */ 'debug' => true, /* |-------------------------------------------------------------------------- | 应用地址 |-------------------------------------------------------------------------- | 这个地址只有在使用 Artisan 命令的时候才会用到,需要设置为应用的根目录。 | 额,如果你还是不清楚我在说什么,那就和下面一样设置成空吧。 */ 'url' => '', /* |-------------------------------------------------------------------------- | 应用的时区 |-------------------------------------------------------------------------- | 这个就是时区操作了,一般如果你没有对 PHP 进行设置的话,时区是美国时区, | 也就是 'UTC' ,啊,你是要写面向我天朝网站么?那就设置成 'Asia/Shanghai' 吧。 */ 'timezone' => 'Asia/Shanghai', /* |-------------------------------------------------------------------------- | 应用的本地化 |-------------------------------------------------------------------------- | 简单的说就是多语言设置,默认是 'en' 如果你没有自己写语言包的话那就还是这个值吧。 | 你可以在 app/lang 文件夹中看到语言包,如果你没有多语言想法的话,那就不用管这个了。 */ 'locale' => 'en', /* |-------------------------------------------------------------------------- | 应用密钥 |-------------------------------------------------------------------------- | 这是在应用 Laravel 自带的加密功能时会用到的密钥,是为了保证加密安全性的。 | 如果你的文件这里不是一个随机的 32 位字符串的话,你可以用 'php artisan key:generate' | 命令生成一个 32 位随机字符串,啊,记住要在你写网页之前做这个事情。 | 一旦你变更这个字符串,那么用上一个字符串加密过的内容就找不回来了!! */ 'key' => '', );
In fact, there is some content behind app.php, but those basically don’t need you to modify. (It is only needed when adding third-party packages, we will talk about it then)
Next, introduce the database.php file
// app/config/database.php 文件 return array( /* |-------------------------------------------------------------------------- | PDO 类型 |-------------------------------------------------------------------------- | 默认情况下 Laravel 的数据库是用 PDO 来操作的,这样能极大化的提高数据库兼容性。 | 那么默认查询返回的类型是一个对象,也就是如下的默认设置。 | 如果你需要返回的是一个数组,你可以设置成 'PDO::FETCH_ASSOC' */ 'fetch' => PDO::FETCH_CLASS, /* |-------------------------------------------------------------------------- | 默认的数据库连接名 |-------------------------------------------------------------------------- | 这里所说的名字是和下面的 'connections' 中的名称对应的,而不是指你用的什么数据库 | 为了你更好的理解,我在这里换了一个名字 */ 'default' => 'meinv', /* |-------------------------------------------------------------------------- | 数据库连接名 |-------------------------------------------------------------------------- | 这里就是设置各种数据库的配置的,每个数组里的 'driver' 表明了你要用的数据库类型 | 同一种数据库类型可以设置多种配置,名字区分开就行,就像下面的 'mysql' 和 'meinv' | 其他的么,我觉得不需要解释了吧,就是字面意思,我相信你英文的能力(其实是我英文不好) */ 'connections' => array( 'sqlite' => array( 'driver' => 'sqlite', 'database' => __DIR__.'/../database/production.sqlite', 'prefix' => '', ), 'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ), 'meinv' => array( //这里就是上面例子里的默认连接数据库名,实际上是 mysql 数据库 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ), 'pgsql' => array( 'driver' => 'pgsql', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'prefix' => '', 'schema' => 'public', ), 'sqlsrv' => array( 'driver' => 'sqlsrv', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => '', 'prefix' => '', ), ), );
Well~, you know, I definitely don’t Enough said, for you who are just starting out, it is enough to know the database settings.
Configuring the development environment
Sometimes we need to specify that the development environment is "local" (the local environment generally refers to the virtual server on our own computer and is not published to Online) or "production" (the production environment generally refers to the online environment, that is, on a formal server), or there are other environments (some development companies will also divide into test environments, etc.) to facilitate a configuration For example, in the "local" environment, you can turn on debug, etc., but in the "production" environment, you cannot turn on debug, otherwise people will know some information about our server, which is secret and will cause insecurity. Then let’s introduce the environment configuration in Laravel.
The environment is configured in bootstrap/start.php. We open this file and find the following code inside.
The code is as follows:
$env = $app->detectEnvironment(array( 'local' => array('your-machine-name'), ));
'your-machine here -name' refers to the hostname of your computer (what is hostname? Well, I checked it for a long time, it is your server name). Someone asked: How do I know the hostname of my computer?
ipconfig /all
Open cmd in Windows and enter
The "host name" below is hostname,
Open the terminal in Ubuntu Enter
hostname
and the displayed hostname
For example, the hostname of my computer is admin, then this is the code
As follows:
$env = $app->detectEnvironment(array( 'local' => array('admin'), ));
System environment requirements
apache, nginx or other web servers;
laravel uses some powerful features of PHP, so it needs to be It can only be executed on PHP5.3 or higher;
Laravel uses the FileInfo library (http://php.net/manual/en/book.fileinfo.php) to detect the mime type of the file. This library is available in PHP5 .3 is included by default, but in Windows users need to enable this module in php.ini themselves. If you don’t understand, you can take a look here: http://php.net/manual/en/fileinfo.installation.php;
Laravel uses the Mcrypt library (http://php.net/manual/en/book.mcrypt.php) to encrypt and generate hash. Before using this framework, you need to ensure that this extension is installed. You can use phpinfo (); Check whether it is installed correctly in the web server. If not, you can check: http://php.net/manual/en/book.mcrypt.php;
Install laravel
Download laravel: http://laravel.com/download;
Unzip the compressed package file and upload it to the web server;
Set the value of key in config/application.php, you can set a 32-character string Random content;
Verify whether storage/views is writable;
Access your application in the browser;
At this point you have completed a Laravel installation, there is more here need to know.
Extra Content
Install some of the following additional extensions so you can take full advantage of Laravel
SQLite, MySQL, PostgreSQL, or SQL Server PDO drivers.
Memcached or APC.
question?
If you have installation problems, try the following:
Make sure the public directory is the root directory of your site (see server configuration below)
If you are using mod_rewrite, set application/config/application The index item in .php is empty.
Verify that your storage folder is writable.
Server configuration
Here we guarantee the most basic apache configuration. Our Laravel root directory is:/Users/JonSnow/Sites/MySite
The configuration information is as follows:
The code is as follows:
<VirtualHost *:80> DocumentRoot /Users/JonSnow/Sites/MySite/public ServerName mysite.dev </VirtualHost>
Note: We installed it to /Users/JonSnow/Sites/MySite, and our DocumentRoot goes to /Users/JonSnow/Sites/MySite/public.
Getting started with Laravel It is a Windows environment, but you are not required to use Windows. You can do it under your favorite system.
The installation of the PHP running environment is beyond the scope of this tutorial. Here we only explain the basic requirements.
Web server:
PHP 5.3 and above
PDO module
Mcrypt module
MYSQL database
The environment used in this tutorial:
PHP 5.4.5
MYSQL 5.0. 45
Install the Laravel framework:
Download the Laravel framework: Laravel official download | Github download
Extract the framework to the server directory
The Laravel framework is installed in a simple two-step process. In order to test whether the installation is successful, Visit in the browser:
http://localhost/public/
The public directory is the folder that comes with the framework. If you see the initial interface of laravel, it means it has been installed. success.
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
How to operate the database in php to determine whether a table exists
##Three common tree traversal techniques in php
php uses curl to connect to the website and obtain information
The above is the detailed content of PHP framework laravel installation and configuration instructions. For more information, please follow other related articles on the PHP Chinese website!

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP is not dead. 1) The PHP community actively solves performance and security issues, and PHP7.x improves performance. 2) PHP is suitable for modern web development and is widely used in large websites. 3) PHP is easy to learn and the server performs well, but the type system is not as strict as static languages. 4) PHP is still important in the fields of content management and e-commerce, and the ecosystem continues to evolve. 5) Optimize performance through OPcache and APC, and use OOP and design patterns to improve code quality.

PHP and Python have their own advantages and disadvantages, and the choice depends on the project requirements. 1) PHP is suitable for web development, easy to learn, rich community resources, but the syntax is not modern enough, and performance and security need to be paid attention to. 2) Python is suitable for data science and machine learning, with concise syntax and easy to learn, but there are bottlenecks in execution speed and memory management.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.