Installing LAMP server could be little bit tricky and if it will not work for you for the first time it will become harder for the next time so please read and do the command step by step.I will not go to much details but I will try to make it ready for you.
First of all if you have just installed Ubuntu ,please do the following:
sudo su
apt-get update
apt-get upgrade
This may over 30 minute according to your internet speed.
Next you have to install PHP5
apt-get install php5
If you like to run php5 code from terminal,Please do:
apt-get install php5-cli
To check if it is working fine or not we must test before go farther.
Let's type
pico phpinfo.php
This will let you type in the terminal.Write the following :
Now Press Ctrl+ o.It will write the data so press ctrl + x to exit.Now type:
php phpinfo.php
It will give you lots of info about the installed php information.If you get that you are with me.
Installing MySQL5
First you have to do the following:
apt-get 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:
New password for the MySQL "root"
Repeat password for the MySQL "root"
What I recommend here is please open a new document and try to copy paste all the command for future reference.
By default MySQl can be run on terminal so you don't need extra lib for that.Let's check MySQL working or not.
sudo netstat -tap | grep mysql
When you run this command, you should see the following line or something similar:
tcp 0 0 localhost.localdomain:mysql *:* LISTEN -
If the server is not running correctly, you can type the following command to start it:
sudo /etc/init.d/mysql restart
Now run to login to your database:
mysql -h localhost -u root -proot
Caution:There is no space in between -proot where root is the password.
So I guess everything is running well.
Installing apache2
Apache2 is available as an Ubuntu package, therefore we can install it like this:
apt-get install apache2
Now if you type your local ip address which is like 192.168.x.x, you may see the image below:
or The following Error in the terminal:
"Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName"
Don't panic ,you are not lost.Please do the following:
pico /etc/apache2/httpd.conf
It will show no letter on the file.Write the following:
ServerName localhost
Now press ctrl +o and exit.If have to restart apache2 by typing :
sudo /etc/init.d/apache2 restart
Now if you type localhost in the browser the image below will come up and will say it's working!
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.
We need to install the apache php5 module so that they may work together.
apt-get install libapache2-mod-php5
/etc/init.d/apache2 restart
The document root of the default web site is /var/www.Please make phpinfo.php the same way we made before and save it.Then in your browser type:
localhost/phpinfo.php
It will show the info() of php5 like this where you can still see MySQL is missing:
To support php5 to work with some useful platform please type:
apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
Now restart the apache and if you run phpinfo.php again you will see MySQL support is there.So you are done.
Recommendation:
It is always a good idea to install phpMyAdmin with LAMP to Manage your Database.Please install it by the following command:
apt-get install phpmyadmin
You will see the something like:
1.Web server to reconfigure automatically: apache2
2.There will b ea screen here just press ok.
3.Configure database for phpmyadmin with dbconfig-common? No
On the browser type :localhost/phpmyadmin
Login using username: root
password: root
Hope this information will help you.Please leave comment or help me to fix typos.