Halaman

Tampilkan postingan dengan label php. Tampilkan semua postingan
Tampilkan postingan dengan label php. Tampilkan semua postingan

Jumat, 04 Juni 2021

How to fix 404 Not Found Nginx - PHP

I'm working on moving applications from the old server to the new server and have to re-install. At this stage I configure PHP-based applications with related frameworks using Nginx as a web server. The problem that arises is the message Not Found with code 404, when the application runs the index.php file which then calls another file to run the actual process.

 

Next I created a test.php file to detect errors in the application and the tes.php file can run normally (code 200).

Information from curl shows the index.php file Found (302), but controller and action Not Found (404).



Status code HTTP/1.1 302 Found, indicates the requested resource resides temporarily under a different URI

The 404 Not Found message states that the server has not found anything matching the Request-URI.

The results of sudo tail -f /var/log/nginx/error.log and sudo tail -f /var/log/nginx/access.log don't show anything odd. The php files have been processed correctly, but the problem lies most likely in my Nginx configuration which is not suitable for processing php files.

I changed the configuration in the file /etc/nginx/sites-available/myweb.domain.com, which is from

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

location / {
try_files $uri $uri/ /index.php?$args;
}

Then do sudo service nginx restart and check the result:


As a result, my applications can run as they should and the status becomes HTTP/1.1 200 OK  or request has succeeded.

Sabtu, 09 Oktober 2010

Using PHP Radius Extension


The FreeRADIUS server software package includes several tools to assist in testing and using the server, some pf them is Radclient and Radtest. To work with applications such as Web inventory Systems, the system has to connect with Radius server using Radius Client. Today I use PHP Radius Extension as Radius client.

PHP Radius client library
This package is PECL extension for Radius (Remote Authentication Dial In User Service). This extension is based on the libradius of FreeBSD. It allows clients to perform authentication and accounting by means of network requests to remote servers.


Auth_RADIUS
This package is a php wrapper around the php radius extension. There are different Classes for the different authentication methods available through RADIUS. If we are using CHAP-MD5 or MS-CHAP authentication, we will also need the Crypt_CHAP package. In addition, if using MS-CHAP authentication, we will need to enable the mhash and mcrypt extension in php.ini. Documentation of the radius extension is available through the PHP manual at http://www.php.net/radius

In previous install link, my sistem has these modules installed
# php -m
[PHP Modules]
Core
date
ereg
gd
libxml
mysql
mysqlnd
pcre
Reflection
session
SPL
standard

I started the installation with the following sequence:

1. Install Auth_Radius a PEAR wrapper classes for the RADIUS PECL.
#/usr/ports/net/pear-Auth_RADIUS
#make
===> Registering installation for pear-1.9.1
===> Returning to build of pear-Auth_RADIUS-1.0.6
===> Configuring for pear-Auth_RADIUS-1.0.6
===> Registering installation for pecl-radius-1.2.5
#make install
----------------------------------------------------------------------
Libraries have been installed in:
/usr/ports/net/pecl-radius/work/radius-1.2.5/modules
****************************************************************************
The following line has been added to your /usr/local/etc/php/extensions.ini
configuration file to automatically load the installed extension:
extension=radius.so
****************************************************************************
===> Returning to build of pear-Auth_RADIUS-1.0.6
===> Generating packing list
===> Generating temporary packing list
===> Checking if net/pear-Auth_RADIUS already installed
===> Installing examples in /usr/local/share/examples/pear/Auth_RADIUS.
install ok: channel://pear.php.net/Auth_RADIUS-1.0.6
===> Registering installation for pear-Auth_RADIUS-1.0.6

# make clean
===> Cleaning for pear-1.9.1 ###PEAR framework for PHP
===> Cleaning for php5-5.3.3_2
===> Cleaning for pecl-radius-1.2.5 ###Radius client library for PHP
===> Cleaning for php5-xml-5.3.3_2
===> Cleaning for pear-Auth_RADIUS-1.0.6 ###PEAR wrapper classes for the RADIUS PECL


2. Install additional package
#/usr/ports/security/pear-Crypt_CHAP
extension=mcrypt.so
extension=hash.so

3. List modules installed
# php -m
[PHP Modules]
Core
date
ereg
gd
hash
libxml
mcrypt
mhash
mysql
mysqlnd
pcre
radius
Reflection
session
SPL
standard
xml

# pear list
Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.7 stable
Auth_RADIUS 1.0.6 stable
Console_Getopt 1.2.3 stable
Crypt_CHAP 1.0.2 stable ### here version 1.0.2
PEAR 1.9.1 stable
Structures_Graph 1.0.3 stable


4.I have to upgrade Crypt_CHAP (replace mhash function to hash function, because I'm on php5.3)
# pear upgrade
downloading Crypt_CHAP-1.5.0.tar ...
Starting to download Crypt_CHAP-1.5.0.tar (Unknown size)
........done: 22,528 bytes
upgrade ok: channel://pear.php.net/Crypt_CHAP-1.5.0
Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.7 stable
Auth_RADIUS 1.0.6 stable
Console_Getopt 1.2.3 stable
Crypt_CHAP 1.5.0 stable
PEAR 1.9.1 stable
Structures_Graph 1.0.3 stable

5. Restart Apache service
#apachectl graceful

6. Start Radius in debug mode



7. Test authentication



8. Use sample number 2 from here and modify arguments as needed, and test it. It works.




Jumat, 08 Oktober 2010

Installation of Mondes' LAB1

Steps to install Mondes' LAB1. This was done remotely via telnet, from 11.50pm to 02.30am.

1. Install Apache web server with prefork MPM (apache-2.0.63_16)
#cd /usr/ports/www/apache20 (released 2008-01-19)
#make install clean
(current Apache is v2.2.16, released 2010-07-25)


2. Install current version of PHP5 (php5-5.3.3_2, released 2010-07-22)
#cd /usr/ports/lang/php5
#make install clean
***************************************************************
Make sure index.php is part of your DirectoryIndex.
You should add the following to your Apache configuration file:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
***************************************************************
This port has installed the following files which may act as network servers and may therefore pose a remote security risk to the system.
/usr/local/libexec/apache2/libphp5.so
/usr/local/bin/php
/usr/local/bin/php-cgi

AddType application/x-httpd-php .php <<.html>>
AddType application/x-httpd-php-source .phps


3. Install mysql shared extension for php (php5-mysql-5.3.3_2)
#cd /usr/ports/databases/php5-mysql
#make install clean
***************************************************************
The following line has been added to your /usr/local/etc/php/extensions.ini configuration file to automatically load the installed extension:
extension=mysql.so
***************************************************************


4. Install session shared extension for php (php5-session-5.3.3_2)
#cd /usr/ports/www/php5-session
#make install clean
***************************************************************
The following line has been added to your /usr/local/etc/php/extensions.ini
configuration file to automatically load the installed extension:
extension=session.so
***************************************************************


5. Install gd shared extension for php (php5-session-5.3.3_2)
#cd /usr/ports/graphics/php5-gd
#make install clean
****************************************************************************
The following line has been added to your /usr/local/etc/php/extensions.ini
configuration file to automatically load the installed extension:
extension=gd.so
****************************************************************************

6. Install text-based web browser
#cd /usr/local/www/lynx
#make install clean
This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.
/usr/local/bin/lynx


7. Make FreeBSD reread the files in the path so it knows what's there
#rehash


8. Adding PHP5 module to Apache
#cd /usr/local/etc/apache2/
===>modify httpd.conf


9. Create test page
# echo ""  >> /usr/local/www/data/tester.php


10.Test the installation
#apachectl start
#lynx localhost/tester.php

ready for web management (RADIUS and Monitoring).

Rabu, 21 April 2010

FPDF Multicell: Printing automatic word wrap and border

Purpose: To print columnar style report with text descriptions lie in top area of a report.
Software: PHP + FPDF
Output:

In FPDF we use Cell method/function to print columnar data, while MultiCell is used for variable-length data to fit in a specified area.

MultiCell allows printing text with line breaks. Word or text wrapping can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other. Text can be aligned, centered or justified. The cell block can be framed and the background painted.

The example above shows a header - as what this article want to address - as a part of a Purchase Requisition form, while the same also apply for Billing or Application form, etc.

Here is a part of my class:


class PDF extends FPDF {
//my var declaration
//my public declaration

function BuatJudulObyekKerja($nomor) {
$nrowHeight=4;
$npageWidth=179;
$nwidthCol1=40;
$nwidthCol2=30;
$nwidthCol3=25;
$nColonWidth=2;

$this->SetFont('Helvetica','B',10);
$this->Cell(0, 0,'Nomor: '.$nomor,'',1,'C',0);
$this->Ln(3);
$this->SetFont('Helvetica','',8.5);
$this->Cell($npageWidth, $nrowHeight, '', 'LTR',0,'R',0);
$this->Cell($npageWidth, 2, '', '',1,'R',0);
$this->Cell($nwidthCol1, 1,'Description', 'L' ,0,'L');
$this->Cell(nColonWidth, 1,':', '' ,0,'L');

$this->SetXY(58,33);

$y=$this->GetY();
$this->MultiCell(137,$nrowHeight,$this->pan_namaobyek,'R','J');
$y1=$this->GetY();

$nrowPrinted=($y1-$y) /$nrowHeight;
$this->SetY($y);
for ($i=0; $i < $nrowPrinted; $i++) {

$this->Cell($nwidthCol1+11, $nrowHeight,'', 'L' ,1,'L');
}


$this->Cell($nwidthCol1, $nrowHeight,'Form','LT' ,0,'L');
$this->Cell($nColonWidth, $nrowHeight,':','T' ,0,'L');
$this->Cell($nwidthCol1,$nrowHeight, $this->kategori , 'T' ,0,'L');
$this->Cell($nwidthCol2, $nrowHeight,'','T',0,'L');
$this->Cell($nwidthCol3, $nrowHeight,'Doc.ID#', 'LT' ,0,'L');
$this->Cell($nColonWidth, $nrowHeight,':','T' ,0,'L');
$this->SetFont('Helvetica','B',8.5);
$this->Cell($nwidthCol1, $nrowHeight, $this->pan_pk , 'TR',1,'L');
$this->SetFont('Helvetica','',8.5);

$this->Cell($nwidthCol1, $nrowHeight,'Raised by','LT' ,0,'L');
$this->Cell($nColonWidth, $nrowHeight,':','T' ,0,'L');
$this->Cell($nwidthCol1,$nrowHeight, $this->usaha , 'T' ,0,'L');
$this->Cell($nwidthCol2, $nrowHeight,'','T',0,'L');
$this->Cell($nwidthCol3, $nrowHeight,'Reff.No', 'LT' ,0,'L');

$this->Cell($nColonWidth, $nrowHeight,':','T' ,0,'L');
$this->Cell($nwidthCol1, $nrowHeight, $this->pan_nosurat , 'TR',1,'L');
....
}

Rabu, 17 Maret 2010

PHPLOT (image does not display)

To show live charts on an event, I've search and found many Flash charts available. While trying some of them, I saw the beauty of SWF files...it's easy to use and their appearance are good. Unfortunately, I could not found SWF files that have feature to draw a supplemental chart. For example, to draw an up and bottom line as reference, or to print some point marks; other than the data itself to be displayed. After all, I've decided to use PHP's image that will generate an image on the fly. Rather than programatically build my self, I tried to use PHPLot on my laptop.

After modifying the source code, and ... baaaang ... a "live chart" appears on the screen ... of course with a twinkle / flicker when the refresh occurs on the web page every n seconds. In order to be more informative, I create additional lines and reference numbers as a guide.

Now, it's time to convey to the production system ... and make some tests. Surprisingly, the chart does not appear - the image does not display. I check GD library (2.0.34), in case of not installed in my production systems. But it was there. What's the problem?
I looked into the Apache2 error log, saying that PHP Warning: Division by zero in phplot.php on line 4432. After making some corrections on phplot.php ... the chart still not appear.

Then I compare the development and production environment, try to set display_errors = Off in PHP.ini file.

Great ..... it's work!! This saves me time, after spending of course!gile

On March 16, 2010 I had to work all day ... from 10:30 am untill 01:30 am in the office - to create and configure a network, install the IP camera, move applications to servers, and perform simulation- and continue to work until 04:20, the next day at home. I use FTP to transfer and update files on server at office ... but still encounter problem of a graph does not appear; go to bed ngantuk for about 2 hours and then returned to the office.

At 07:42 AM on March 17 .... last minute before I'm sure everything went smoothly..the charts appears after changing display_errors to off. I laughed out loud tepuktangan, a problem that should not have happened to me, but I might have changed some time ago for other cases.