PHP remains popular if you are developing a dynamic website or a complex web application due to its flexibility, robustness, and extensive support. But after developing your application, the next crucial step is to deploy it in a live environment. This post will guide you through deploying your PHP application to your virtual machine (VM) using SFTP.
Local Setup
Start by ensuring an SFTP client is installed on your local machine. Several options are available, with FileZilla and WinSCP being the most popular. For this guide, we will be using FileZilla (Client).
Connect to the VM Using SFTP
Once FileZilla is ready to go, launch it, and follow these steps:
Navigate to File > Site Manager.
Click on New Site and fill in the following details:
Host: Enter your VM's IP address.
Port: Typically, this is 22 for SFTP.
Protocol: Choose SFTP - SSH File Transfer Protocol.
Logon Type: Select Normal (if you use a username/password for authentication) or Key file (if you use a private key for authentication).
User: Input the username for your VM.
Password or Key file: Fill in your password or browse your private key file.
Click Connect.
Upload Your Code
With a connection established, you are now ready to upload your PHP application. In the left pane (Local site), navigate to your local GitHub repository folder containing the PHP application. In the right pane (Remote site), navigate to the directory where you wish to deploy your PHP application.
To upload the files, you can drag and drop them from the left pane to the right pane. Alternatively, you can right-click on your local files and select "Upload."
Configure cPanel for Your PHP Application
Now that your files are on your VM, you'll need to configure cPanel.
Login to your cPanel account, typically by accessing your VM's IP address followed by /cpanel in a web browser (e.g. your-vm-ip-address/cpanel).
Depending on your PHP application's configuration requirements, you may need to:
- Set up a new MySQL database and user for your application using the MySQL Databases section.
- Configure PHP settings in the MultiPHP INI Editor.
- Set up a domain or subdomain to point to your application directory via the Domains section.
Note: These steps can vary depending on your VM's configuration, security settings, and your PHP application's specific requirements.
A Note on Alternate Solution
Deploying directly from your local machine to production may seem straightforward, but it carries inherent risks. Having a dedicated development or staging environment to test changes before deployment is strongly recommended. In this scenario, implementing a Continuous Integration/Continuous Deployment (CI/CD) pipeline makes deployments more efficient, reliable, and automated.
The DevSecOps approach, which encompasses CI/CD, enhances your deployment process. By embedding security checks and balances into the development and deployment cycle, DevSecOps can help to identify and resolve security vulnerabilities early, thus making your PHP application more robust and secure.
On the other hand, you can go for a better solution that accommodates DevSecOps within it but does not expose the complexities of implementing it. This is Batoi’s Rapid Application Development (RAD) Platform that can significantly simplify these operations. RAD offers a user-friendly shortcut for developers, reducing the need for complex setups and configurations. It allows for a more agile approach to software development and deployment, with less time spent on tedious technical configurations and more time focused on innovating and improving the application.