List

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.

from getcomposer.org.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Posts

1 2 3 4
February 28th, 2018

Concluding the February Challenge

Writing every day for the month of February has been an experience, and has changed my perspective on writing tremendously. […]

February 27th, 2018

Cloudflare2DB

Cloudflare stats are very useful, but they expire and can’t be tracked over a long period of time. That’s why […]

February 26th, 2018

Nightly Database Backups to Google Drive

If you have a Google Apps account (a business account with more than 5 users or one provided by your […]

February 25th, 2018

Sublime Text

Sublime Text is a really powerful text editor and includes tons of functionality relevant to programming. I will dive into […]

February 24th, 2018

Great Resources for Student Developers

Being enrolled in a university comes with its pros and cons (a topic itself worthy of many other blog posts), […]

February 23rd, 2018

What is MVC?

MVC is a term thrown around lots of software development projects. Laravel, Zend, CodeIgniter, Ruby on Rails, Django, iOS, and […]

February 22nd, 2018

Getting Started With Phalcon PHP

To get started with Phalcon, I already have my server stack setup with Ubuntu 16.04, Percona MySQL, Nginx, and PHP […]

February 21st, 2018

What is Phalcon?

Phalcon is a modern PHP framework with the typical feature set you’d expect. Database ORM, error handling, MVC architecture, and […]

February 20th, 2018

Setting Up a PHP Development Environment

If you do PHP development, moving to a PHP IDE is extremely beneficial especially when debugging. PHPStorm is a great […]