Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

abdullahghanem's avatar

install laravel on digitalocean by LAMP

sudo apt-get update
sudo apt-get dist-upgrade

2 - enable the Apache mod_rewrite module

sudo a2enmod rewrite

3 - to know your mysql password

cat /etc/motd.tail

4 - to change your password

mysqladmin -u root -p'password' password newpassword

5 - install Composer, run these commands:

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

6 - if you're using Git you can install it very easily:

sudo apt-get install git

7 - now go to /var/www to install first app

cd /var/www
composer create-project laravel/laravel your-project-name --prefer-dist

if got a error when run above command Error like this: The following exception is caused by a lack of memory and not having swap configured you can use for example, to enable the swap

cd~
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1

8 - Apache vHost PHP Files

Check Apache virtual hosts that come out of the box. Available ones are in sites-available while enabled ones are symlinked from sites-available to sites-enabled.

We'll create new virtual host at /etc/apache2/sites-available/my_app.conf:

sudo nano ../etc/apache2/sites-available/my_app.conf

and past this :

<VirtualHost *:80>
    ServerName my-site.com
    ServerAlias Xxx.ZxZ.1X7.XxX #your server ip

    DocumentRoot /var/www/your-project-name/public
    <Directory /var/www/your-project-name/public>
        # Don't show directory index
        Options -Indexes +FollowSymLinks +MultiViews

        # Allow .htaccess files
        AllowOverride All

        # Allow web access to this directory
        Require all granted
    </Directory>

    # Error and access logs
    ErrorLog ${APACHE_LOG_DIR}/my-site.error.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/my-site.access.log combined
</VirtualHost>

Now Enable the Virtual Host using Apache's tool that comes with the Ubuntu package of Apache2:

# Symlink it to sites-enabled directory
sudo a2ensite my_app

# Reload Apache so the new configuration is loaded
sudo service apache2 reload

9 - now you can visit your site (ip) and you show your project if when visit your site and show White page you can use this link: https://laracasts.com/discuss/channels/servers/install-laravel-51-on-digitalocean

0 likes
6 replies
SNaRe's avatar

Great post. You saved the day for me.

bvcxtds's avatar

damn i fnished all the steps but my digitalocean box is still going to /var/www/html/index.php which is the default Apache2 Ubuntu Default Page. I believe something is wrong with my my_app.conf I copied and pasted the code provided and even tried changing the areas to reflect my work environment

twelvester's avatar

Thanks for the post. It was helpful. but my deployment is still not working

  • copied my project to /var/www/
  • Ran sudo chmod -R gu+w storage and sudo chmod -R guo+w storage
  • login page shows. Yay!

But i cant figure out how to fill in the .env values for my database. DB_HOST=localhost DB_DATABASE=new_database DB_USERNAME=root DB_PASSWORD=<SOME_PASSWORD>

Installed phpmyadmin but i think the my_app.conf file is preventing access to the folder. Have a info.php file in /var/www/ but i also can't access it. How should i configure the my_app.conf file to handle other directories? Thanks

1 like
vladshoob's avatar

Thanks for an awesome tutorial. It worked like a charm for my first website on server.

But now I am trying to add another application, in addition to first one, but to use 8080 port.

I created app2.conf file in sites-available directory. with content

Listen 8080

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:8080>
    ServerName app2.test
    ServerAlias Xxx.ZxZ.1X7.XxX #server ip, I need it to be same as app1

    #same, but pointed to app2 directory
</VirtualHost>

And after restart server.ip:8080 is still not available, sadly.

Maybe some hints? Thanks in advance.

Please or to participate in this conversation.