Wednesday, July 5, 2017

FreeBSD: Install FEMP (MariaDB - PHP7 - Nginx) on FreeBSD 11.0

FreeBSD is one of my favorite Unix Operating System because of advance networking tools and commands and the most robust networking task of most Operating system. It has the reputation of being extremely secure. Having said that, creating a web application system and website stored in FreeBSD is only a fraction of its task. In this tutorial, we are going to Install the famous word FEMP which means (FreeBSD - Nginx - MariaDB and PHP7). Lets install first nginx because it has the less requirement.

1. Install Nginx. You need to click the link to install nginx. After installing nginx, we need to configure it later on to easily understand the process. You can go back here to install the second step.



2. Install PHP7. You need to click the link to install PHP7. After installing PHP7, we need to configure it later on to easily understand the process. You can go back here to install the third step which is MariaDB. I choose PHP7 because of the speed and accuracy than the aging PHP5.



3. Install MariaDB. After installing MariaDB database, you can go back here to configure nginx and php7. MariaDB is a drop replacement of MySQL. So, you can import and export MySQL to MariaDB. The commands are almost the same. 



4. Configure Nginx. We need to configure our nginx in /usr/local/etc/nginx/nginx.conf. But if you want a separate file to store your server configuration, you can create your own configuration in the nginx directory. 


vi /usr/local/etc/nginx/nginx.conf



4a. Add this line on server block

   server {
        listen       80;
        server_name  localhost;
        root /var/www/html;
        index index.php index.html index.htm;

        location / {
                try_files $uri $uri/ =404;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        location = /50x.html {
                root /var/www/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

    }

4b. Restart Nginx. We need to restart our nginx to take effect our changes in configuration file. 

service nginx restart




5. Configure PHP7. We need to configure our PHP7 in the directory /usr/local/etc/php-fpm.d. 


vi /usr/local/etc/php-fpm.d/www.conf




5a. Uncomment the line 'listen = 127.0.0.1:9000' by adding semi-colon. Add this line below 'listen = /var/run/php-fpm.sock' . Remove the semi-colon of listen.owner, listen.group, listen.mode. 




5b. Restart PHP7.

service php-fpm restart




6. Create a test php and browse your file to your web browser. You can create your own php file or use below PHP syntax to know the PHP version and modules installed in your operating system. We need to create a file in /var/www/html because our root directory of nginx configuration file is in /var/www/html. After creating the php file, we can now use your preferred browser and navigate the ip address of FreeBSD. Make sure that the directory of the file is in html because that's the common error of newbies.


vi /var/www/html/info.php



<?php phpinfo(); ?>



http:// IP-ADDRESS


No comments:

Post a Comment