Home >PHP Framework >ThinkPHP >How to run thinkphp under linux

How to run thinkphp under linux

PHPz
PHPzOriginal
2023-04-17 09:52:061798browse

How to run the ThinkPHP project under the Linux platform?

ThinkPHP is a very excellent PHP development framework. It greatly improves PHP development efficiency and code quality, and is favored by the majority of developers. How to run the ThinkPHP project on the Linux platform? Below, I will give you a detailed introduction.

  1. Install the PHP environment

Installing the PHP environment under Linux is very simple, just execute the following command:

Ubuntu:

sudo apt-get install php

CentOS:

yum install php

  1. Install Apache or Nginx

under Linux Commonly used web servers include Apache and Nginx. The following describes how to install them.

2.1 Apache installation

Ubuntu:

sudo apt-get install apache2

CentOS:

yum install httpd

2.2 Nginx installation

For users who use Nginx, you can choose to install Nginx and use the php-fpm module to execute PHP code. This method is more efficient than Apache.

Ubuntu:

sudo apt-get install nginx php-fpm

CentOS:

yum install nginx php-fpm

  1. Install Composer

ThinkPHP 5 uses Composer as the package management tool. If Composer has been installed, you can skip this step.

Ubuntu:

sudo apt-get install composer

CentOS:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

  1. Install ThinkPHP

In Linux, there are many ways to install ThinkPHP. Two are introduced below: Composer installation and manual installation.

4.1 Composer installation

Execute the following command in the command line:

composer create-project topthink/think tp5 --prefer-dist

Among them, tp5 is the project name, --prefer-dist means to install using compressed package.

After the installation is completed, you can start the PHP built-in web server in the project root directory through the command line and execute the following command:

php think run

4.2 Manual installation

Manual installation requires first downloading and decompressing ThinkPHP to the specified directory, and then configuring the rewrite rules (you can use .htaccess or nginx.conf). After the configuration is completed, it can be run.

  1. Configuring the database

Under Linux, ThinkPHP uses the MySQL database by default. Database connection information needs to be set in the configuration file.

In the project root directory, open the application/database.php file and fill in the correct database connection information.

  1. Run the project

After the configuration is completed, you can access the project through a web browser.

Rule: http(s)://your domain name or IP/project name/module name/controller name/method name

For example:

http:/ /localhost/tp5/index/index/hello

  1. Summary

Under the Linux platform, it is not difficult to install and run the ThinkPHP project. Please pay attention to the following points:

  • Install PHP environment;
  • Install Apache or Nginx;
  • Install Composer;
  • Install ThinkPHP;
  • Configure database;
  • Run the project.

I hope that the introduction in this article can help you better run ThinkPHP projects under Linux systems.

The above is the detailed content of How to run thinkphp under linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn