TQ
dev.com

Blog about software development

Subscribe

Installing PHP7 on Ubuntu 16.04

21 Apr 2016 - by 'Maurits van der Schee'

Today is the release of Ubuntu 16.04! On this release you can install the entire LAMP stack using:

sudo apt-get install lamp-server^
sudo apt-get install mariadb-server mariadb-client

The command "php -v" will show that PHP7 is included:

$ php -v
PHP 7.0.4-7ubuntu2 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

If you get the following error from PHPUnit:

Class 'DOMDocument' not found

It is likely that you are missing the package "php-xml", install it using:

sudo apt-get install php-xml

Other great packages for PHP are:

sudo apt-get install php-gd php-zip php-sqlite3 php-pgsql php-curl php-intl php-memcache php-redis

You can't login as the root user with "mysql -uroot". This is caused by the "auth_socket" method which is configured for the "root" user. This means that you are not asked for a password if you connect with the same username via a socket. The command "sudo mysql" will work and will show that MariaDB 10.0.24 is installed:

$ sudo mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 23476
Server version: 10.0.24-MariaDB-7 Ubuntu 16.04

If you now want to make a database named 'mydb' you can simply type:

CREATE DATABASE `mydb` CHARACTER SET utf8 COLLATE utf8_general_ci;

If you want to create a user 'myuser' with password 'mypass' that has permissions to this database do:

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
GRANT ALL PRIVILEGES ON `mydb`.* TO 'myuser'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

If you want to create an alternative root user, then the username should match your Linux username:

CREATE USER 'maurits'@'localhost' IDENTIFIED WITH auth_socket;
GRANT ALL PRIVILEGES ON *.* TO 'maurits'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

NB: This may be "okay" on a dev machine, but it is (for security reasons) not recommended on a production server.

Enjoy!


PS: Liked this article? Please share it on Facebook, Twitter or LinkedIn.