onsdag 1 augusti 2012

Installing LAMP (Linux, Apache, MySQL and PHP) On Linux Mint

Through this tutorial, you'll learn how to Install Apache, MySQL and PHP.If you're a webpage designer or developer and use PHP, mySQL and Apache, you'll be needing these applications to be installed. When I istalled Mint, I was looking for a way to install LAMP and found a tutorial on a website by somebody named "Cargoship". That tutorial was for ubuntu. But I installed it on my Linux mint, and it is working.


 

In this guide I will show you how to install a LAMP system. LAMP stands for Linux, Apache, MySQL, PHP. The guide is intended to help those who have very little knowlegde of using Linux.
We will not cover how to install Linux the L of LAMP, because Linux Mint is already installed in your computer.

Install Apache

To start off we will install Apache.
1. Open up the Terminal (Applications > Accessories > Terminal).
2. Copy/Paste or type the following line of code into Terminal and then press enter:
sudo apt-get install apache2
3. The Terminal will then ask you for you're password, type it and then press enter.

Testing Apache

To make sure everything installed correctly we will now test Apache to ensure it is working properly.
1. Open up any web browser and then enter the following into the web address:
http://localhost/
You should see a folder entitled apache2-default/. Open it and you will see a message saying "It works!" , congrats to you! or something like that!

Install PHP

In this part we will install PHP 5.
Step 1. Again open up the Terminal (Applications > Accessories > Terminal).
Step 2. Copy/Paste or type the following line into Terminal and press enter:
sudo apt-get install php5 libapache2-mod-php5
Step 3. In order for PHP to work and be compatible with Apache we must restart Apache. Type the following code in Terminal to do this:
sudo /etc/init.d/apache2 restart

Test PHP

To ensure there are no issues with PHP let's give it a quick test run.
Step 1. In the terminal copy/paste or type the following line:
sudo gedit /var/www/testphp.php
This will open up a file called testphp.php.
Step 2. Copy/Paste this line into the phptest file:
<?php phpinfo(); ?>
Step 3. Save and close the file.
Step 4. Now open you're web browser and type the following into the web address:
http://localhost/testphp.php
(It will show you the page that has all information about your php. If you have prior experience of installing php in some other OS, you must have seen this page.)
Congrats you have now installed both Apache and PHP!

Install MySQL

To finish this guide up we will install MySQL.
Step 1. Once again open up the amazing Terminal and then copy/paste or type this line:
sudo apt-get install mysql-server
Step 2 (optional). In order for other computers on your network to view the server you have created, you must first edit the "Bind Address". Begin by opening up Terminal to edit the my.cnf file.
gksudo gedit /etc/mysql/my.cnf
Change the line
bind-address = 127.0.0.1
And change the 127.0.0.1 to your IP address.
(In Linux Mint 11, terminal itself asked to the set password, But if it doesn't follow the step 3.)
Step 3. This is where things may start to get tricky. Begin by typing the following into Terminal:
mysql -u root
Following that copy/paste or type this line:
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');
(Make sure to change yourpassword to a password of your choice.)
Step 4. We are now going to install a program called phpMyAdmin which is an easy tool to edit your databases. Copy/paste or type the following line into Terminal:
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
After that is installed our next task is to get PHP to work with MySQL. To do this we will need to open a file entitled php.ini. To open it type the following:
gksudo gedit /etc/php5/apache2/php.ini
Now we are going to have to uncomment the following line by taking out the semicolon (;).
Change this line:
;extension=mysql.so
To look like this:
extension=mysql.so
Now just restart Apache and you are all set! 
sudo /etc/init.d/apache2 restart

If you get a 404 error upon visiting http://localhost/phpmyadmin: You will need to configure apache2.conf to work with Phpmyadmin.
sudo gedit /etc/apache2/apache2.conf
Include the following line at the bottom of the file, save and quit.
Include /etc/phpmyadmin/apache.conf

Then just restart Apache
sudo /etc/init.d/apache2 restart

 


Now make wonderful website and have fun!wink
Terminal scares the newbies, but here, you'll see how magical terminal or comand promt (whatever you call it) is.
And as Linux is very secure OS, it'll ask you the password again and again, on every administrative command. You'll have to type in your password many times, whenever terminal asks for it.

The End


Tags: terminal, gedit, browser (firefox).
Created: 1 year ago.
Last edited: 4 months ago.
Reviewed: 11 months ago by oscar799.
Read 2013 times.

Comments
1 month ago

kyousanzo
thanks for info :D  
1 month ago

bobbilob
I tried to a LAMP stack on Ubuntu with repeated frustration. Tried Mint and followed your tutorial with success!
Linuxmint 13 Maya comes with pluma rather than gedit, so a substitution was needed. Substitution also works for bluefish (my favourite) but generates some error messages.
 
1 month ago

Hiuhu
Oh tnanx it worked  
1 month ago

mysoomro
Where are you saving those .php files??
Make sure to save them in the Root > var > www ...
 
1 month ago

Hiuhu
I followed those instructions & did exactly what you said but now when I try a file with a .php extension it, the browser downloads it instead of loading it what could be the problem ? (thnx)  
2 months ago

mysoomro
You're welcome!!  
3 months ago

htutt
Thanks, very helpful one.  
3 months ago

mysoomro
Sorry for late reply. I couldn't sign in for sometime.
@Harri-P: You're most welcome! :-)
@sapistic: I guess stleon gave you a good help. And for for uploading the files to your website you need to use an ftp(file transfer protocol) client. Use filezilla for it. You can install it with following command in your terminal


sudo apt-get install filezilla


or you can download it from this link:
http://community.linuxmint.com/software/view/filezilla
just click on install. :-)
@stleon: thanks buddy! :-)
 
3 months ago

sapistic
Thanks  
3 months ago

stleon
/var/www by root. or in your home directory(http://community.linuxmint.com/tutorial/view/853)  
3 months ago

sapistic
So I got all this, but now I want to make a website. I have a basic knowledge of web languages, including PHP, but once I have my files, where do I save them so that Apache and PHP have access to them?  
3 months ago

Harri-P
Thank you so much for this! Was brilliant explanation and really clear. I remember trying to do it before and was not looking forward to doing it again but i had done it within 20mins with this! thanks  
3 months ago

mysoomro
you're most welcome stleon...  
3 months ago

stleon
Thank you very much for the wonderful tutorial.  
4 months ago

mysoomro
@gdawn: check these out and see if they're helpful.


http://www.webhostingtalk.com/showthread.php?t=875255


MySQL: Error 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: NO):

 
4 months ago

gdawg
While attempting to install mysql I get the following error:
jane@gdawg-Satellite-C675 ~ $ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

I also tried 'sudo mysql -u root' but got same result. Any help will be appreciated.
 
5 months ago

mysoomro
@cahyadwiguna: Check this tutorial. I think you'll find help in it.
http://community.linuxmint.com/tutorial/view/244
 
5 months ago

mysoomro
@minx, Did you changed you httpd-vhosts.conf file?
if you didn't, you need to specify your virtual hosts there, something like following
##
##ServerAdmin postmaster@yourvirtualhost.localhost
##DocumentRoot "/var/www/yourvirtualhost"
##ServerName yourvirtualhost.localhost
##ServerAlias www.yourvirtualhost.localhost
##ErrorLog "logs/yourvirtualhost.localhost-error.log"
##CustomLog "logs/yourvirtualhost.localhost-access.log" combined
##

You can find location of httpd-vhosts.conf file from httd.conf it is normally in apache/conf/extra.
 
5 months ago

minx
Hello,
How to use virtual hosts in Apache? I followed a tutorial of ubuntu and i have activated vhost_alias module but it does not work.
 
6 months ago

nicolx
I think is important fix this on apache restart:
Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
Is just a warning but i hate see them! :P
To solve it, open /etc/apache2/site-avaiable/default and att at top of file ServerName localhost.
If you like it add this tips in this article!
 
6 months ago

cahyadwiguna
how to make virtual directory or /var/www in home?
how to make change permission?
 
6 months ago

slotzero
Great write up - thanks!  
6 months ago

mysoomro
Hey mk_hayes and the64u.. I'll look into other question and comments later on. But mk_hayes you're right for

<?php phpinfo(); ?>
not
<!--?php phpinfo(); ?-->

But I noticed this error long ago and corrected it twice.. If you look at the older comments you'll find out.. But I don't know why it's changing again and again. I think some other codes are messing up with the codes in this tutorial..

Sorry for inconvenience.
 
6 months ago

mk_hayes
Thanks for this tutorial as it's a great start but it needs a few additions.

Yeah, Test PHP instructions are still, or perhaps again screwy.

sudo gedit /var/www/testphp.php opens up a file called testphp.php, not phptest.php as you have written. And the file needs to contain this:

<?php phpinfo(); ?>

not this:

<!--?php phpinfo(); ?-->

And for those looking for ;extension=mysql.so in php.ini
search for this without the ; as it is spaced well apart from the rest and you'll be able to find and uncomment it. (Which is what removing the semicolon does.)

I needed manuka's comment to get phpmyadmin to work. Also, while it may seem obvious, phpmyadmin login is root plus the password created during the mysql install.
 
6 months ago

the64u
hi,

i work on LAMP last 3 Days.
I m working Linux Mint Katya 32bit
i also tries Mint community, ther Mr Collin helped me..

I want create DB for Drupal

But face probelem in log in of localhots/phpmyadmin
error : #1045 Cannot log in to the MySQL server

when i found i completely remove the mysql-server, PHP5,Apache2
and then follow the instruction given by u.
Start was ok,but the commend does not show any thing
http://localhost/testphp.php
After that there is no content for ;extension=mysql.so

i still finding another solution..


Help me to sort out..




 
6 months ago

QianQinD
Thanks for the very helpful article:)  
9 months ago

mysoomro
you're most welcome. :-)  
9 months ago

zaenal1234
Thank's for this tutorial...& very useful&helpful;.  
9 months ago

zibams
thanks so much bro this is really awesome  
10 months ago

mysoomro
Dear Bob,
You're most welcome. I'm glad that this tutorial is assisting the Linuxmint community.

Regards,
Younis
 
10 months ago

mysoomro
Dear Mark,

Try using SCP Client for Mac
Transmit http://www.panic.com/transmit/
or filezilla or cyberduck.

If you want to setup FTP following link might help you in this regard.
http://community.linuxmint.com/software/view/vsftpd
https://security.appspot.com/vsftpd.html
http://www.unixmen.com/linux-tutorials/475-insall-vsftpd-in-ubuntu-
 
10 months ago

macgraphic
Thanks mysoomro, that got it all set up nicely on Mint.

Got a question though, how can I set up FTP accounts within Mint/LAMP to allow access (uploading of files {plugins etc for the wordpress sites on there} for use on them - I also have this installed on a local PC, but do my site coding in Dreamweaver on a mac (on same local network).

Thank again. Mark
 
10 months ago

guruwannabe
Hi,
Thanks a lot.
Just managed to install Apache, MySQL and PHP following your tutorial.
Regards,
Bob
 
11 months ago

manuka
This is a step a lot of LAMP tuts miss, if you are getting a 404 error after finishing all the install steps for http://localhost/phpmyadmin then do the following:

Type the following command to open up your apache2.conf file:
gksudo gedit /etc/apache2/apache2.conf

Add the following line of code inside apache2.conf:
Include /etc/phpmyadmin/apache.conf

Now restart Apache:
sudo /etc/init.d/apache2 restart

Done. I can't claim credit for this and is documented on a few LAMP installs round the place
 
1 year ago

ilucmaster
How to install pear-php, i bought a bock named Beginning PHP 5 and MySQL E-Commerce  
1 year ago

prativasic
Thanks for this wonderful tutorial. Although I use Xampp for it. But for my 64bit PC, I think it's the best way.
And dear Gurman, you can try installing Xampp for Linux which is a package containing the same and requires less command line.
 
1 year ago

mysoomro
Dear Gurman! try using these terminal commands you'll see if it's more complex or really fast, easy and convenient. With just one command, it'll locate the site of the application on web, download it for you, and Install it.. All in one go.. What can me more easy and convenient than this.. And I don't agree with you.. Web page developers and designers do need to code a lot.. May be only graphical part doesn't need coding but all other stuff needs a lot of code. PHP, MySQL, CSS, HTML, XHTML, XML, ASP.NET, JavaScript, all are code based technologies.. Though you can use GUI phpmyadmin for MySQL, but all other still need codings.  
1 year ago

Gurman
"If you're a webpage designer or developer..."
If I am a webpage designer or developer I do not want to understand the complexities of command line. I need a modern graphical interface for fast and convenient installation and configuration.The designer should be able to do the design but not programming shell. imho.
 
1 year ago

Elisa
IMO, for silly noobs aka beginners it's better instead Apache, use rather other web server, a nice GUI configured one -> 'Cherokee' :D or another powerful one - 'lighttpd' ;)
Think about that :P
 
1 year ago

Fiffifips
Thanx to trollboy and thanx to mysoomro ! working with terminal is fun . and always don't panik! things go on . I think it did well. and I will go on with this stuff working, thanx. My Homepage is waiting ....  
1 year ago

mysoomro
Got it right. :). I think the websites code was messing up with the code of tutorial.  
1 year ago

mysoomro
Thank you. and yes, you're 100% right. It's <?php phpinfo(); ?>. But I think there is some problem. When I went to edit this, this entire field of code was empty. And I had checked each code before uploading the tutorial.
Let me try it again.
 
1 year ago

trollboy
Good tutorial but Test PHP step 2 is wrong

It should read
<?php phpinfo(); ?>

instead of
<!--?php phpinfo(); ?-->

Inga kommentarer: