I'm currently using Ubuntu for web development, this article explains how I configure Ubuntu for either desktop or virtual machine development. I also talk about Ubuntu Server on Virtual Private Servers (VPS) with the hope of matching development environments between desktop and server.
The goal of this article is to provide a number of commands that you can copy and paste into a terminal to get to a usable install. The idea is to gather all the commands you need to start a skeleton bash script for future installs.
What You will Need
I'm not going to cover how to install Ubuntu in this article. The intent is that you have an existing, fresh install of Ubuntu on either a Desktop, virtual machine or Server. This article has been updated to explain Ubuntu 16.04.
I'm going to run through a few programs that I use on Ubuntu Desktop as well as talk about setting up both a LEMP (Linux, Nginx, MariaDB, PHP) or a LAMP (Linux, Apache, MySQL, PHP) environment. I am not going to explain how to run both on the same machine.
Ready? Connect to your machine.
First I'm going to make sure that my system is up-to-date and ensure I can find the right packages. I'm going to switch to root run updates using apt.
sudo su apt-get update
If you are running a VPS you obviously will already have SSH installed (or you wouldn't be able to connect to it), but however I'm usually running a VM, dedicated machine or Desktop. I use both the client and server on all machines so let's just install them both.
apt-get -y install openssh-server openssh-client
If you are using a VPS (like one from Digital Ocean) or have a publicly available server, you should take a few easy steps to secure it.
If your vps created you a root user, you will have to create your own user account. If you want your user to have root permissions (usually the case) you can add them to the sudo group. I also want to be part of the web group
#adduser yourName adduser nick #usermod -aG groupName username usermod -aG sudo nick usermod -aG www-data nick
Now add your ssh public key to your authorized_keys file. Remember a public key can be shared publicly so it should be easy to place it somewhere you can wget it.
Next (after testing the above user can login), let's secure SSH. Open /etc/ssh/sshd_config with your favourite command line text editor (mine is vi). There are three things I like to do to secure ssh:
- Change the port (any number between 1025 and 65536 will work)
- Disallow root login, set: PermitRootLogin no
- Disallow password login: PasswordAuthentication no
Don't forget to restart the service:
service ssh restart
There now you have a secure ssh server. Don't forget to update the info in your ssh config file on the client computer, then you don't need to remember the username, port, or the private key (if it's different).
If you are working with a VM or VPS you probably want to change the hostname of the server. Most VPS and installs ask for a hostname, this is for when you are working from an image or on an older VPS provider.
#check hostname hostname #Set new hostname hostname your-new-name #Set hostname permanently in /etc/hostname #vi /etc/hostname #Set hostname permanently in /etc/hosts #vi /etc/hosts #Your hosts file should look similar to this: 127.0.0.1 localhost.localdomain localhost 127.0.1.1 hostname.yourdomain.tld hostname YourIP hostname.yourdomain.tld hostname
Here are some tools I can't live without and are installed on all my machines.
snap install nmap apt-get -y install htop git-core vnstat p7zip-full subversion unzip
The following are some tools I only use on the desktop (you might not need any of these).
apt-get -y install scite phpmyadmin krename vlc picard
Removing Excess (pre 16.04)
I don't like whoopsie running (the tool that shares errors with Ubuntu), so I disable it:
vi /etc/default/whoopsie # Change report_crashes parameter to false sudo service whoopsie stop.
Installing LAMP on Ubuntu or Ubuntu Server is the easiest job in the world, you type one command and follow the prompts.
apt-get -y install lamp-server^
If you want to install each application separately (to swap out mysql for mariadb) you can run the following commands:
apt-get install apache2 #16.04 php7 is default but to be save you could use php7.0 apt-get install -y php libapache2-mod-php7.0 #apt-get install mysql-server apt-get -y install mariadb-server mariadb-client
Configuring Apache is usually a pain, configurations change from version to version, so there is always something new to break. Here are the modules I use with Ubuntu 16.04
a2enmod headers expires rewrite
Also set your "ServerName" by creating the file /etc/apache2/conf-available/servername.conf. You can add "ServerName localhost" or replace localhost with any FQDN. Then enable the configuration:
Don't forget to restart service apache2 restart
LEMP (Alternative to LAMP)
It's also pretty easy to install LEMP. I've only tested on Ubuntu 14.04. I'm still new to nginx so this is a work in progress section
apt-get -y install nginx apt-get install php5-fpm service nginx start
how set cgi.fix_pathinfo=0 in /etc/php5/fpm/php.ini
set the configuration "location" to use fastcgi_pass unix:/var/run/php5-fpm.sock;
A forked version of MySQL (after Oracle bought them).
sudo apt-get install software-properties-common sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db sudo add-apt-repository 'deb http://mariadb.mirror.iweb.com//repo/5.5/ubuntu saucy main' sudo apt-get update sudo apt-get install mariadb-server
I've organized some common PHP applications that I use. Because VPS's are so cheap these days I usually only install what I need per server and just run the one application per server; however, as far as I know there is no reason why you can't install all the below.
#php command line interface apt-get -y install php-cli php-mysql #handle images apt-get -y install php-imagick php-gd #for joomla apt-get -y install php-json php-curl php7.0-xml php7.0-zip #for Joomla App Sobipro apt-get -y install php5-xsl php5-sqlite php5-tidy #magento apt-get -y install curl php5-curl php5-mcrypt php5-mhash php5-dev php-pear
If I need to send mail, I install sendmail!
apt-get -y install sendmail