Installing Ubuntu 14.04 LTS Server with PHP 5.6
Written by Mark Chambers onOverview
- Download and install Ubuntu
- Set system clock
- Upgrade to PHP 5.6
- Activate root user
1: Download and Install Ubuntu
1.1: Download
Pick your breed of “Trusty Tahr” below. I’ll be going with the 64-bit Server for this guide.
http://releases.ubuntu.com/14.04.5/
1.2: Install
Load your CD (or mount the ISO) to begin the installer.
Follow the prompts; here’s the process step-by-step:
- In the main menu, select "Install Ubuntu Server" and press Enter.
- Select a language – This is only for the install process. (This guide is in English, so...)
- Select your location – Since I'm in Germany, I have to choose
other
and press Enter... - ...then I select Europe, then Germany.
- Configure locales – Because English and Germany isn't a valid combination, I have to choose a country to base my language settings on. I'll go with United States. ;)
- Configure the keyboard – Detect keyboard layout? Yes.
- Answer the Yes or No questions about which keys exist on your keyboard. Eventually it has enough information to make a good guess. Press Continue. If it seems wrong, Go Back and try again.
- Hardware detection and configuration will now take place. "This may take some time."
- Configure the network – Set the hostname to whatever is appropriate for your network. If you're not sure, just leave the default value and press Enter. For this example it’s
bornkamp
. - Set up users and passwords – Enter full name of the user. For this example it’s going to be
Bornkamp Dev
. - Enter a username for the above user. (This is typically a short-form of the above, in lower-case letters.) For this example it’s simply
dev
. - Choose a password and verify it.
- Encrypt your home directory? Since I'm running a server and not really using the home directory, it's not necessary. So, No.
- Configure the clock – If it successfully detects your time zone, then press Enter. Otherwise press No and choose it manually.
- Now disk detection takes place...
- Partition disks – Choose partitioning method. For my case I'm choosing the first option:
Guided – use entire disk
. - Now select the disk to partition and press Enter.
- Confirm that this is the right disk and that you acknowledge any contents will be deleted and replaced with Ubuntu. Write the changes to disks? Yes.
- Configure the package manager – Before we can install additional packages, we need Internet access. Do you gain access through a proxy? Not in this tutorial. Blank for none. Continue.
- Configuring apt... please wait.
- Configuring tasksel –
No automatic updates
- Software selection – Select extra packages. Use the arrow keys to move up and down and press the spacebar to select a package. For this example we need
OpenSSH server
andLAMP Server
. Press Enter to continue. - Configuring mysql-server-5.5 – Choose a password for the MySQL "root" user. You can also leave it blank for none.
- The rest of the packages and their dependencies will now install...
- Install the GRUB boot loader on a hard disk – Yes
- This concludes the installation. Eject the CD (or unmount your ISO) and press Continue to reboot.
Log in as the user account you just created.
By default the root
user account is disabled in Ubuntu. As unlocking it is not recommended, this guide will use the usual sudo
-prepended commands.
2: Set System Clock
Before we start making changes to the server, let’s make sure the clock keeps in sync.
2.1: Enable built-in Network Time Protocol
timedatectl set-ntp true
2.2: Install the NTP daemon
sudo apt-get -y install ntp
2.3: Configure the NTP Servers
Once the program is installed, open the configuration file:
sudo vi /etc/ntp.conf
Find the selection below:
server 0.ubuntu.pool.ntp.org
server 1.ubuntu.pool.ntp.org
server 2.ubuntu.pool.ntp.org
server 3.ubuntu.pool.ntp.org
Since I'm in Germany, I'm going to replace it with these servers:
server 0.de.pool.ntp.org
server 1.de.pool.ntp.org
server 2.de.pool.ntp.org
server 3.de.pool.ntp.org
For a full list of NTP servers around the world, click here.
2.4: Restart and check the time
sudo service ntp restart
timedatectl
Output looks good:
Local time: Wed 2016-11-30 13:49:36 CET
Universal time: Wed 2016-11-30 12:49:36 UTC
Timezone: Europe/Berlin (CET, +0100)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: no
Last DST change: DST ended at
Sun 2016-10-30 02:59:59 CEST
Sun 2016-10-30 02:00:00 CET
Next DST change: DST begins (the clock jumps one hour forward) at
Sun 2017-03-26 01:59:59 CET
Sun 2017-03-26 03:00:00 CEST
Now our log file timestamps will always be accurate. =]
3: Upgrade to PHP 5.6
3.1: Add the repository
sudo add-apt-repository ppa:ondrej/php
You should get the output:
Co-installable PHP versions: PHP 5.5, 5.6, PHP 7.0 and batteries included.
You can get more information about the packages at https://deb.sury.org
For PHP 5.4 on Ubuntu 12.04 use: ppa:ondrej/php5-oldstable
BUGS&FEATURES: This PPA now has a issue tracker: https://deb.sury.org/#bug-reporting
PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/
WARNING: add-apt-repository is broken with non-UTF-8 locales, see https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:
# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
Press [ENTER] to continue or ctrl-c to cancel adding it
Press Enter
to continue.
3.2: Get PHP 5.6
Now run the following commands:
sudo apt-get update
sudo apt-get -y install php5.6 php5.6-mbstring php5.6-mcrypt php5.6-mysqlnd php5.6-xml php5.6-gd php5.6-dev make
3.3: Out with the old and in with the new
Disable PHP 5.5:
sudo a2dismod php5
Remove PHP 5.5:
sudo apt-get -y purge php5-common
Now enable 5.6:
sudo a2enmod php5.6
Now restart the server:
sudo service apache2 restart
3.4: Check the current version of PHP
php -v
If you see PHP 5.6.x...
then you did something right!
4: Activate the root user
By default Ubuntu disables the superuser root
in favor of privileged commands needing to be run with sudo
, which then requires a password confirmation — good for preventing accidents. But if you’re fearless, rushed or just plain lazy, we can set root
free like so:
sudo passwd root
First you are asked for your current user password, then you can choose (and confirm) the root
password.
Now go ahead and change to root
:
su root
Don’t break anything!
Enable root login over SSH
As root
, edit the sshd_config
file in /etc/ssh/sshd_config
:
vi /etc/ssh/sshd_config
Add a line in the Authentication
section of the file that says PermitRootLogin yes
(if this line already exists with the value without-password
, then replace with yes
):
# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
Save the updated /etc/ssh/sshd_config
file.
Restart the SSH server:
service ssh restart
You can now connect to the server as root
over SSH.