Install Drupal 8 with phpng (php next generation) on FreeBSD 10.1

After get success with php next generation (phpng) installation I decide to test it with real php script. Drupal came to my attention and I came with a plan of recipe 🙂

  • Drupal 8 (at the moment its 8.0.0-beta4)
  • PHP 7.0.0-dev
  • Lighttpd
  • MariaDB 10

I still use Vultr as Vps provider since my adsl connection is sucks at the moment.

Lets get start

Install MariaDB 10

I use pkg approach than using source way that I did before.

Delete previous installed mysql client

# pkg info | grep mysql
mysql56-client-5.6.22 Multithreaded SQL database (client)
# pkg delete mysql56-client
Checking integrity… done (0 conflicting)
Deinstallation has been requested for the following 1 packages (of 0 packages in the universe):

Installed packages to be REMOVED:
mysql56-client-5.6.22

The operation will free 45 MB.

Proceed with deinstalling packages? [y/N]: y
[1/1] Deinstalling mysql56-client-5.6.22…
[1/1] Deleting files for mysql56-client-5.6.22: 100%

Install MariaDB 10 server and Client

# pkg install -y mariadb100-server mariadb100-client

Enable MariaDB from rc.conf

# echo 'mysql_enable=YES' >> /etc/rc.conf

Start MariaDB Service

# /usr/local/etc/rc.d/mysql-server start

Change MariaDB root password

# /usr/local/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we’ll need the current
password for the root user. If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
… Success!

Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
… Success!

By default, MariaDB comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Add new user for upcoming drupal installation

# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.0.15-MariaDB FreeBSD Ports

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> create database drupal;
Query OK, 1 row affected (0.00 sec)

MariaDB [mysql]> grant all privileges on drupal.* to [email protected] identified by ‘123456’ with grant option;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.01 sec)

MariaDB [mysql]> exit
Bye
#

Compile phpng

I compile phpng using last post.

# mkdir $HOME/tmp/usr/etc

# /root/tmp/usr/etc/php.ini

add these lines

max_execution_time=600
memory_limit=128M
error_reporting=0
display_errors=0
log_errors=0
user_ini.filename=
realpath_cache_size=2M
cgi.check_shebang_line=0

zend_extension=opcache.so.0.0
opcache.enable_cli=1
opcache.save_comments=0
opcache.fast_shutdown=1
opcache.validate_timestamps=1
opcache.revalidate_freq=60
opcache.use_cwd=1
opcache.max_accelerated_files=100000
opcache.max_wasted_percentage=5
opcache.memory_consumption=128
opcache.consistency_checks=0

Install Lighttpd

# pkg install -y lighttpd
Updating FreeBSD repository catalogue…
FreeBSD repository is up-to-date.
All repositories are up-to-date.
The following 2 packages will be affected (of 0 checked):

New packages to be INSTALLED:
lighttpd: 1.4.35_5
pcre: 8.35_2

The process will require 6 MB more space.
1 MB to be downloaded.
Fetching lighttpd-1.4.35_5.txz: 100% 215 KB 219.8k/s 00:01
Fetching pcre-8.35_2.txz: 100% 1 MB 1.1M/s 00:01
Checking integrity… done (0 conflicting)
[1/2] Installing pcre-8.35_2…
[1/2] Extracting pcre-8.35_2: 100%
[2/2] Installing lighttpd-1.4.35_5…
[2/2] Extracting lighttpd-1.4.35_5: 100%

Set Lighttpd run on boot

# echo 'lighttpd_enable=YES' >> /etc/rc.conf

Create document root

# mkdir -p /usr/local/www/data

# touch /usr/local/www/data/index.html

# echo 'tes' > /usr/local/www/data/index.html

Lighttpd Configuration

modules.conf

# ee /usr/local/etc/lighttpd/modules.conf

remove # sign in front of this line:

##
## FastCGI (mod_fastcgi)
##
include “conf.d/fastcgi.conf”

save the file.

# ee /usr/local/etc/lighttpd/conf.d/fastcgi.conf

Add these lines under “server.modules += ( “mod_fastcgi” ) ” : source.

fastcgi.server = ( “.php” => ((
“bin-path” => “/root/tmp/usr/bin/php-cgi”,
“socket” => “/tmp/php.socket”,
“max-procs” => 2,
“bin-environment” => (
“PHP_FCGI_CHILDREN” => “16”,
“PHP_FCGI_MAX_REQUESTS” => “10000”
),
“bin-copy-environment” => (
“PATH”, “SHELL”, “USER”
),
“broken-scriptfilename” => “enable”
)))

Enable fastcgi

Make sure output of

# /root/tmp/usr/bin/php-cgi -v

PHP 7.0.0-dev (cgi-fcgi) (built: Jan 23 2015 04:55:05)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.8.0-dev, Copyright (c) 1998-2014 Zend Technologies

cgi-fcgi means fast cgi enabled.

Testing phpinfo()

# echo "<?php phpinfo();?>" > /usr/local/www/data/info.php

See it from browser.

freebsd_vps_europe_7

 

Fix Lighttpd error message

(network.c.283) warning: please use server.use-ipv6 only for hostnames, not without server.bind / empty address; your config will break if the kernel default for IPV6_V6ONLY changes

That message show up when lighttpd restart.

 

Install Drupal 8

I’ll continue it next time 🙂

How to install phpng aka php7 on FreeBSD 10

FreeBSD Mug

Update : I already try official PHP 7 and wrote it here (using git) and there (using tar.gz file)

FreeBSD Mug by wsinetworks

I just curious about php next generation aka phpng aka php7 . After a few times fail with hhvm ( FreeBSD hhvm and DragonFlyBSD hhvm) I think I need to test something different for my lab experiment 🙂

The choice came to phpng and with the help from Vultr I can cure my curiosity in fast deployment. Well,

I use this configuration :

VPS location : Germany (Frankfurt), Europe.

freebsd_vps_europe1

FreeBSD version : FreeBSD 10 64 bit

freebsd_vps_europe2

Specs : 1 cpu, 768 MB memory, 15 GB storage and 1000 GB transfer.

freebsd_europe_vps_4

Great, Hit ‘Place Order’ button and I can test it.

Steps :

Most of step taken from php.net wiki of phpng.

1. Log in to server using ssh

freebsd_europe_vps5

Continue reading

How to install FTP Server (pure-ftp) on FreeBSD 10.1

This is 3rd post from virtual user hosting with FreeBSD 10 series. First two are located here :

  1. How to install virtual Ftp hosting with PureFTP on FreeBSD 10 : Part 1 – Setup
  2. How to install virtual Ftp hosting with PureFTP on FreeBSD 10 : Part 2 – TLS & Unix Auth

I restart the process using latest FreeBSD version at the moment : FreeBSD 10.1 using custom iso.

Some highlight from FreeBSD 10.1-RELEASE announcement :

  • The new console driver, vt(4), has been added.
  • Support for FreeBSD/i386 guests has been added to bhyve(4).
  • The bhyve(4) hypervisor now supports booting from a zfs(8) filesystem.
  • Support for SMP was added to the armv6 kernels and enabled by default in the configuration files for all platforms that contain multi-core CPUs.
  • Initial support for UEFI boot has been added for the FreeBSD/amd64 architecture.
  • Support has been added to cache geli(8) passphrases during system boot.
  • Support for the UDP-Lite protocol (RFC 3828) has been added to the IPv4 and IPv6 stacks.
  • The new filesystem automount facility, autofs(5), has been added.
  • The sshd(8) rc.d(8) startup script now generates ED25519 sshd(8) host keys if keys do not already exist when ssh_keygen_alg() is invoked.
  • OpenSSH has been updated to version 6.6p1.
  • The nc(1) utility has been updated to match the version in OpenBSD 5.5.
  • Sendmail has been updated to 8.14.9.
  • The unbound(8) caching resolver and ldns have been updated to version 1.4.22.
  • OpenPAM has been updated to Ourouparia (20140912).
  • OpenSSL has been updated to version 1.0.1j.
  • The pkg(8) package management utility has been updated to version 1.3.8.

Back to process 🙂

# uname -rsv
FreeBSD 10.1-RELEASE FreeBSD 10.1-RELEASE #0 r274401: Tue Nov 11 22:51:51 UTC 2014     [email protected]:/usr/obj/usr/src/sys/GENERIC

Update Package

# pkg update
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
………………………………..

…………………………………………

…………………………………………………..
Updating FreeBSD repository catalogue…
Fetching meta.txz: 100%   944 B   0.9k/s    00:01
Fetching digests.txz: 100%    2 MB 108.8k/s    00:19
Fetching packagesite.txz: 100%    5 MB  95.6k/s    00:56
Processing new repository entries: 100%
FreeBSD repository update completed. 23787 packages processed:
0 updated, 0 removed and 23787 added.

Install Ports

# portsnap fetch

# portsnap extract

# cd /usr/ports/ftp/pure-ftpd/

pure-ftpd-freebsd options

To reduce dependency compile process (download and install for each dependency), I ask for pkg help :

# pkg install dialog4ports mysql55-client perl5

Resume make install process of pure-ftp ports.

# make install

Check everything

# pkg info
dialog4ports-0.1.5_2           Console Interface to configure ports
mysql55-client-5.5.40          Multithreaded SQL database (client)
perl5-5.16.3_11                Practical Extraction and Report Language
pkg-1.3.8_3                    Package manager
pure-ftpd-1.0.36_3             Small, easy to set up, fast, and secure FTP server

Enable pureftp

#echo 'pureftpd_enable=YES' >>/etc/rc.conf

Since I want MySQL support for pure-ftp then I install MySQL server.

# pkg install mysql55-server

Enable MySQL server to start automatically after server reboot.

# echo 'mysql_enable=YES' >> /etc/rc.conf

Start MySQL server

# /usr/local/etc/rc.d/mysql-server start

According to pure-ftpd manual (mysql section).

Table structure for hold virtual user as follows :

CREATE TABLE users (
  User VARCHAR(16) BINARY NOT NULL,
  Password VARCHAR(64) BINARY NOT NULL,
  Uid INT(11) NOT NULL default '-1',
  Gid INT(11) NOT NULL default '-1',
  Dir VARCHAR(128) BINARY NOT NULL,
  PRIMARY KEY  (User)
);

Lets create that table.

# cat /etc/master.passwd | grep mysql
mysql:*:88:88::0:0:MySQL Daemon:/var/db/mysql:/usr/sbin/nologin

In my opinion Uid and Gid is 88. But as pure-ftpd manual said about 1000. I use it.

Ok, lets log in to MySQL database and insert user :

# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.40 Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> create database ftp;
Query OK, 1 row affected (0.01 sec)

mysql> use ftp;
Database changed
mysql> CREATE TABLE users (
->   User VARCHAR(16) BINARY NOT NULL,
->   Password VARCHAR(64) BINARY NOT NULL,
->   Uid INT(11) NOT NULL default ‘-1’,
->   Gid INT(11) NOT NULL default ‘-1′,
->   Dir VARCHAR(128) BINARY NOT NULL,
->   PRIMARY KEY  (User)
-> );
Query OK, 0 rows affected (0.02 sec)

mysql> insert into users set User=’alamsyah’,Password=md5(‘123456′), Uid=1000,Gid=1000,Dir=’/home/ftpdata/alamsyah’;
Query OK, 1 row affected (0.00 sec)

mysql>

The command above work : log in to database, create database named ‘ftp’ . Choose database ‘ftp’. Create table named ‘users’ with its structure and insert data into the table.

At this stage pure-ftpd is running, MySQL server also running. Example user also take place.

Configuration

Create directory

# mkdir -p /home/ftpdata

To be able to read MySQL data, purfe-ftpd.conf need to know that.

# cd /usr/local/etc/

# mv pure-ftpd.conf.sample pure-ftpd.conf

# ee pure-ftpd.conf

remove # sign in front of MySQLConfigFile

from

# MySQL configuration file (see README.MySQL)

# MySQLConfigFile               /etc/pureftpd-mysql.conf

# CreateHomeDir               yes

into

# MySQL configuration file (see README.MySQL)

MySQLConfigFile               /usr/local/etc/pureftpd-mysql.conf

CreateHomeDir               yes

save the file.

Next step is create mysql configuration file and fill the data.

# mv pureftpd-mysql.conf.sample pureftpd-mysql.conf

# ee pureftpd-mysql.conf

The file content is well explained.

From these lines :

MYSQLUser       root

# Mandatory : user password. You must have a password.

MYSQLPassword   rootpw

# Mandatory : database to open.

MYSQLDatabase   pureftpd

# Mandatory : how passwords are stored
# Valid values are : “cleartext”, “crypt”, “sha1”, “md5” and “password”
# (“password” = MySQL password() function)
# You can also use “any” to try “crypt”, “sha1”, “md5” *and* “password”

MYSQLCrypt      cleartext

You need to change a few lines :

MysqlUser : root -> keep this as is.

MysqlPassword : not set yet, change to anything designed. For example ‘123456secret’.

MysqlDatabase : ftp (this database already created in above step).

MySQLCrypt : md5 (user alam in previous step use md5)

The rest is not changed.

save the file.

Next step is change mysql password for user root to : 123456secret.

# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.40 Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=password(‘123456secret’) where user=’root’;
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

Test it

# ftp localhost
Trying 127.0.0.1:21 …
Connected to localhost.
220———- Welcome to Pure-FTPd [privsep] [TLS] ———-
220-You are user number 1 of 50 allowed.
220-Local time is now 13:42. Server port: 21.
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
Name (localhost:alam): alamsyah
331 User alamsyah OK. Password required
Password:
230 OK. Current restricted directory is /
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
229 Extended Passive mode OK (|||46398|)
150 Accepted data connection
drwxr-xr-x    2 1000       1000              512 Nov 22 13:42 .
drwxr-xr-x    2 1000       1000              512 Nov 22 13:42 ..
226-Options: -a -l
226 2 matches total
ftp>

If anything is not right then you may refer to log

# tail -f /var/log/messages

If you need to enable TLS you refer to 2nd post.

See you next time!

How to install virtual Ftp hosting with PureFTP on FreeBSD 10 : Part 1 – Setup

My friend who work as R & D for small company told me about new policy from their management. Every one must backup their work once in a week and that backup also include internet backup. Such solution like dropbox is not allowed since their management a bit worry about control. What if they need to conduct audit of their backup or see bad pattern from there. One of management person told him about FTP as alternative that located in vps. Since my friend never use ftp before he ask me to create demo for him. Not a big deal since I ever work with such solution, utilize pureftp as ftp server and mysql as database server where they store user information like directory, password etc. In this post I’ll use FreeBSD 10 as operating system.

Preparation

I use Vultr as vps provider. In reality I should use their ‘strorage series‘ that utilize sata storage. But for demo purpose and speed access. I choose performance series.

How to install virtual Ftp hosting with PureFTP on FreeBSD 10 : choose storage series

Operating system

FreeBSD 10 x64 with latest patch (automatic freebsd-update using posti install) from vultr.

Continue reading

How to install latest WordPress on FreeBSD 10 : enable web server

In my last post I decide to investigate how to install wordpress on FreeBSD 10 (latest version of FreeBSD at the moment). I use two methods of installation; first using ports and second using pkg. After try it myself I prefer to use pkg for future deployment for following reason :

  1. Fast installation; you don’t have to wait for hours as you did with ports.
  2. More secure; you have binary package. No need for compiler stuff installed in my server.

Of course ports can supply you with so many different options with its dialog but as Michael W Lucas said, he prefer to do other job that pay his bills than watch compile process. Me too 🙂

Ok, back to wordpress. Last install is not complete one as I don’t see web server and database.

pkg info result

# pkg info

ca_root_nss-3.17.1             The root certificate bundle from the Mozilla Project
curl-7.38.0_2                  Non-interactive tool to get files from FTP, GOPHER, HTTP(S) servers
freetype2-2.5.3_2              Free and portable TrueType font rendering engine
jpeg-8_5                       IJG’s jpeg compression utilities
kbproto-1.0.6                  KB extension headers
libICE-1.0.9,1                 Inter Client Exchange library for X11
libSM-1.2.2_2,1                Session Management library for X11
libX11-1.6.2_2,1               X11 library
libXau-1.0.8_2                 Authentication Protocol library for X11
libXaw-1.0.12_2,2              X Athena Widgets library
libXdmcp-1.1.1_2               X Display Manager Control Protocol library
libXext-1.3.2_2,1              X11 Extension library
libXmu-1.1.2_2,1               X Miscellaneous Utilities libraries
libXp-1.0.2_2,1                X print library
libXpm-3.5.11_2                X Pixmap library
libXt-1.1.4_2,1                X Toolkit library
libpthread-stubs-0.3_6         This library provides weak aliases for pthread functions
libxcb-1.10_2                  The X protocol C-language Binding (XCB) library
libxml2-2.9.1_1                XML parser library for GNOME
pcre-8.35_1                    Perl Compatible Regular Expressions library
php5-5.4.33_1                  PHP Scripting Language
php5-curl-5.4.33_1             The curl shared extension for php
php5-gd-5.4.33_1               The gd shared extension for php
php5-mysql-5.4.33_1            The mysql shared extension for php
php5-tokenizer-5.4.33_1        The tokenizer shared extension for php
php5-xml-5.4.33_1              The xml shared extension for php
php5-zip-5.4.33_1              The zip shared extension for php
pkg-1.3.8_3                    Package manager
png-1.5.18                     Library for manipulating PNG images
printproto-1.0.5               Print extension headers
t1lib-5.1.2_4,1                Type 1 font rasterization library for Unix/X11
wordpress-4.0,1                State-of-the-art semantic personal publishing platform
xextproto-7.3.0                XExt extension headers
xproto-7.0.26                  X11 protocol headers

Lets continue : Continue reading