ninethehacker.xyz Setting up a dev environment for laravel/react (Part 1 of Some)

Setting up a dev environment for laravel/react (Part 1 of Some)

time to learn some php


setting up lxc

sudo apt install lxc
sudo lxc-create -t download -n laravel

Obviously if you were deploying on the cloud you would create unprivileged containers for security. I am running on localhost and do not plan to set my container up as a systemd unit or manage it like a daemon so I’m skipping all that drama. I chose to install arch, because I’ve heard many amazing things about it. This is something I may regret as there are few running arch as a server OS.

The lifecycle of an lxc container is very straightforward.

# start
sudo lxc-start -n laravel

# connect shell
sudo lxc-attach -n laravel

# kill
sudo lxc-stop -n laravel

# delete
sudo lxc-destroy -n laravel

If you’re concerned with emulating a deployment environment more exactly you may choose to set up sshd and user groups.

setting up Arch

After connecting I installed and started nginx.

pacman -Syu nginx
systemctl enable nginx
systemctl start nginx

#you can grab the containers IP with
ip addr

# read the inet line from the eth0 interface.

Plugging the ip into my browser showed that nginx was running and configured correctly.

screenie of nginx in browser

At this point I was very drunk on a Friday night so I spent 20 mins moshing to psytrance and went and got a pizza.

setting up laravel

I want to avoid the overhead of Docker, this means I’ll be using composer to install.

pacman -Syu composer php-cgi php-fpm
systemctl enable php-fpm
systemctl start php-fpm
mkdir /var/www
cd /var/www
composer create-project laravel/laravel dev-test

# you can test the install with
php artisan serve --host 10.0.3.10 --port 8000

Composer raised a warning not to install laravel as root, this is my first time with the framework (and php for that matter) so I YOLOd past it. From here I want to hook the app up to nginx. I replaced the default config with the one from the arch wiki and wrote a minimal config file in /etc/nginx/sites-available/dev-test

server {
    listen 80;
    server_name 10.0.3.10;
    root /var/www/dev-test/public;

    location / {
        index index.html index.htm index.php;
    }

    location ~ \.php$ {
        try_files $fastcgi_script_name =404;

        include fastcgi_params;

        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;

        fastcgi_param DOCUMENT_ROOT $realpath_root;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    }
}

You simply link the config over to the sites enabled directory and it will replace the nginx default page with laravel. Nginx and fpm run the app as user http so I chowned the storage directory to them and the app was now configured to start whenever the container was rebooted so I called it a friday night. Probably should have configured a DB though.


there are no comments yet


all comments are manually reviewed before publication