Home >PHP Framework >ThinkPHP >How to deploy FTP service using ThinkPHP

How to deploy FTP service using ThinkPHP

PHPz
PHPzOriginal
2023-04-11 10:40:20842browse

With the development of the Internet, various websites, applications and services have gradually entered people's lives and work. The development of these websites and applications is inseparable from an excellent development framework. Currently, one of the most popular and widely used PHP development frameworks in China is ThinkPHP. However, for developers, how to deploy their websites or applications to the server and ensure normal operation is an unavoidable problem. This article will introduce how to use ThinkPHP to deploy FTP service.

Step 1: Install the FTP service

Before deploying FTP, we first need to install the FTP service on the server. If the FTP service has not been installed on your server, you can use the following command to complete it:

sudo apt-get install vsftpd

Next, we need to edit the FTP configuration file and find the vsftpd.conf file. The command is as follows:

sudo nano /etc/vsftpd.conf

Find the following content in the file:

#anonymous_enable=YES

and modify it to:

anonymous_enable=NO

Because we need to log in to the FTP service through a username and password, anonymous access needs to be disabled.

We also need to add the following lines at the end of the file:

#添加用户时目录自动创建
user_sub_token=$USER
local_root=/var/www/$USER

#防火墙开启20、21端口
pasv_enable=YES
pasv_min_port=60000
pasv_max_port=61000

These configurations will automatically create the user directory, enable PASV mode and set the port range of PASV mode to 60000-61000.

After editing is complete, save and close the file.

Step 2: Create an FTP user

Next, we need to create an FTP user on the server. You can use the following command:

sudo adduser ftpuser

After the command is executed, We are prompted to enter some information, including a password and whether additional information needs to be added. Just follow the prompts step by step.

Step 3: Set the FTP user directory

In the above FTP configuration file, we set the user directory to /var/www/$USER, so we need to manually create the directory and Set the appropriate permissions. Use the following command to complete:

sudo mkdir /var/www/ftpuser
sudo chown ftpuser:ftpuser /var/www/ftpuser
sudo chmod 755 /var/www/ftpuser

Step 4: Upload the project file to the FTP server

Package the uploaded project file into ZIP format and use FTP client software to connect to the server , upload the ZIP file to the directory (such as /var/www/ftpuser in the example above).

Step 5: Unzip the ZIP file

The command line to unzip the file is as follows:

sudo apt-get install unzip
sudo unzip -o yourfilename.zip -d yourfilename/

Step 6: Configure the virtual host

The last step By configuring the virtual host, Apache or Nginx can recognize our project code and deploy the website to the server. Add the following content to the Apache or Nginx configuration file:

<VirtualHost *:80>
    ServerAdmin webmaster@yourdomain.com
    DocumentRoot /var/www/yourfilename/public
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory /var/www/yourfilename/public>
        AllowOverride All
    </Directory>
</VirtualHost>

Among them, the path after DocumentRoot is the path of your project code, ServerName and ServerAlias ​​are your domain name and alias respectively, which can be modified according to the actual situation.

At this point, the deployment of ThinkPHP's FTP service is completed. We can connect to the server through the FTP client software, use the username and password we just created, and access the FTP site for file upload and download.

The above is the detailed content of How to deploy FTP service using ThinkPHP. 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