Question

Migrate existing php App to Digital Ocean

I have a PHP web app running on production. Now I thought it is better to migrate on Digital Ocean. My code repository is on Gitlab. I know first I have to create a LAMP droplet. But what after that?

Can you please explain me what steps should I have to ensure a smooth transition?

Including my domain pointing and adding different environments like (testing, staging, production ) on single droplet.

Thanks


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
July 24, 2023

Hi there,

You can start by setting up a LAMP Droplet as described below, or use the following 1-Click installation from the Marketplace:

https://marketplace.digitalocean.com/apps/lamp

  1. Create a new Droplet on DigitalOcean: After logging into DigitalOcean, click on the “Create Droplet” button. Choose an Ubuntu base, and select your desired size. Once the Droplet is created, you’ll have access to its IP address.

  2. Set up the LAMP stack:

    • Connect to your droplet: ssh root@your_droplet_ip
    • Update your package lists: sudo apt-get update
    • Install Apache: sudo apt-get install apache2
    • Install MySQL: sudo apt-get install mysql-server. During the installation process, you will be asked to secure your MySQL installation.
    • Install PHP: sudo apt-get install php libapache2-mod-php php-mysql

    For an indepth instructions on how to do this, follow this tutorial:

    https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-22-04

  3. Set up Git:

    • Install Git: sudo apt-get install git
    • Configure Git with your details: git config --global user.name "Your Name" and git config --global user.email "youremail@yourdomain.com"
  4. Clone your app:

    • Move to the webroot directory: cd /var/www/html
    • Clone your app: git clone your_gitlab_repo_url
  5. Set up your .env file:

    • Move to your application’s directory: cd your_app_directory
    • Copy the .env.example to .env: cp .env.example .env
    • Edit .env with nano or vim: nano .env (update the settings to reflect your production environment)
  6. Install Composer dependencies:

    • Install Composer: Follow the official instructions to download and install Composer.
    • Install dependencies: composer install --no-dev --optimize-autoloader
  7. Set up Apache:

    • Create a new VirtualHost configuration: sudo nano /etc/apache2/sites-available/your_app.conf
    • In the new file, enter a configuration like the following, then save and close the file:
    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/your_app_directory/public
        ServerName your_domain
        ServerAlias www.your_domain
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    
    • Enable the new VirtualHost: sudo a2ensite your_app.conf
    • Reload Apache to apply the changes: sudo service apache2 reload
  8. Database migration:

    • Login to MySQL: mysql -u root -p
    • Create a new database: CREATE DATABASE your_database;
    • Import your data. First, exit MySQL with exit. Then, use the command: mysql -u username -p new_database < data-dump.sql
  9. Test your application: Visit http://your_droplet_ip in your web browser.

  10. Set up DNS: This will be done through your domain provider’s interface. Add an A record that points your domain to the droplet’s IP address.

  11. SSL Certificate:

- Install Certbot: `sudo apt-get install certbot python3-certbot-apache`
- Get and install a certificate: `sudo certbot --apache`

Remember that these steps are an outline. Always ensure that you’re following the best practices for your application and server environment.

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.