Just another WordPress.com site

Archive for the ‘Ubuntu’ Category

Installing Nginx With PHP5 And MySQL Support On Ubuntu 12.04 (precise)

add relevant PPA in the source list.
 edit like

nano /etc/apt/sources.list

as i am using ubuntu 12.04 (precise ) so add following

deb http://ppa.launchpad.net/nginx/development/ubuntu precise main 
deb-src http://ppa.launchpad.net/nginx/development/ubuntu precise main

 First, for good measure lets make sure our server is all up-to-date.

apt-get update

Installing MySQL

Then let’s begin by installing MySQL:

apt-get install mysql-server mysql-client
after entering the above command you will also be prompted for a MySQL “root” user password…

Installing PHP

Next up, lets install PHP5 and a few common extensions (here is a list if you are in need of other extensions):

apt-get install php5-cgi php5-cli php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-pspell php5-recode php5-sqlite php5-tidy php5-xmlrpc php5-xsl

As you may have noticed, we have installed php-cgi, that is because we will be running a FastCGI interface.
here are some articles online which recommend using lighttpd for its FastCGI interface, this is totally not needed. PHP has its own FastCGI interface which works perfectly well (thanks to Tomasz Sterna for a great article on FastCGI with Nginx)

At this point, we will be using a little bit of vim to do a bit of file editing, so here is a quick primer on using vim.
Lets create the following file:  

vim /etc/init.d/php-fastcgi

 This file will have the following content:

#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=500

PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS=”- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND”
RETVAL=0

start() {
      echo -n “Starting PHP FastCGI: “
      start-stop-daemon –quiet –start –background –chuid “$USER” –exec /usr/bin/env — $PHP_CGI_ARGS
      RETVAL=$?
      echo “$PHP_CGI_NAME.”
}
stop() {
      echo -n “Stopping PHP FastCGI: “
      killall -q -w -u $USER $PHP_CGI
      RETVAL=$?
      echo “$PHP_CGI_NAME.”
}

case “$1” in
    start)
      start
  ;;
    stop)
      stop
  ;;
    restart)
      stop
      start
  ;;
    *)
      echo “Usage: php-fastcgi {start|stop|restart}”
      exit 1
  ;;
esac
exit $RETVAL

 As Tomasz Sterna mentions, you will need to fiddle with the PHP_FCGI_CHILDREN and PHP_FCGI_MAX_REQUESTS variables depending on your server’s amount of memory and compute power. I am running a baseline 256 MB / 10 GB Rackspace Cloud Server so I use the following settings which seem to work very well (as seen above):

PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=500

Moving on … after you’ve created and saved the file we will make it executable and then start up the FastCGI service with the following commands:

chmod +x /etc/init.d/php-fastcgi
/etc/init.d/php-fastcgi start

We will want the service to auto start when we reboot our server, so we also do the following:

 update-rc.d php-fastcgi defaults

Installing Nginx

Installing Nginx is easy, use the following commands to install and then start up the Nginx server.

apt-get install nginx
/etc/init.d/nginx start

After installing Nginx, it will be automatically configured to start when we reboot our server (unlike the PHP FastCGI service we had to setup), so we are all set.

Testing Nginx and PHP

At this point we can see that Nginx is working by typing the server’s IP address into a web browser (http://%5BIP_ADDRESS%5D/). You should get a “Welcome to nginx!” message.
Now lets test PHP, we will create a generic phpinfo.php file with the following:

echo "" > /var/www/nginx-default/phpinfo.php

/var/www/nginx-default/ is the Nginx server default root directory…
If you use your browser to go to  

http://%5BIP_ADDRESS%5D/phpinfo.php 

,you will notice that it doesn’t work … before this will work, we have to enable FastCGI in the Nginx config file. Open up the following file:

vim /etc/nginx/sites-available/default

in the server {

change #root /usr/share/nginx/www; 

to root /var/www;
 

 
Find the following lines (scroll to line 47):
       

#location ~ \.php$ {
    #fastcgi_pass   127.0.0.1:9000;
    #fastcgi_index  index.php;
    #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #includefastcgi_params;
#}

 and change them to (removing the # character from each line, changing line 50 and adding a space between include and fastcgi_params on line 51):

location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /var/www/nginx-default/$fastcgi_script_name;
    include fastcgi_params;
}

Now lets restart Nginx so our config changes will take effect:

/etc/init.d/nginx restart

 Now use your web browser to go to http://%5BIP_ADDRESS%5D/phpinfo.php, you should see a PHP info page.

Installing phpMyAdmin + phpMyAdmin Vhost Configuration 

apt-get install phpmyadmin

You will see the following questions:
Web server to reconfigure automatically: <– select none (because only apache2 and lighttpd are available as options)
Configure database for phpmyadmin with dbconfig-common? <– No
You can now find phpMyAdmin in the /usr/share/phpmyadmin/ directory. Now we must configure our vhost so that nginx can find phpMyAdmin in that directory.
Open /etc/nginx/sites-available/

nano /etc/nginx/sites-available/

 and add the following part to the server {} container:

server {
[...]
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
[...]
}

Reload nginx:

/etc/init.d/nginx reload

That’s it! You can now go to

http://127.0.0.1/phpmyadmin/
or http://localhost/phpmyadmin

 some useful links for further help regarding LEMP (linux,enginx,mysql,php)

  1. http://suckup.de/linux/ubuntu/nginx-php5-fpm-auf-debianubuntu/
  2. http://www.rackspace.com/knowledge_center/article/installing-nginx-and-php-fpm-running-on-unix-file-sockets
  3. http://www.howtoforge.com/running-phpmyadmin-on-nginx-lemp-on-debian-squeeze-ubuntu-11.04

Advertisements

linux file permission simplest rule of thumb

Chmod 777 –R /var/www/html/webdir
Permission level
1.       r (read)       =  4
2.       w (write)     =  2
3.       x (execute)  =  1

For example : 

chmod 753 abc.txt thus means
assign (4+2+1)(4+1)(2+1) to abc.txt

=>
assign (rwx)(rx)(wx) to abc.txt
assign (owner)(group)(other) to abc.txt

Another example

chmod 572 dump.txt thus means
assign (4+1)(4+2+1)(2) to 
dump .txt
=>
assign (rw)(rwx)(w) to  dump .txt

linux commands for every web developer/Software engineer

scp – Linux command line tool to copy files over ssh

scp [[user@]from-host:]source-file [[user@]to-host:][destination-file]

scp  abc.TXT root@10.215.3.150:/home/user/xyz.TXT


from-host
Is the name or IP of the host where the source file is, this can be omitted if the from-host is the host where you are actually issuing the command
user
Is the user which have the right to access the file and directory that is supposed to be copied in the cas of the from-host and the user who has the rights to write in the to-host
source-file
Is the file or files that are going to be copied to the destination host, it can be a directory but in that case you need to specify the -r option to copy the contents of the directory
destination-file
Is the name that the copied file is going to take in the to-host, if none is given all copied files are going to maintain its names

Copy Multiple fies

scp root@192.168.168.052:/home/ftp-124/5656/$dir/\{abc.txt,def.txt,ghi.txt\} root@192.168.168.053:/home/shahzeb

Restart MySql Ubuntu

To restart Apache2 on Ubuntu, we enter the following command in a terminal such as bash:

restart mysql

service mysql start


Restart Apache2 Ubuntu

To restart Apache2 on Ubuntu, we enter the following command in a terminal such as bash:

/etc/init.d/apache2 restart

Of course, you most likely will need to be the superuser to do that so you might need to enter the following command and then your password when requested:

sudo /etc/init.d/apache2 restart

Pointer

use pointer to acees the variable within a variable directly like

 foo=bar
 name=foo
 echo ${!name}
Result : bar

grep command: 

grep command usually interpet “|” as “AND” sign but you can use the same “|” for “OR” sign

for example

zgrep “^2012-06-05” /var/path/to/file/abc12346-12-06* | grep -E ‘3003300356|3003301763|3008203898|3008202542|3008226266|3003404159’

zgrep = grep for gzipped files

some of the basic linux command

There are many common Linux commands that will be helpful to you, if you ever even use the command line interface in Linux. Most average users just use the graphical user interface instead which usually has many tools and front-ends to Linux common commands. This Linux tutorial on command commands will help even the average user in case X server crashes, fails, is not properly configured, etc. So continue reading for some of the more common Linux bash commands.

Some of the more common Linux shell commands are listed below for more information on each command you can always run man [command] and this will bring up the manpage for that command, you can also click on the commands listed for some common examples and syntax.
First before I list them any syntax in [] will need some kind of input from you normally, for example:
man [command] you will want to actually replace [command] with the shell command you want to read the man page for: man ls will give you the man page for the Linux shell command ls.

  • linux ls command – is used to list files on the filesystem.
  • file – command that will check the filetype, this will output to you what the file type is no matter what the extension is.
  • mkdir command – used to make directories on the filesystem.
  • cd – is used for changing into a different directory in the Linux shell
  • cp – is the Linux copy command, this shell command is used to copy files|directories from one location on the filesystem to another.
  • mv – the Linux terminal command to move files|directories. Like the cp command, but deletes the original source.
  • rm – shell command in Linux to remove files|directories.
  • Linux cat command- this command is used to print|view the contents of a file to the screen|terminal.
  • grep – command used to search|find contents of a file and print|view on your terminal|screen.
  • Linux more and less – commands that will allow you to read output of files, unlike cat that will output the entire file at once, even if it is too large for your terminal more and less will output only as many lines as the shell you are in can output, and allow you to scroll through the file contents.
  • chown – Linux command to change ownership of a file|directory.
  • Linux chmod – command that allows you to change mode of user access|permissions, basically set read, write, and execute permissions.
  • Linux ps – lists the current running processes on your Linux system
  • Linux kill and killall commands – used to kill|terminate running processes

Unpacking or uncompressing gz files under Linux and UNIX systems

Using gunzip command:

$ gunzip file.gz
$ ls file

Using gzip -d command:

$ gzip -d file.gz
$ ls file

If file extension is tar.gz, type the command:

$ tar -zxvf file.tar.gz

Please note that gunzip can currently decompress files created by gzip, zip, compress, compress -H or pack programs.

Installing Apache2 With PHP5 And MySQL On Ubuntu 10.10 (LAMP)

LAMP is short for Linux, Apache, MySQL, PHP. This tutorial shows how you can install an Apache2 webserver on an Ubuntu 10.10 server with PHP5 support (mod_php) and MySQL support.

1 Preliminary Note

In this tutorial I use the hostname server1.example.com with the IP address 192.168.0.100. These settings might differ for you, so you have to replace them where appropriate.I’m running all the steps in this tutorial with root privileges, so make sure you’re logged in as root:

sudo su

2 Installing MySQL 5

First we install MySQL 5 like this:

aptitude install mysql-server mysql-client

You will be asked to provide a password for the MySQL root user – this password is valid for the user root@localhost as well as root@server1.example.com, so we don’t have to specify a MySQL root password manually later on:

New password for the MySQL “root” user: <– yourrootsqlpassword
Repeat password for the MySQL “root” user: <– yourrootsqlpassword

3 Installing Apache2

Apache2 is available as an Ubuntu package, therefore we can install it like this:

aptitude install apache2

Now direct your browser to http://192.168.0.100, and you should see the Apache2 placeholder page (It works!):
Apache’s default document root is /var/www on Ubuntu, and the configuration file is /etc/apache2/apache2.conf. Additional configurations are stored in subdirectories of the /etc/apache2 directory such as /etc/apache2/mods-enabled (for Apache modules), /etc/apache2/sites-enabled (for virtual hosts), and /etc/apache2/conf.d.

4 Installing PHP5

We can install PHP5 and the Apache PHP5 module as follows:

aptitude install php5 libapache2-mod-php5

We must restart Apache afterwards:

/etc/init.d/apache2 restart

5 Testing PHP5 / Getting Details About Your PHP5 Installation

The document root of the default web site is /var/www. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

vi /var/www/info.php
<?php phpinfo(); ?>

Now we call that file in a browser (e.g. http://192.168.0.100/info.php):
As you see, PHP5 is working, and it’s working through the Apache 2.0 Handler, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don’t have MySQL support in PHP5 yet.

6 Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php5-mysql package. It’s a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:

aptitude search php5

Pick the ones you need and install them like this:

aptitude install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json

Now restart Apache2:

/etc/init.d/apache2 restart

Now reload http://192.168.0.100/info.php in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module:

7 phpMyAdmin

phpMyAdmin is a web interface through which you can manage your MySQL databases. It’s a good idea to install it:

aptitude install phpmyadmin

You will see the following questions:
Web server to reconfigure automatically: <– apache2
Configure database for phpmyadmin with dbconfig-common? <– No
Afterwards, you can access phpMyAdmin under http://192.168.0.100/phpmyadmin/:

How To Install Dreamweaver CS3 In Ubuntu Hardy

It would be great if there is a Linux build of the popular Dreamweaver CS3, or that it could be easily installed via WINE. The truth is, none of the above work. There is no Linux version, nor will it work via WINE direct installation. The only way to get it to work is to port it over from a Windows installation.
If you are new to Dreamweaver CS3, it is one of the best, if not, the best web editor software in the market. While there are many open source and free web editors out there, none of them come close to it in term of quality and capability. Although it comes with a hefty price tag of $399, it is well worth the money if you are into serious web developing. As such, if you wish to follow this guide and install Dreamweaver CS3 in your Ubuntu machine, please make sure you have the licensed copy, or proceed to Adobe to make your purchase. Do not attempt to use illegal software.
Initial Installation – WINE
We will need WINE to create a Windows environment for Dreamweaver. If you have already installed WINE, you can skip to the next section.

sudo apt-get install wine
winecfg

The WINE configuration window will pop up. Click OK to close the window. You can now find a .wine folder in your Home directory (if you can’t see it, go to View and check “Show Hidden Files“).
Porting Dreamweaver CS 3 From Windows
Install your Dreamweaver CS 3 in Windows. (For this step, I would advise you to install it on a Windows virtual machine so that you can transfer files between the two OS easily later on.)
Now there are 5 main folders that you need to copy to your Ubuntu machine.

1) Open up File Manager and navigate to C:\Program Files. Copy the whole ‘Adobe‘ folder to Ubuntu /home/username/.wine/drive_c/Program Files folder.
2) Still in the Windows File manager, navigate to C:\Documents and Settings\your-windows-user-name\Application Data (if you can’t find the Application Data folder, go to Tools->Folder Option->View and select ‘show hidden files and folders‘) and copy the whole ‘Adobe‘ folder to Ubuntu /home/username/.wine/drive_c/windows/profiles/All Users/Application Data/
3) In the Windows File manager, go to C:\Program Files\Common Files and copy the whole ‘Adobe‘ folder to Ubuntu /home/username/.wine/drive_c/Program Files/Common Files4) In the Windows file manager, go to C:\WINDOWS\system32 and copy the whole ‘marcomed‘ folder to Ubuntu /home/username/.wine/drive_c/windows/system325) In the Windows file manager, go to C:\WINDOWS and copy the whole ‘WinSxS‘ folder to Ubuntu /home/username/.wine/drive_c/windows

Next, we need to import the Dreamweaver registry to WINE.
In your Windows,

go to Start->Run. Type in ‘regedit‘ and press Enter.

In the window that pop up, on the left pane, navigate to HKEY_LOCAL_MACHINE-> SOFTWARE->Adobe->Dreamweaver. Right click on the ‘Dreamweaver‘ folder and select ‘Export’. Save the file as dreamweaver.reg
Copy this dreamweaver.reg to your Ubuntu home folder.
Now you need to convert the registry file to ASCII format.

sudo apt-get install recode
recode ucs-2..ascii dreamweaver.reg
wine regedit dreamweaver.reg

At this time, you have successfully ported all the necessary files from Windows to Ubuntu. To test your installation:

cd .wine/drive_c/Program\ Files/Adobe/Adobe\ Dreamweaver\ CS3/
wine Dreamweaver.exe

Dreamweaver CS3 should now launch.
Creating entry in Applications menu
To create an entry in your Applications menu, right click on the Applications menu and select ‘Edit Menus’.
Scroll down to the Wine->Programs entry and select New Item. Enter the following
Type: Application
Name: Dreamweaver CS3
Command: wine /home/username/.wine/drive_c/Program\ Files/Adobe/Adobe\ Dreamweaver\ CS3/Dreamweaver.exe
Click Close. You should now see an entry in your Application menu. You can drag the entry to your desktop or to the panel to create a shortcut.

%d bloggers like this: