sâmbătă, 19 septembrie 2009

LAMP Server on Ubuntu/ Debian.

Build Your Own Debian/Ubuntu LAMP Server - Quick & Easy Do it Yourself Installation

· Apache 2 - Linux Web server

· MySQL 5 - MySQL Database Server

· PHP4/5 - PHP Scripting Language

· phpMyAdmin - Web-based database admin software.

Note: Linux + Apache + MySQL + PHP/Perl together commonly known as LAMP Server.

First, let us prepare a system that has a minimum requirement of Debian/Ubuntu version of linux with atleast 256MB of RAM available. Anything less than this minimum ram will cause lot of problems since we are running a server along especially mysql and webmin requires lot of RAM to run properly. Mysql will give you this nasty error "cannot connect to mysql.sock" if you dont have enough memory in your server.

I love debian/ubuntu based linux because of my enormous affinity towards this command apt-get. As a starter knowing this one command, It is so easy to install packages and you dont need to worry about package dependency and configuration. You need to buy a dedicated server or a VPS package if you want to setup your own server. If you want to experiment with the server and installation it is recommended to buy a vps package from various hosts. I prefer vpslink because of their pricing. Believe it or not it is so easy to install and configure your server yourself eventhough you are new are to linux and dedicated/vps hosting.

First download PuTTy if you are accessing your server through SSH. Just enter the IP of your server with root login to access your host. As you probably know, Webmin is a freely available server control panel and we will setup this once we have completed the LAMP server and Mail Server. Webmin makes more easier for us to fine tune our linux box.

Before proceeding to install, update the necessary packages with debian with this command.

apt-get install update

1. Installing Apache + PHP

Apache is one of the most famous web server which runs on most linux based servers. With just few commands you can configure apache to run with PHP 4 or PHP 5.

If you want to install PHP 4, just apt-get

apt-get install apache2 php4 libapache2-mod-php4

To install PHP5, just run the following on linux shell. Note that if you dont specify packages with '4', PHP5 will be automatically installed.

apt-get install apache2 php5 libapache2-mod-php5

Apache configuration file is located at: /etc/apache2/apache2.conf and your web folder is /var/www.

To check whether php is installed and running properly, just create a test.php in your /var/www folder with phpinfo() function exactly as shown below.

nano /var/www/test.php

# test.php

Point your browser to http://ip.address/test.php or http://domain/test.php and this should show all your php configuration and default settings.

You can edit necessary values or setup virtual domains using apache configuration file.

2. Installing MySQL Database Server

Installing mysql database server is always necessary if you are running a database driven ecommerce site. Remember running mysql server to a fair extend requires atleast 256mb of RAM in your server. So unless you are running database driven sites you dont absolutely need mysql. The following commands will install mysql 5 server and mysql 5 client.

apt-get install mysql-server mysql-client php5-mysql

Note: If you have already installed php4, you should make a slight change like this.

apt-get install mysql-server mysql-client php4-mysql

The configuration file of mysql is located at: /etc/mysql/my.cnf

Creating users to use MySQL and Changing Root Password

By default mysql creates user as root and runs with no passport. You might need to change the root password.

To change Root Password

mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('new-password') WHERE user='root';
mysql> FLUSH PRIVILEGES;

You must never use root password, so you might need to create a user to connect to mysql database for a PHP script. Alternatively you can add users to mysql database by using a control panel like webmin or phpMyAdmin to easily create or assign database permission to users. We will install Webmin and phpmyadmin during later once we complete basic installation.

3. PhpMyAdmin Installation

PhpMyAdmin is a nice web based database management and administration software and easy to install and configure under apache. Managing databases with tables couldnt be much simpler by using phpmyadmin.

All you need to do is:

apt-get install phpmyadmin

The phpmyadmin configuration file is located at: /etc/phpmyadmin folder.

To set up under Apache all you need to do is include the following line in /etc/apache2/apache2.conf:

Include /etc/phpmyadmin/apache.conf

Now restart Apache:

/etc/init.d/apache2 restart

Point your browser to: http://domain/phpmyadmin

That's it! MySQL and phpMyAdmin are ready. Log in with your mysql root password and create users to connect to database from your php script.

This tutorial was written and contributed to HowToForge by Scott who currently runs MySQL-Apache-PHP.com. Permission is fully granted to copy/republish this tutorial in any form, provided a source is mentioned with a live link back to the authors site.

VARIANTA 2

Installing LAMP on Debian Etch

It has been awhile since my last post as I have been nursing a sick family and coming up to speed on some PHP and MySQL for a few projects I am currently working on. I wanted to share with you how simple it is to get Apache2, PHP5, MySQL Server 5.x installed on an existing installation of Debian Etch.

# apt-get update
# apt-get install apache2 php5 mysql-server phpmyadmin php5-gd

With the simple exception of phpmyadmin and php5-gd that is all you need to get going!

VARIANTA 3

How to install a Debian LAMP Server

The combination of Linux + Apache + MySQL + PHP setup is known as LAMP

We will be using:

Debian Linux - Operating System

Debian is an opensource operating system, which uses the popular Linux kernel. It is a good choice for servers as it is stable and has an easy to use package manager

Apache - Web server

Apache is one of the most famous web servers and with just few simple commands, you can configure apache to play nicely with PHP.

Note: You put your content /var/www.

MySQL 5 - Database Server


The MySQL database is renownd for its excellent performance, high reliability and ease of use.

PHP5 - Scripting Language

PHP is a common scripting language that is especially suited for Web development and can be easialy embedded into HTML pages and works well with other technogies such as the MySQL database and Apache webserver.

phpMyAdmin - Web-based database administration software.

PhpMyAdmin is an excellent web based database administration tool. Managing databases and tables couldnt any simpler.

Note:

First, lets ensure that the system meets the minimum requirements for Debian and that it has at least 256MB of RAM available. If your machine has less than 256MB ram then it can cause lot of problems and MySQL will give you the error "cannot connect to mysql.sock".

Getting Started:

Debian linux is my favourite for servers as it has the command "apt-get".

This command makes it easy for a beginner to install packages as you dont need to worry about package dependencies or manually creating configuration files.

I will assume that you have already installed debian and have it up and running (very easy). I personally love to use the netinstall cd and install just a base system then use apt-get.

If you wish to access the server remotely through SSH from a windows PC then please download a tool called PuTTY


Install:

Ok, now type (in this order, hit enter at the end of the line) and wait for it to complete. Reboot once all the software is installed

apt-get update

apt-get install apache2 php5 libapache2-mod-php5 mysql-server mysql-client php5-mysql phpmyadmin ssh


Security:

By default the mysql root (superuser) account does not have a password. Set one like this:

mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('new-password') WHERE user='root';
mysql> FLUSH PRIVILEGES;

You are now ready to roll!

Varianta 4

[edit] Introduction

LAMP is essentially a server that runs Linux, Apache, MySQL and Php/Perl and is more commonly known as a LAMP server. This wiki item will provide detailed instructions on setting LAMP up and once completed you will have a LAMP server that runs:

· Apache 2 - Linux Web server

· MySQL 5 - MySQL Database Server

· PHP5 - PHP Scripting Language

· phpMyAdmin - Web-based database admin software.

[edit] Requirements

· A Debian Etch base installation - Installation HOWTO here.

· At least 256MB of RAM installed on your machine.

· An understanding of the "apt-get" command.

[edit] Pre-Installation

Before proceeding to install, update the necessary packages with Debian with this command.

apt-get update

apt-get upgrade

[edit] Installing Apache 2 + PHP5

To install Apache 2 and PHP5, just run the following in a Linux shell.

apt-get install apache2 php5 libapache2-mod-php5

Your Apache 2 configuration file is located at: /etc/apache2/apache2.conf and your web folder is /var/www

Let's check that PHP5 was installed correctly. Run the following command to open up the vim editor and create a new php page called test.php:

vim /var/www/apache2-default/test.php

With this page opened insert the following code into vim:

You can now save the file.

Point your browser to http://example.com/apache2-default/test.php and this should show all your PHP5 configuration and default settings.

[edit] Installing MySQL 5 Database Server

Installing the MySQL database server is necessary if you intend on running a database driven web site. The following commands will install MySQL 5 server and MySQL 5 client.

apt-get install mysql-server mysql-client php5-mysql

The configuration file of MySQL is located at: /etc/mysql/my.cnf

[edit] Creating users to use MySQL and Changing Root Password

By default MySQL creates a user as root and runs with no password which is a high security risk. You will need to change the root password immediately.

To change Root Password:

mysql -u root

mysql> USE mysql;

mysql> UPDATE user SET Password=PASSWORD('new-password') WHERE user='root';

mysql> FLUSH PRIVILEGES;

You must never use your root account and password when running databases. The root account is a privileged account which should only be used for admin procedures. You will need to create a separate user account to connect to your MySQL databases from a PHP script. You can add users to a MySQL database by using a control panel like phpMyAdmin to easily create or assign database permissions for users.

[edit] phpMyAdmin Installation

phpMyAdmin is a nice web based database management and administration software and easy to install and configure under apache. Managing databases with tables couldnt be much simpler by using phpmyadmin.

All you need to do is:

apt-get install phpmyadmin

The phpMyAdmin configuration file is located at: /etc/phpmyadmin

To have access to phpMyAdmin on your website (i.e. http://example.com/phpmyadmin/ ) all you need to do is include the following line in /etc/apache2/apache2.conf:

Include /etc/phpmyadmin/apache.conf

Now restart Apache:

/etc/init.d/apache2 restart

Point your browser to: http://example.com/phpmyadmin/ and you're ready to go.

That's it! MySQL and phpMyAdmin are ready. Log in with your MySQL root account and password and create users to connect to the databases from your PHP script.

[edit] The really quick way of doing this

The above is broken into step by step examples to give you a detailed understanding of what each step does. However, you can install the LAMP server running only two commands. First run:

apt-get update

And then run:

apt-get install apache2 php5 libapache2-mod-php5 mysql-server mysql-client php5-mysql phpmyadmin

That's it. With these two commands you will install everything as described in the wiki HOWTO.

Un comentariu:

  1. Thanks! I am using a debian vps, now I can install those applications to my system. Merry Christmas! :)

    RăspundețiȘtergere