How To Install LAMP (Linux, Apache, MySQL, PHP) On Ubuntu 11.04/11.10/12.04
How To Install LAMP (Linux, Apache, MySQL, PHP) On Ubuntu 11.04/11.10/12.04Do you like this story?
http://4.bp.blogspot.com/-pB2LLIyLclg/ToHLlS-nnPI/AAAAAAAAA_M/Ru3eaXwqi7U/s200/lamp.jpg Ifyou develop web applications and scripts, it will be nice testing them locally in your own computer before launching them online. This will require the installation of a webserver on your computer.
LAMP (Linux,Apache, MySQL, PHP) is one of the easiest and perfect environment where you can test all your PHP codes. In this tutorial, we will help you install the LAMP webserver on Ubuntu 12.04/11.10; can also be installed on older distributions of Ubuntu (11.04/10.10/10.04).
LAMPInstallation
The LAMP webserver can be installed easily with this command (the caret (^)is required, don't exclude it):
sudoapt-get install lamp-server^
During the installation, you will be asked to enter a new root password for the MySQL database, submit it and press Enter:http://1.bp.blogspot.com/-o0PvziM5j1k/ToHHnzbKonI/AAAAAAAAA-s/Sm79uHHLwrc/s400/MySQL-Password.pngYou will be prompted to enter the password again for confirmation. Wait now until the installation is complete. You have now installed the LAMP webserver on Ubuntu 11.04/11.10. Let's now go to the next step.
TestingApache
Launch your web browser (Firefox, Google Chrome, etc.) and open one of these addresses:
http://localhost/
or
http://127.0.0.1/
If you get this page, then Apache isstarted:http://1.bp.blogspot.com/-UIQ-jqLVw80/ToHH5qVcYjI/AAAAAAAAA-w/aQDWY1sz5cQ/s400/Apache-it-works.pngOtherwise try to restart Apache with this command:
sudo/etc/init.d/apache2 restart
Then give it another try.
TestingPHP
Let's now test PHP. You need to create an empty PHP file in /var/wwwandinsert this snippet of code into it:
<?phpphpinfo(); ?>
You can easily do it with these two commands via the terminal:
echo"<?php phpinfo(); ?>" | sudo tee /var/www/test.php
sudo /etc/init.d/apache2 restart
Then open this address:
http://localhost/test.php
You should see a page like this:http://4.bp.blogspot.com/-kzofWMMAbFI/ToHIackahRI/AAAAAAAAA-0/5pFWrQmUaqY/s320/test-php.pngConfiguringMySQL
Since you are using the LAMP webserver locally, your MySQL database must uses the same IP address of your localhost which is: 127.0.0.1.Via the Terminal, run this command to verify it:
cat/etc/hosts | grep localhost
Here is the correct output you must get:
~$cat /etc/hosts | grep localhost
127.0.0.1 localhost
::1 ip6-localhost ip6-loopback
Also verify that the bind address is set correctly by running this command:
cat/etc/mysql/my.cnf | grep bind-address
You should get this output:
~$cat /etc/mysql/my.cnf | grep bind-address
bind-address = 127.0.0.1
If you get a different IP address, then edit the my.cnf filewith this command:
sudogedit /etc/mysql/my.cnf
Search for the line containing "bind-address"and correct its address by replacing it with 127.0.0.1.
phpMyAdminInstallation
If you want an easy GUI for managing your MySQL databases, you can installphpMyAdmin withthis command:
sudoapt-get install libapache2-mod-auth-mysql phpmyadmin
During the installation you will be asked to select a web server that will be configured automatically to run phpMyAdmin. Select apache2 usingyour spacebar and press Enter:http://2.bp.blogspot.com/-yIRRmb_cnYk/ToHJZC4yPaI/AAAAAAAAA-4/mXIrlwsao68/s400/select-apache2-lamp.pngYou will be asked next to configure a database for phpmyadmin with dbconfig-common,select Yes andpress Enter:http://4.bp.blogspot.com/-lVlQzOF9H-0/ToHJqPJbpII/AAAAAAAAA-8/PG5GvHXDND0/s400/phpmyadmin-dbconfig-common.pngIn the next screen, enter the MySQL password you have submitted before and press Enter:http://2.bp.blogspot.com/-Gc1liTcUOdQ/ToHJz-21NUI/AAAAAAAAA_A/pBXGacagLfw/s400/mysql-password-phpmyadmin.pngCongratulation! phpMyAdmin is now installed in your system. To test it, open simply this address via your web browser:
http://localhost/phpmyadmin/
Login to phpMyAdmin using root asusername and the password you created earlier:http://1.bp.blogspot.com/-o_YVZ3pyYzY/ToHKNtQJnBI/AAAAAAAAA_E/461nxbmJmBc/s400/phpmyadmin+%25281%2529.pnghttp://3.bp.blogspot.com/-elNSumC6RK4/ToHKOYw3F3I/AAAAAAAAA_I/wwHuttEKEs0/s400/phpmyadmin+%25282%2529.pngYou have now successfully installed LAMP on your system. All your projects and files must be placed in /var/www sothat you can run them.
RemovingLAMP & phpMyAdmin
To uninstall the LAMP web server and phpMyAdmin, open the terminal and run this command:
forpkg in `dpkg -l *apache* *mysql* phpmyadmin | grep ^ii | awk '{ print $2 }'`; do sudo apt-get -y purge --auto-remove $pkg; done;
That's it!
页:
[1]