Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

21 October 2018

ERR_CONNECTION_REFUSED Apache Virtual Hosts

Note to self: Whenever creating Virtual Hosts in Apache, don't name your dev site .dev

Name it .lan instead. For some reason browsers are forcing .dev domains to access the web as you will see with the https:// prefix.

Installing Magento 2.2 on Ubuntu 18.04

I'm learning Magento and needed to install Magento 2.2 on Linux; however, it's is a bit trickier than normal, due to Magento 2.2 not supporting php7.2 yet (support for 7.2 will come in Magento 2.3).

You will need to install either 7.0.13–7.0.x or 7.1.x, but these versions are not in the default repositories. You can add a ppa from here.

It's also best to read the guide to set it up here.

Then you can run your php7.1 install

Note: make sure you install 7.1 modules only. The dom module is actually the xml module.
leon@leon:/var/www/html/magento$ sudo apt install php7.1-
php7.1-bcmath     php7.1-dev        php7.1-intl       php7.1-odbc       php7.1-snmp       php7.1-xsl
php7.1-bz2        php7.1-enchant    php7.1-json       php7.1-opcache    php7.1-soap       php7.1-zip
php7.1-cgi        php7.1-fpm        php7.1-ldap       php7.1-pgsql      php7.1-sqlite3    
php7.1-cli        php7.1-gd         php7.1-mapi       php7.1-phpdbg     php7.1-sybase     
php7.1-common     php7.1-gmp        php7.1-mbstring   php7.1-pspell     php7.1-tidy       
php7.1-curl       php7.1-imap       php7.1-mcrypt     php7.1-readline   php7.1-xml        
php7.1-dba        php7.1-interbase  php7.1-mysql      php7.1-recode     php7.1-xmlrpc  

along with an extensive list of php7.1 modules magento uses

bc-math (Magento Commerce only for 2.2.0 - 2.2.3. Magento Commerce and Magento Open Source as of 2.2.4.)
ctype
curl
dom
gd, ImageMagick 6.3.7 (or later) or both
intl
mbstring
mcrypt
hash
openssl
PDO/MySQL
SimpleXML
soap
spl
libxml
xsl
zip
json
iconv

Copy your magento download folder

sudo cp -r magento /var/www/html/

Set the correct ownership

sudo chown -R leon:www-data /var/www/html/

Read this guide carefully. It's wasn't too clear to me which of the two options were for a local dev environment, but I added myself to the www-data group

Note: To add yourself as a primary or secondary group member of www-data, be aware of the difference between the -g and -G flags. For more info about how being a primary group member works, check out this nice article. If you want a really quick explanation, -g gets you primary membership which means everything you create will be assigned the www-data group instead of your default user group. Secondary membership will give you access, but anything you create will still be your default user group. I think primary is best used if you create another user specifically for magento or web dev. This certainly applies if you are working on a dev server, but I prefer to keep things as is, then modify anything I create for magento with chown.

sudo usermod -a -G www-data leon

and confirm it

groups leon

You should see www-data in your groups.

leon : leon adm cdrom sudo dip www-data plugdev lpadmin sambashare

Set ownership and permissions for www-data

cd /var/www/html/magento && sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + && sudo chown -R :www-data . && sudo chmod u+x bin/magento

Note: After installing php extensions, restart apache for changes to take effect.

service apache2 restart

Finally, visit http://localhost/magento/setup

If you get an HTTP ERROR 500 check your apache error.log for problems.

Update: If you have issues with the layout post install, try the following...

Enable mod rewrite

sudo a2enmod rewrite

and in 000-default.conf (apache2 > sites-available), add this before the closing </VirtualHost> tag.

<Directory "/var/www/html">
    AllowOverride  all
</Directory>

AllowOverride all allows access to .htaccess files, which are important to access for Magento. If you found this solution after googling a similar problem, you'll have to replace 000-default.conf with whatever your VH file is running from.

30 August 2017

Basic commands to quickly set file/folder permissions and ownership

Assuming you have navigated to the directry you want these changes to take effect ie. /var/www/your_vh_domain

Note: Remember to set individual restricted permissions to sensitive files and folders after this bulk action has taken place. For example, with WordPress you will want to set wp-config.php file to 600

Change folder permissions recursively

find public_html -type d -exec chmod 755 {} \;

Change file permissions recursively

find public_html -type f -exec chmod 644 {} \;

Change file ownership recursively - Set your own user and group as desired

chown -R leke:www-data public_html

26 July 2017

Get a Windows licence key from a machine after it's been uninstalled

It turns out you can get the Windows licence key from a machine, even after it's been uninstalled, using Linux. Run this in the console

sudo hexdump -s 56 -e '"MSDM key: " /29 "%s\n"' /sys/firmware/acpi/tables/MSDM

If the key is in your machine's firmware, you should see it.

24 April 2017

QPython Hello World over SSH

QPython is a script engine that allows you to run python programs on Android. It comes with SL4A (Scripting Layer for Android) built in. SL4A has access to many of the APIs available to full-fledged Android applications, but has a greatly simplified interface that makes it easy to get things done by wrapping it in Python modules. It supports my really old Gingerbread 2.3.5 OS and can be installed directly from the PlayStore. It really is a great piece of standalone software that will get you coding in minutes, but I decided to run this over SSH with SSHDroid. Take your time to properly setup and protect SSHDroid, get things like the IP address, then try this hello world application.

On your local PC, create a file called test.py and add

import androidhelper
droid=androidhelper.Android()
droid.makeToast("hello world!")

Copy it to the QPython scripts folder on the SD card (note, your ssh port number and IP Address will be different)

scp -P 2017 test.py root@192.168.0.109:/mnt/sdcard/qpython/scripts

To test the script, you can do it via the QPython GUI interface. You can also run it by calling QPython's python interpreter from a logged in SSH session, and pass it your script to execute. It's a bit like calling python test.py

ssh -p 2017 root@192.168.0.109
/data/data/org.qpython.qpy/files/bin/qpython.sh /mnt/sdcard/qpython/scripts/test.py

If all looks good, you might want to now call it over SSH. Log out of your SSH session. Wrap your whole command in an alias to issue a quick command from your Linux terminal

alias phone-helloworld = 'ssh -p 2017 root@192.168.0.109 "/data/data/org.qpython.qpy/files/bin/qpython.sh /mnt/sdcard/qpython/scripts/test.py"'

14 April 2016

How To Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS

Well this has been tested on Ubuntu 14.04 LTS, but it could work on your linux distro too.

Anyway, here is a quick tutorial for using Apache’s virtual hosts to organise sites to be developed locally.

Note: If you are working with a framework like CodeIgniter and need to modify URLs, you’ll need to activate mod_rewrite. See https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite for more details. tldr;

sudo a2enmod rewrite

Create the folder. I’m using example.dev as the test site. Note: I’ve used .dev because I have a plugin that forces the browser to request sites that support https to change the url from, for example http://example.com to https://example.com This will then take you to the online web page instead of the local one.

sudo mkdir -p /var/www/example.dev/public_html

Allow current user privileges to that folder

sudo chown -R $USER:$USER /var/www/example.dev/public_html

Create a test page

nano /var/www/example.dev/public_html/index.html

and add for example,

<html>
  <head>
    <title>This is example.dev</title>
  </head>
  <body>
    <h1>Success! We are running example.dev on virtual hosts!</h1>
  </body>
</html>

Make a copy of your default virtual host file

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.dev.conf

Edit the copy you just created

sudo nano /etc/apache2/sites-available/example.dev.conf

Change the following lines to point to example.dev

<VirtualHost *:80>
    ServerAdmin admin@example.dev
    ServerName example.dev
    ServerAlias www.example.dev
    DocumentRoot /var/www/example.dev/public_html
</VirtualHost>

Enable the virtual host file with the a2ensite tool

sudo a2ensite example.dev.conf

Restart apache

sudo service apache2 restart

Edit your local hosts file

sudo nano /etc/hosts

Add the line

127.0.0.1 example.dev

Test it. Open a browser and type

http://example.dev

Remember, this will now send you your local site example.dev instead of the actual example.dev online (if such a site exists).

You can delete or comment those local host entries after you’ve finished developing your site.

Update

I recently discovered ubuntu disables the functionality of the .htaccess file by default. If you intend to use it during local development, you will need to add this to your example.dev.conf file.

<Directory /var/www/example.dev/public_html >
    # AllowOverride All allows using .htaccess
    AllowOverride All
</Directory>

so the /etc/apache2/sites-available/example.dev.conf will look like this

<VirtualHost *:80>
    ServerName example.dev
    ServerAlias www.example.dev
    ServerAdmin admin@example.dev
    DocumentRoot /var/www/example.dev/public_html

    <Directory /var/www/example.dev/public_html >
        # AllowOverride All allows using .htaccess
        AllowOverride All
    </Directory>
</VirtualHost>

Update 2

If you want to process url routes make further changes

<Directory /var/www/example.dev/public_html >
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all      
</Directory>

11 April 2016

Getting my wifi working on a new bare bones Debian install

Here’s a quick way to get connected to your wireless network. Note, your router will have to have dhcp enabled. This won’t work for other networks — you’ll need a network manager for that.

Login as su and edit

nano /etc/network/interfaces

At the end of the file, add this

auto wlan0
iface wlan0 inet dhcp
        wpa-ssid the_ssid_name_of_your_network
        wpa-psk your_network_password

As this file now contains your network password, make sure only root can access it.

chmod 600 /etc/network/interfaces

Reboot for changes to take effect.

31 March 2016

Minecraft server on a eeePC

Intro

This tutorial is for getting a minecraft server running on Linux.

I originally made this for the Raspberry Pi, but since my model was the earlier Model-B with only 265MB ram, it wasn’t enough to run the server. Here, I have modified the tutorial for the net install (minimal) version of Debian Linux. The only thing I added during the install process was ssh. When prompted, don’t bother installing things like a web server etc… You don’t actually need ssh, but I find it convinient for my pruposes.

I hear minecraft servers require a good ammount of memory to run (even if the server is just for you and a few friends). It doesn’t require much processing power though. Like I mentioned earlier, I got this up and running on a moderatly overclicked raspberry pi with 256mb of memory, but it would fail after a few moments with just one user. My current succsessful setup is on an old eeePC 701 with 2GB ram. This tutorial expects you have Debian Linux installed, but most other linux systems would probably be fine too.

Another important thing to note is bandwidth allowance. Checkout this page to estimate how many users you can host: http://canihostaminecraftserver.com/

Setup

Log in as root (su). Get Oricle’s JDK —see http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html for more info.

Follow the intructions there. While you are logged in as root, grab git too.

apt-get install git-core 

Next, sign out of root and with your regular user account, create a folder for your minecraft server and cd into it

mkdir minecraft
cd minecraft

Next you’ll need Spigot. Simply put, Spigot is the most widely-used modded Minecraft server software in the world. [Link].

Spigot uses a program called BuildTools to get and build the latest version of the server from GitHub (this is why we downloaded git earlier).

So to get BuildTools

wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar

BuildTools.jar shound now be in ~/minecraft

Next run BuildTools to build your minecraft server (this may take some time).

java -jar BuildTools.jar

Launch the server.

Depending on how much memory your server has, you’ll need to change the Xms and Xmx memory allocation. Xms is the memory allocated to starting up Java, and Xmx is the memory allocated once something is running on it (I think).

java -Xms1024M -Xmx1024M -jar /home/$USER/minecraft/spigot.jar nogui

Note: These values are system specific. Change them to meet the requirements of your system. The minecraft server is now running.

Plugins

Note: Before installing any plugins, make sure you’ve run the server succssfully once. This will create a plugins folder for you to install your server plugins.

To keep the server running smoothly, install this plugin

cd ~/minecraft/plugins
wget http://ci.shadowvolt.com/job/NoSpawnChunks/lastSuccessfulBuild/artifact/target/NoSpawnChunks.jar

Post install

Before you actually play on the server, you obviously have to open a port on your router — the default port is 25565 (allow both TCP and UDP).

Admin commands

Use these commands “as is” in the Linux command line or prefix with / if you are an admin in the game.

op yourself with the command

op [your minecraft username]

To stop, type either into the command line or in the game if you are op

stop or /stop

More commands can be found here

Configuration

Open the config file in ~/minecraft

nano server.properties

Some settings you may want to change

server-name=A Debian Bukkit Server
max-players=4
motd=A Minecraft Server