Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Friday, February 20, 2015

Update PHP Version to 5.4.37 in Ubuntu 12.04

PHP 5.4.37 is not available in Ubuntu 12.04 repositories. You may update your PHP version from some other repositories (PPA).

I am going to use ondrej's oldstable PPA for updating PHP. You will have to run the following commands to complete the process:

1. sudo apt-get install python-software-properties
2. sudo add-apt-repository ppa:ondrej/php5-oldstable
3. sudo apt-get update
4. sudo apt-get install php5

The latest version of PHP will be installed.

Thursday, December 20, 2012

PHP Script Execution Nature, A Problem and Solution

Do you know that a php script cannot be executed simultaneously on a single server. Even another script which is included with a executing script also becomes unavailable for execution or being included with other script. Usually a php script with complex algorithms and multiple mysql operations takes approximately 0.005 seconds for completing execution. For usual scripting with some mysql operations and an limited amount of users, the execution nature of apache server (PHP) is perfect. But, suppose, if a script has single or multiple API request to remote servers, then it will take some extra seconds to accept the reply. By the mean time other requests will be queued and will be processed while the script becomes free.

Recently, I have created a script which has more than 25 API requests and requires around 1-2 minutes for completing the whole execution. As the script has some dependencies over some universal scripts of my application, so I needed to change something to make the system always accessible for other users. First thing came to mind was to divide the whole execution and run it on multiple execution to make sure it frees the related scripts for other users for some while. I have used a Session Variable ($_SESSION) where I have put all information required for requesting API request. For every execution of the script, now it sends only a single API request, and then frees the script and redirect to the same script for rest of the requests.

Saturday, March 10, 2012

Testing Webserver (httpd) at VirtualBox

Now, my challenge is to browse websites hosted in CentOS which is running in a VirtualBox window. Already installed httpd, php, mysql, perl etc. and they are working fine. I could manage to test a script using text based web browser lynx.

Now, I am going to try from host pc using graphical browser. I'll have to define a ip address at guest CentOS then try to browse it.

Before starting, I have to change network settings of virtual box for CentOS installation. I changed it at virtualBox>Settings>Network>Attached to, choose "Host-only Adapter" then clicked "Ok". Now it's ready for doing the rest.

I forgot the way how to change ip, searching, but finding nowhere. What happened!! Better keep searching my notes of my B.Sc networking classes. I don't know where to find them. Wow, I have found those notes, but they are about Red Hat, I have to make them useful for my current CentOS.

Yeah, I can now browse hosted files from guest pc. Let me tell what I have done:

First, I have checked virtual host-only network ip address of host pc.
Then, I have edited ip address of guest "centos" by the following command prompt codes:

vi /etc/sysconfig/network-scripts/ifcfg-eth0

pressed "i" for inserting text into the script, started from at end of the lines there. Added these following lines:

BOOTPROTO=static
IPADDR=192.168.56.5
NETMASK=255.255.255.0
GATEWAY=192.168.56.1

For your information 192.168.56.1 is the ip address of host-only network card (virtual).

Then restarted network by the following command prompt code:

service network restart

Then, went to my graphical browser at host, and got the default centos-apache page. And also could browse my hosted files.

Friday, March 9, 2012

Real approach to install php/mysql on linux-apache web server

Hi, I have just found out that working on lampp in linux is not a real approach of working on PHP based software development. Recently, I need to use some multimedia encoder/decoders to compile some of my scripts, but lampp could not help me. We usually use lampp to install the whole working environment fast and in one click, but when we need some extra things to be included with this, it may not help and consume time to start.

I am using CentOS to make a real web server (for test scripts), it has a nice built in package manager YUM. I have already installed "Apache 2" for creating web server. It was easy and fast, apache (httpd) comes with centOS disks as default. I used the following line to install it.

yum install httpd

Then, I had to install php, php command line, perl, mysql to make the server ready for lamp development environment. This installation process required Internet connection and I used following line to install the whole thing.

yum install php php-cli mysql

It automatically searched all dependencies and the mirror from which they will be installed.

I didn't check the environment yet, but hope, it will help me fine.

Tuesday, February 28, 2012

Installing XAMPP/LAMPP in Linux

For Ubuntu:

Start Terminal.

If you have already updated you apt repository then enter write "apt-get install lampp" in terminal and press enter. XAMPP will be installed automatically.

But, if you don't have updated apt repository, then write "apt-get update" in terminal and press "Enter".

Sometime it becomes difficult to install software from Bangladesh. For solving this problem go to "System Settings" from start menus. Then, go to "Software Sources" from Settings menus. Click "Ubuntu Software" tab. change the source of Download from "Download From" drop-down filed. Choose Main Server to avoid problem of online software installation using "apt-get". Don't forget to update apt by writing "apt-get update" at terminal and pressing enter.

For CentOS:

First check if your "wget" command is installed for the system. If not, login to terminal as root and then write "yum install wget" and press enter. Then press y and enter to approve installation of "wget".

Then, download installation file for XAMPP.
write "wget http://www.apachefriends.org/download.php?xampp-linux-1.6.8a.tar.gz" and press Enter, installation file will be stored in current file directory.

After the download is complete, install XAMPP using the command: tar xvfz xampp-linux-1.6.8a.tar.gz -C /opt

If you want to start XAMPP at the start of the machine Command the following commands:

lvl=`egrep :initdefault: /etc/inittab|cut -d: -f2`

cd /etc/rc.d/rc${lvl}.d

ln -s /opt/lampp/lampp S99lampp

ln -s /opt/lampp/lampp K01lampp


Starting, Restarting or Stopping XAMPP Server:

First go to root directory: cd /

Then for starting XAMPP server: opt/lampp/lampp start

for re-starting XAMPP server: opt/lampp/lampp restart

for starting XAMPP server: opt/lampp/lampp stop

Friday, December 2, 2011

How to upload a file to ftp directory using PHP

For some projects, we need to upload a file into another ftp server. In this post we will show a simple procedure and description about uploading a file to a ftp using PHP.

Prerequisites


You should have the ftp locations and credentials.

Step 1:


Start PHP script with tag ()


Step 2:


Specify the ftp location in a variable. Location could be a domain like "ftp.domain.com" or also could be a IP address like "121.233.45.12".


Step 3:


Store user name of ftp server in a variable.


Step 4:


Store password of ftp server in a variable.


Step 5:


Store the destination location of the file you want to upload. If you want to store the file into the root directory of the ftp, then just mention the name of uploaded file only. But if you want to upload it to a specific folder then, mention the full path and filename. For example, we will use the "In" directory to upload the file with name "example.txt". (Remember, if you upload two files with same name, then second one will replace the first file.)


Step 6:


Store the source location in a variable. If you want to upload a file which is located at the directory from where the upload script is located, then mention only the file name. But, if your file is in another directory, then you have to mention the full path with file name. For example, We will upload a file situated in "files/example.txt". "files" is the name of the directory where "example.txt" file is located.


Step 7:


Establish the connection, store the information of the connection in a variable. We will use ftp_connect($server) function. As we stored server location in the variable "$server".


Step 8:


Login into the ftp server and store information into a variable.


Step 9:


This is portion is not obligatory. But, I always use this line to my code for successful ftp file transfer. I suggest you to add this line to your script.


Step 10:


Upload the file now. There are two different format of file to upload. They are "FTP_ASCII" and "FTP_BINARY". If you upload a text file, any of them you can use based on your text format "ASCII" or "UTF". But, if you upload a file like "zip" or other, use "FTP_BINARY" format.


Step 11:


Now upload is complete, close the ftp connection if you don't have any other ftp actions. If you have other tasks with this same ftp server just after the upload of the file, then you should not establish connection again.


Step 12:


End the PHP tag.


This is a simple tutorial of ftp file upload. But, you have to extend codes based on the requirements of your project. Every steps show lines of a single script.

Thursday, December 1, 2011

How to Create a Text File Using PHP

Once, before invention of relational database, file (text) were the only way to save information. Now, it is more easier to develop an Information System using database and database is more suitable than using text file. But, still it is needed to use the file for different purposes. For, example, it is needed for ftp based banking API integration. For some projects programmers need to create rewritable php or xml scripts also, for these purposes, files are used. Now, we are going to see how to create a text file using PHP.

Step 1:


Create a php script file and codes will remain inside php tag.


Step 2:


Specify your text and save it to a variable.
Suppose, you want to save the text: "Let's make a text file using php." Then, store it to a variable.


Step 3:


Create a blank text file with your expected name and extension. For this example, we will create a example.txt file. Syntax of this code is fopen("file/pathname","permission"). If you want to store the text file into your current directory from which the script is running then just give the name of the file. But, if you want to store it to a specific location, then you have to give complete path with the name of the creating file. Suppose, your script is located at "root/scripts/file/", then with only the name of file will bd created with location: "root/scripts/file/example.txt", but if you want to store it to root directory then give path like "../../example.txt". Permissions are usually write/read. If you want to just create the file as read only mode, keep permission "r". Or, if you want to keep it in write mode, then keep "w" or "r+". We will keep it "w" (write permission mode) for writing a text into it. And we are going to store the file into the same directory of the script's location.


Step 4:


Store the text into the file. Require php syntax for this action is fwrite("file variable", "Text/ text variable"). As we have created the file and stored it's information in $file variable and already stored the text into the variable into $text variable, our syntax will be like fwrite($file,$text);


Step 5:


Close the file and end php tax.


This is a simple tutorial of creating a text file. You will need to do extended coding for fulfilling additional requirements of your project. It will be great pleasure of mine, if this tutorial helps you.