Skip to content

Instantly share code, notes, and snippets.

@alamkanak
Last active December 1, 2020 23:24
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alamkanak/771ffa63b159c5f0b936 to your computer and use it in GitHub Desktop.
Save alamkanak/771ffa63b159c5f0b936 to your computer and use it in GitHub Desktop.
How I set up a server in DigitalOcean for Laravel

Create a droplet

  1. Go to digitalocean.com and hit Create Droplet.
  2. Name your droplet, select size and region.
  3. Select ubuntu distribution and lamp application.
  4. Click Create droplet.
  5. You will receive an email with ip address and user credentials.

Log in with putty

  1. Download putty from: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
  2. Open putty.
  3. Put you ip address that you received in the email.
  4. A terminal (ssh) window will appear.
  5. Enter root as your user name.
  6. Enter the password that you received with the email.
  7. You will be asked to change your password. Change your password.
  8. A success message along with the MySQL password will be displayed. Note this password.

Set up phpmyadmin

  1. Run sudo apt-get install phpmyadmin apache2-utils in the ssh.
  2. Select Apache2 for the server.
  3. Choose YES when asked about whether to Configure the database for phpmyadmin with dbconfig-common.
  4. Enter your MySQL password when prompted.
  5. Enter the password that you want to use to log into phpmyadmin.
  6. After the installation has completed, you have to add phpmyadmin to the apache configuration. Run sudo nano /etc/apache2/apache2.conf to open the apache config file.
  7. Append Include /etc/phpmyadmin/apache.conf at the end of the file.
  8. Save and exit the file.
  9. Restart apache by running sudo service apache2 restart.

Install git and composer

  1. Install git by running sudo apt-get install git.
  2. Install composer by running curl -sS https://getcomposer.org/installer | php.
  3. Move the composer to the bin folder to be able to use it anywhere sudo mv composer.phar /usr/local/bin/composer.

Set up automated deployment with butbucket.org

Now I want to set up an automated deployment system such that whenever I push a commit to a branch in my repor in bitbucket the server will automatically fetch the changes and thus the site will always be up to date automatically.

Set up SSH keys in server

  1. Go to root directory by running cd.

  2. Create a folder named .ssh by running mkdir .ssh.

  3. Go to the folder just created by running cd .ssh.

  4. Create an ssh key by running ssh-keygen -t rsa.

  5. When a file name is asked, put bitbucket_rsa as the file name.

  6. No need to enter a passphrase for now.

  7. To get the public key, run cat bitbucket_rsa.pub.

  8. Copy the key (including the part with ssh-rsa).

  9. Create a file in .ssh folder by running sudo nano config.

  10. Type the following in the file.

    Host bitbucket.org
      IdentityFile ~/.ssh/bitbucket_rsa
    
  11. Save the file.

Add the SSH key in bitbucket

  1. Open a browser and log into Bitbucket.
  2. Choose avatar > Manage Account from the menu bar.
  3. The system displays the Account settings page. Click SSH keys.
  4. The SSH Keys page displays. It shows a list of any existing keys. Then, below that, a dialog for labeling and entering a new key.
  5. Enter a Label for your new key, for example, Default public key.
  6. Paste the copied public key into the SSH Key field.
  7. Click the Add key button.
  8. Test the connection with bitbucket by running ssh -T git@bitbucket.org in the server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment