NextCloud Install

NextCloud is an open-source next-generation file sharing and file synching web-application that you can run and install on your own Linux server. It’s similar to Dropbox, the file-sharing cloud application. The big difference between Dropbox and NextCloud is that you get to run your own cloud storage on your own server. The following are instructions on how to install NextCloud on an Ubuntu Server 16.04 LTS server.

Run Updates First

$ sudo apt-get update
$ sudo apt-get upgrade -y
$ sudo apt-get dist-upgrade -y

Install Apache

$ sudo apt-get install apache2

Install MySQL Server

$ sudo apt-get install mysql-server mysql-client
$ sudo mysql_secure_installation

Install PHP

$ sudo apt-get install php libapache2-mod-php php-mbstring php-zip php-xml php-mysql php-gd
$ sudo apt-get install php-json php-curl php-intl php-mcrypt php-imagick php-dom unzip

Edit php.ini change the memory limit and upload and post file sizes to something bigger. Restart Apache.

$ sudo nano /etc/php/7.0/apache2/php.ini
memory_limit = 512M
upload_max_filesize = 500M
post_max_size = 500M
$ sudo service apache2 restart

Create Database and User. Flush privileges.

$ mysql -u root -p
mysql> create database nextcloud;
mysql> grant all privileges on nextcloud.* to 'ncuser'@'localhost' identified by 'password';
mysql> flush privileges;
mysql> exit;

Download and Install the latest Nextcloud. Give permissions to Apache.

$ cd /var/www/html
$ sudo wget https://download.nextcloud.com/server/releases/nextcloud-11.0.2.zip
$ sudo unzip nextcloud-11.0.2.zip
$ sudo chown -R www-data:www-data nextcloud

Setup Apache

$ sudo nano /etc/apache2/sites-available/nextcloud.conf
 
Alias / "/var/www/html/nextcloud/"
 
 Options +FollowSymlinks
 AllowOverride All
 
  Dav Off
 
 SetEnv HOME /var/www/html/nextcloud
 SetEnv HTTP_HOME /var/www/html/nextcloud

Enable Nextcloud. Disable default.

$ sudo a2ensite nextcloud.conf
$ sudo a2dissite 000-default.conf

Enable the following

$ sudo a2enmod rewrite
$ sudo a2enmod headers
$ sudo a2enmod env
$ sudo a2enmod dir
$ sudo a2enmod mime
$ sudo service apache2 restart

Open your browser and access your server via IP address or domain name to complete the NextCloud install.

You will be asked to enter a new username and password. Also enter your database credentials to complete the installation.

Quick Database Check

Here’s a quick PHP script to check if your web server can connect to your MySQL database. It’s a neat little script if you don’t have any application installed yet, and you just want to see if your web server setup can quickly connect to the database. All you have to do is create a new file called connect.php, and place the following code inside. Just change the username, password and database. Most likely the hostname will be localhost.

$ sudo nano /var/www/html/connect.php
$username = "user";
$password = "password";
$hostname = "hostname";
$database = "database";
 
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
echo "Successfully Connected to the MySQL Database.<br/>";
 
$selected = mysql_select_db("$dbname", $dbhandle) or die("Could not select database");
echo "Successfully Connected to Database called: $database";

It’s also available on my Github gist.

Laravel 5.4 Install

This is the installation of Laravel 5.4 on an Ubuntu Server 16.04 LTS. Laravel requires that you run Apache, MySQL and PHP. In this installation, I’m using the following versions: Apache 2.4.18, MySQL 5.7.17 and PHP 7.0.15. The installation of Laravel has changed over the years. I wished the installation was simpler. You can try Forge, but it’s not free. It also requires that you have an account at Linode, Digital Ocean or AWS. Forge costs $15 per month and Forge Plus is $30 per month. If you don’t want to pay, I’m afraid you are going to have to install Laravel yourself. Laravel installation may vary based on the distro you’re using. These instructions are for the Ubuntu Server 16.04 LTS.

Run Update

sudo apt-get update
sudo apt-get upgrade

Install Apache

sudo apt-get install apache2
sudo a2enmod rewrite
sudo service apache2 restart

Install MySQL

sudo apt-get install mysql-server
sudo mysql_secure_installation

Install PHP

sudo apt-get install php libapache2-mod-php php-mbstring php-zip php-xml php-mysql

Install Composer

sudo curl -sS https://getcomposer.org/installer | sudo php — —install-dir=/usr/local/bin —filename=composer
# you may have to move composer manually if it doesn't work
sudo mv composer.phar /usr/local/bin/composer
# check if composer is accessible globally
composer -V

Install Laravel Installer

composer global require "laravel/installer"
# Using alias instead of $PATH
echo 'alias laravel="~/.composer/vendor/bin/laravel"' >> ~/.bashrc
source ~/.bashrc
# add source ~/.bashrc to .profile to load automatically
echo 'source ~/.bashrc' >> ~/.profile
# restart apache
sudo service apache2 restart
# check if laravel is accessible globally
laravel

Install New Laravel Project

# set permissions
cd /var/www/
sudo chown -R ubuntu:ubuntu /var/www/html
sudo chmod -R 755 /var/www/html
# install new project
cd /var/www/html
laravel new project
# give apache permissions 
sudo chgrp -R www-data /var/www/html/project/storage
sudo chgrp -R www-data /var/www/html/project/bootstrap/cache

Configure Apache

cd /etc/apache2/sites-available
sudo cp 000-default.conf project.conf
sudo nano project.conf
#
<VirtualHost *:80>
  ServerName local.project.com
  ServerAdmin admin@project.com
  DocumentRoot /var/www/html/project/public
  <Directory "/var/www/html/project">
    AllowOverride All
  </Directory>
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
#
sudo a2ensite project.conf
sudo a2dissite 000-default.conf
sudo service apache2 restart

Finally, you can now access Laravel from the browser from the server IP address or domain.

Working With AWS LightSail

Just a quick demo how to work with AWS LightSail. LightSail is AWS lightweight VPS at a fixed price point. You can install just the OS. You can choose either Amazon Linux or Ubuntu OS. If you prefer, you can install any of the several ready-made applications provided by AWS in conjunction with Bitnami. In this example, I installed Ubuntu and Apache just demonstrate how to easy it is to work with LightSail.

Where Featured Images Are Stored

The WordPress Genesis theme uses featured images on its posts on several of its themes. If you’re curious as to where the Genesis theme stores the image links on the database, you’ll need to go to a couple of WordPress tables to find them. First and foremost, you’ll need to get the ID of your WordPress post. You can easily find this by hovering over the edit link and checking the ID number.

Let’s pretend the post ID is 110. You will then need to find the meta_value in the wp_postmeta table.

Table: wp_postmeta

meta_id     post_id   meta_key         meta_value
544         110       _thumbnail_id    45
SELECT meta_value FROM wp_postmeta WHERE meta_key='_thumbnail_id' and post_id=110;

The result is 45. Now that you have the meta_value, you can then search for the link from the wp_posts table.

Table: wp_posts

ID      post_type       guid
45      attachment      http://yourdomain.com/wp-content/uploads/2017/03/featured-image.jpg
SELECT guid FROM wp_posts WHERE post_type='attachment' and id=45;

The result will be the URL of the image, e.g. http://yourdomain.com/wp-content/uploads/2017/03/featured-image.jpg.

It’s an odd place to store the image link, but that’s where it is.