How to install FEMP in FreeBSD
To install FEMP in FreeBSD
FEMP is acronym for FreeBSD, Nginx, MariaDB, PHP. Nginx, MySQL and PHP can be combined together as a powerful solution for serving dynamic content on the web. Usually PHP based websites install FEMP for greater performance and low maintenance. In this article we will learn how to install FEMP in FreeBSD.
To install MySQL
Run the following command to install MySQL by using “ pkg install” command.
root@linuxhelp:~ # pkg install mysql56-server
Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
Updating database digests format: 100%
The following 2 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
mysql56-server: 5.6.32
mysql56-client: 5.6.32
.
.
.
.
Although this database client is not listed as
" affected" , it is vulnerable and will not be
receiving a patch. Please take note of this when
deploying this software.
* * * * * * * * * * * * * * * * * * * * * * * *
Message from mysql56-server-5.6.32:
************************************************************************
Remember to run mysql_upgrade the first time you start the MySQL server
after an upgrade from an earlier version.
************************************************************************
Enable and start the MySQL services by running the following command.
root@linuxhelp:~ # sysrc mysql_enable=yes mysql_enable: -> yes root@linuxhelp:~ # service mysql-server start Starting mysql.
Next run “ mysql_secure_installation” command for basic configuration of mysql.
root@linuxhelp:~ # mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we' ll need the current password for the root user. If you' ve just installed MySQL, 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 MySQL 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 MySQL installation has an anonymous user, allowing anyone to log into MySQL 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, MySQL 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! All done! If you' ve completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! Cleaning up...
To install PHP
Run the following command to install the PHP.
root@linuxhelp:~ # pkg install mod_php56 php56-mysql php56-mysqli
Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
The following 7 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
mod_php56: 5.6.25
php56-mysql: 5.6.25
php56-mysqli: 5.6.25
apache24: 2.4.23_1
apr: 1.5.2.1.5.4_1
db5: 5.3.28_4
php56: 5.6.25
.
.
.
.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Message from mod_php56-5.6.25:
***************************************************************
Make sure index.php is part of your DirectoryIndex.
You should add the following to your Apache configuration file:
< FilesMatch " .php$" >
SetHandler application/x-httpd-php
< FilesMatch " .phps$" >
SetHandler application/x-httpd-php-source
***************************************************************
Then copy the “ php.ini-production” file to “ php.ini”
root@linuxhelp:~ # cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini Open the “ php.ini” file and change the value from 1 to 0 as shown below. root@linuxhelp:~ # nano /usr/local/etc/php.ini . . . cgi.fix_pathinfo=0 . . .
Then open “ php-fpm.conf” file and do as instructed.
root@linuxhelp:~ # nano /usr/local/etc/php-fpm.conf
.
.
.
listen = 127.0.0.1:9000
listen=/var/run/php-fpm.sock
.
.
.
listen.owner = www
listen.group = www
listen.mode = 0660
.
.
.
Once all the configuration is done, enable the php-fpm service by using “ sysrc” command.
root@linuxhelp:~ # sysrc php_fpm_enable=yes
php_fpm_enable: -> yes
Start the php-fpm service by running the following command.
root@linuxhelp:~ # service php-fpm start
Performing sanity check on php-fpm configuration:
[27-Sep-2016 02:15:09] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful
Starting php_fpm.
Install the nginx by running the following command.
root@linuxhelp:~ # pkg install nginx
Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
The following 2 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
nginx: 1.10.1_1,2
openssl: 1.0.2_14
.
.
.
.
===> Creating groups.
Using existing group ' www' .
===> Creating users
Using existing user ' www' .
[2/2] Extracting nginx-1.10.1_1,2: 100%
Message from openssl-1.0.2_14:
Copy /usr/local/openssl/openssl.cnf.sample to /usr/local/openssl/openssl.cnf
and edit it to fit your needs.
Message from nginx-1.10.1_1,2:
===================================================================
Recent version of the NGINX introduces dynamic modules support. In
FreeBSD ports tree this feature was enabled by default with the DSO
knob. Several vendor' s and third-party modules have been converted
to dynamic modules. Unset the DSO knob builds an NGINX without
dynamic modules support.
To load a module at runtime, include the new `load_module'
directive in the main context, specifying the path to the shared
object file for the module, enclosed in quotation marks. When you
reload the configuration or restart NGINX, the module is loaded in.
It is possible to specify a path relative to the source directory,
or a full path, please see
https://www.nginx.com/blog/dynamic-modules-nginx-1-9-11/ and
http://nginx.org/en/docs/ngx_core_module.html#load_module for
details.
Default path for the NGINX dynamic modules is
/usr/local/libexec/nginx.
===================================================================
After installation, take the backup of default nginx cofiguration.
root@linuxhelp:~ # mv /usr/local/etc/nginx/nginx.conf /usr/local/etc/nginx/nginx.conf.bkup
Create new nginx.con file and add following lines.
root@linuxhelp:~ # nano /usr/local/etc/nginx/nginx.conf
user www
worker_processes 2
error_log /var/log/nginx/error.log info
events {
worker_connections 1024
}
http {
include mime.types
default_type application/octet-stream
access_log /var/log/nginx/access.log
sendfile on
keepalive_timeout 65
server {
listen 80
server_name localhost
root /var/www/nginx
index index.php index.html index.htm
location / {
try_files $uri $uri/ =404
}
error_page 500 502 503 504 /50x.html
location = /50x.html {
root /usr/local/www/nginx-dist
}
location ~ .php$ {
try_files $uri =404
fastcgi_split_path_info ^(.+.php)(/.+)$
fastcgi_pass unix:/var/run/php-fpm.sock
fastcgi_index index.php
fastcgi_param SCRIPT_FILENAME $request_filename
include fastcgi_params
}
}
}
Create directory for document root by running the following command.
root@linuxhelp:~ # mkdir -p /var/www/nginx
Create directory for error log.
root@linuxhelp:~ # mkdir -p /var/log/nginx
Run the following command to create error log file.
root@linuxhelp:~ # touch /var/log/nginx/error.log
Enable and restart the nginx service by running the following command.
root@linuxhelp:~ # sysrc nginx_enable=yes
nginx_enable: -> yes
root@linuxhelp:~ # service nginx start
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
Then navigate to " nginx" directory and list the files by running the following command.
root@linuxhelp:~ # cd /usr/local/www/nginx
root@linuxhelp:/usr/local/www/nginx # ls
50x.html index.html
EXAMPLE_DIRECTORY-DONT_ADD_OR_TOUCH_ANYTHING
Copy the index.html file to new document root directory.
root@linuxhelp:/usr/local/www/nginx # cp index.html /var/www/nginx/
root@linuxhelp:/usr/local/www/nginx # cd
Create a sample php file into /var/www/nginx/ location.
root@linuxhelp:~ # nano /var/www/nginx/sample.php
< ?php
phpinfo()
?>
Restart the nginx service by running the following command.
root@linuxhelp:~ # service nginx restart
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Stopping nginx.
Waiting for PIDS: 1280.
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx
Open the browser and navigate to http://< IP_address>
To check the PHP file, just edit the URL as follows, http://< IP_address> /sample.php
# pkg install nginx
# pkg install mod_php56 php56-mysql php56-mysqli
# pkg install mysql56-server
# mysql_secure_installation
# nano /usr/local/etc/nginx/nginx.conf