This article will describe installation of Apache,MySQL and PHP on a Ubuntu host. This is the most simple and straight forward way to install. If you intent to use the host as just a server and not for everyday desktop/laptop use, then its better install Ubuntu server edition of LTS (Long Term Support), which would be 12.04 as of this writing. Though one can use Tasksel to install the lamp-server, We prefer to install each package at a time. This way we can only install what the server will be used for.
Installation on Ubuntu can be done in three ways:
- from Ubuntu repositories using apt-get, aptitude or Synaptic package managers.
- from source file; compiling and installing them individually. (the hardcore method).
- from the binary packages available at the respective sites.
Installation of Apache :
The Apache2 web server is available in Ubuntu repository as “apache2” package.
- Open a terminal window, and use the following command to install Apache2 :
> sudo apt-get install apache2
2. To check whether the Apache2 is stored:
go to “/etc” and check for apache2 folder. The folder should contain main configuration file i.e., “apache2.conf”.
3. After making any required changes or after installation, we should restart Apache2 service. this can be done by executing the command:
> sudo /etc/init.d/apache2 restart
4. Create a new text editor file such as "sudo nano " or "gksudo gedit"
>sudo nano /etc/apache2/conf.d/fqdn
or
>gksu "gedit /etc/apache2/conf.d/fqdn"
Installation of php5 :
PHP5 is a general-purpose server-side scripting language originally designed for Web development to produce dynamic Web pages.
1. Open a terminal window, and use the following command to install php5:
> sudo apt-get install php5
2. If you are running PHP you will also need to install the php module for apache2 :
> sudo apt-get install libapache2-mod-php5
3. To check whether the PHP5 is stored:
go to “/etc” and check for php5 folder . The folder should contain configuration folder i.e., “conf.d”.In this folder there will be all .ini files.
Checking PHP 5 installation :
1. Create a new text editor file such as "sudo nano " or "gksudo gedit"
> gksudo "gedit /var/www/testphp.php" 2. Write some php code to test php5 or use the following simple codes to test php5. (1) <?php print_r (phpinfo()); ?> (2) <?php echo "Hello, world!"; ?> 3. Run in the browser as “//http://localhost/testphp.php " If you use the 1st test code : You will see the complete information of PHP5 i.e., php version, configuration, apache environment ,......... so on. If you use the 2nd test code : You will see Hello, world! The file “testphp.php” is stored in the /var/www directory. 4. To run PHP5 scripts from command line you should install php5-cli package. To install php5-cli you have to enter the following command in the terminal prompt: >sudo apt-get install php5-cli 5. You can also execute PHP5 scripts without installing PHP5 Apache module. To accomplish this, you should install php5-cgi package. You can run the following command in a terminal prompt to install php5-cgi package: >sudo apt-get install php5-cgi
Installing MySQL 5 Server on Ubuntu is a quick and easy process:
MySQL is a widely spread SQL database management system mainly used on LAMP (Linux/Apache/MySQL/PHP) projects.
1. Open a terminal window, and use the following command to install Mysql5 :
> sudo apt-get install mysql-server
2. If you are running PHP you will also need to install the php module for mysql 5:
> sudo apt-get install php5-mysql
3. If you have already set a password for the mysql root while installing, then you will need to use:
> mysql -u root -p
Enter Password:
How-To create a MySQL database and set privileges to a user :
In order to be able to use a database, we need to create: a new database, give access permission to the database server to a database user and finally grant all right to that specific database to the user.
1. Create a mysql database :
Syntax :
mysql> CREATE DATABASE <databasename>;
Example:
mysql>create database guest;
Query OK, 1 row affected (0.00 sec)
(The above command creates the database called “guest”)
2. After the database is created, we must select it to continue with our database building.
mysql> use guest;
Database changed
mysql>3. Granting all privileges to new user :
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yourusername'@'localhost'
IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;4. Granting fewer privileges to new user :
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON database1.* TO
'yourusername'@'localhost' IDENTIFIED BY 'yourpassword';
Exit from MySQL :
mysql> \q
(or)
mysql> exit
Important Links:
1) Ubuntu LTS: http://www.ubuntu.com/
2) Apache Project: http://www.apache.org/
3) MySQL: http://www.mysql.com/
4) PHP5: http://www.php.net/
5) LAMP Installation on Ubuntu: https://help.ubuntu.com/community/ApacheMySQLPHP
No comments:
Post a Comment