Report this

What is the reason for this report?

how to upload php application to ubuntu LAMP droplet and connect app with mysql?

Posted on August 10, 2017

I created a preset droplet call ubuntu LAMP.

I can access to this droplet via ssh. And that’s all. I don’t know what to do with the following steps

Where in the droplet should I upload my PHP app to?

How can I config droplet’s mysql so that my app can connect to mysql?

How can I upload my data to droplet’s mysql ?



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!

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.

In order to get your php app to work you are going to need to follow a number of steps all on your server’s command line.

  1. Upload your application and set ownerships on your files.

  2. Configure Apache to serve your application. See steps 1,2,4,5 from this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04

  3. Create a database.

  4. Import in your existing db into the new database. See the importing section of this tutorial: https://www.digitalocean.com/community/tutorials/how-to-import-and-export-databases-in-mysql-or-mariadb

After you have created a new database and imported your data you should create a new mysql user and give them access to the db. You need to log into the mysql server and run the following command:

 GRANT ALL ON database.* TO user@localhost IDENTIFIED BY 'password';

Replace “database” with the name of the db you created. Replace “user” with a new username. Replace “password” with a password.

  1. Configure your php app to use the database. Somewhere in you php app there will be a file where the database access information is held. This will require three pieces of information:
  2. Location
  3. User
  4. Password

The location will be localhost and the username and password will be the ones you set in the “GRANT ALL…” command you ran.

Upload your application and set ownerships on your files

upload to where?

Say I connect to server using this command

ssh root@174.138.65.31

Then what should I do next to upload ?

There is no single correct location. You can put it anywhere you like, however, the standard location for a website or web app is under:

/var/www

If your app is called SuperApp then:

/var/www/SuperApp

Would be a good location.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.