Home >Backend Development >PHP Problem >How to install tp5 using php command
PHP is a widely used programming language that can be used for web development, scripting, command line scripting, and more. ThinkPHP is an open source web application framework based on PHP, which allows developers to build web applications more conveniently and quickly. This article will introduce how to install ThinkPHP5 through the command line.
First you need to ensure that the PHP environment has been installed locally. If it is not installed, you can install it through the following command:
$ sudo apt-get install php
Ubuntu is used here For example, other systems may differ.
Composer is a commonly used dependency management tool in PHP, which allows users to more conveniently manage dependent libraries in PHP projects.
Composer can be installed through the following command:
$ curl -sS https://getcomposer.org/installer | php $ sudo mv composer.phar /usr/local/bin/composer
The curl tool is used here to download the Composer installation script, rename it and move it to the /usr/local/bin directory. For more information about Composer, see the official documentation: https://getcomposer.org/
Via Composer To download and install ThinkPHP5, enter the following command in the command line:
$ composer create-project topthink/think tp5 --prefer-dist
topthink/think here is the package provided by the ThinkPHP5 development team, and tp5 is the project name. Note that you may need to enter some configuration information during the installation process.
After the command is executed, a folder named tp5 will be created in the current directory, which is the root directory of the ThinkPHP5 application.
In order to preview the running effect in a local browser, a web server needs to be built locally so that users can enter http:/ /localhost/tp5 to access the running application.
You can configure the virtual host through the following two methods:
Method 1: Using Apache
If you have installed Apache2, you can open the virtual host through the following command Configuration:
$ sudo a2enmod rewrite $ sudo nano /etc/apache2/sites-available/000-default.conf
In the open file, find the following code block:
DocumentRoot /var/www/html
Change it to:
DocumentRoot /path/to/tp5/public
path/to/tp5 is your tp5 project the absolute path. Then add the following code at the end of the file:
<Directory /path/to/tp5/public> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
Save and close the file, and restart the Apache2 service:
$ sudo service apache2 restart
Method 2: Use PHP built-in web server
If you If you don't want to use Apache2, you can use PHP's built-in web server to start the virtual host. Enter the following command on the command line:
$ php -S localhost:8000 -t /path/to/tp5/public
The localhost:8000 here represents the address and port of the service listening, and /path/to/tp5/public is the absolute path of your tp5 project. Enter http://localhost:8000 in the browser to access your tp5 application.
Now, you can access http://localhost/tp5 (or http://localhost :8000, depending on your virtual host configuration), you will see a welcome interface, indicating that tp5 has been successfully installed and run.
Next, you can try to create a controller in the Controller under the tp5 application directory app, and then visit http://localhost/tp5/Controller name/operation name, You can see the results output by your controller in the application.
Summary:
This article introduces how to install ThinkPHP5 through the command line, configure a virtual host to start the application, and briefly demonstrates how to create a controller in the application. I hope this article will be helpful to your TP5 application development.
The above is the detailed content of How to install tp5 using php command. For more information, please follow other related articles on the PHP Chinese website!