What good is an app if you can’t run it? This post will discuss setting up a stack using Nginx / PHP7 / and Percona Server for MySQL on Ubuntu. Steps will be similar for other stacks, and you can certainly run this on other stacks and database engines, as Laravel supports multiple ones.
Nginx
Nginx from the normal ubuntu repositories are a bit too old for my liking. Let’s install the latest stable release.
Add the repo for NGINX stable from nginx.org.
wget https://nginx.org/keys/nginx_signing.key sudo apt-key add nginx_signing.key sudo add-apt-repository "deb http://nginx.org/packages/ubuntu/ $(lsb_release -sc) nginx" rm nginx_signing.key
Percona Sever for MySQL
Add repo for Percona Server for MySQL 5.7 from www.percona.com. I recommend Percona over stock MySQL and over MariaDB due to better performance and stability, (more on this in an upcoming blog post).
wget https://repo.percona.com/apt/percona-release_0.1-4.$(lsb_release -sc)_all.deb dpkg -i percona-release_0.1-4.$(lsb_release -sc)_all.deb rm percona-release_0.1-4.$(lsb_release -sc)_all.deb
Install packages
sudo apt update sudo apt install git nginx hhvm percona-server-server-5.7
Install composer for downloading Laravel dependencies.
curl -sS https://getcomposer.org/installer | php
Move composer to bin.
sudo mv composer.phar /usr/local/bin/composer
Clone the application, install the dependencies.
cd /var/www/ git clone https://github.com/JorgenPhi/training-modules cd training-modules composer dump-autoload --optimize composer install php artisan optimize php artisan route:cache cp .env.example .env php artisan key:generate
Replace mysite.local
with the domain-name you’d like to use. Enable SSL if available.
nano /etc/nginx/conf.d/mysite.local.conf
server { listen 80; listen [::]:80; #listen 443 ssl; #listen [::]:443 ssl; #ssl_certificate /etc/nginx/ssl/mysite.local.crt; #ssl_certificate_key /etc/nginx/ssl/mysite.local.key; root /var/www/training-modules/public; index index.php; server_name mysite.local; location ~ \.(php)$ { fastcgi_keep_conn on; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } client_max_body_size 2M; location / { try_files $uri $uri/ /index.php$is_args$args; } }
Create the database and the credentials for the app.
I recommend you generate a random password for this.
mysql -u root -p CREATE USER 'mbt'@'localhost' IDENTIFIED BY 'password'; CREATE DATABASE mbt DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci; GRANT ALL PRIVILEGES ON `mbt`. * TO 'mbt'@'localhost'; FLUSH PRIVILEGES; exit
Tell Laravel our database credentials.
Edit APP_NAME, APP_URL, DB_* with the information specific to your instance.
nano /var/www/training-modules/.env
Have Laravel install the database structure and optimize caches.
chgrp -R www-data storage bootstrap/cache chmod -R ug+rwx storage bootstrap/cache php artisan migrate
Reload nginx configuration
service nginx reload
And that’s it! You’re up and running from scratch! Be sure to login with the default username test@localhost.net
and password secret
and change the password to something more secure.
Thanks for following this series and have a Happy New Year!
Leave a Reply