PHP Basics #2 : How to Install Apache, PHP and MySQL
How to get started with PHP...?
Hello everyone in this tutorial I will show you how to make a development environment for PHP. This is one of the topics where most of the beginners have problems when to get to PHP development. You must get one thing clear that we cannot just open a editor and create a new html file and write php codes on it...this technique is not going to work with PHP as you need a localhost or a server PC to run php files and the file you are going to write PHP codes should be a .php file and don't worry this will not effect any of your html codes..
The above paragraph gives you alot of information but now lets get all topics clear.
To Start Developing in PHP :-
- PHP will not work if we write php codes in an HTML file and open in the browser.
- The file in which we will write php codes must be a PHP file ex. index.php and you dont need to worry about the HTML file getting corrupt or anything you HTML is gonna run fine in a php file.
- We need a server to run php files.
Installation Guide For Ubuntu:
About LAMP
LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Since the virtual private server is already running Ubuntu, the linux part is taken care of. Here is how to install the rest.Step One—Install Apache
Apache is a free open source software which runs over 50% of the world’s web servers.
To install apache, open terminal and type in these commands:
sudo apt-get install apache2
That’s it. To check if Apache is installed, direct your browser to your server’s IP address (eg. http://12.34.56.789). The page should display the words “It works!" like this.
How to Find your Server’s IP address
You can run the following command to reveal your server’s IP address.
ifconfig eth0 | grep inet | awk '{ print $2 }'
Step Two—Install MySQL
MySQL is a powerful database management system used for organizing and retrieving data
To install MySQL, open terminal and type in these commands:
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
During the installation, MySQL will ask you to set a root password. If you miss the chance to set the password while the program is installing, it is very easy to set the password later from within the MySQL shell.
Once you have installed MySQL, we should activate it with this command:
sudo mysql_install_db
Finish up by running the MySQL set up script:
sudo /usr/bin/mysql_secure_installation
The prompt will ask you for your current root password.
Type it in.Enter current password for root (enter for none):
OK, successfully used password, moving on...
Then the prompt will ask you if you want to change the root password. Go ahead and give it a password for mysql
Once you're done with that you can finish up by installing PHP.
Step Three—Install PHP
PHP is an open source web scripting language that is widely use to build dynamic webpages.
To install PHP, open terminal and type in this command.
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
After you answer yes to the prompt twice, PHP will install itself.
Congratulations! You now have LAMP stack on your computer!!
Test Your New Personal Server:
Now when you can open your browser and type on the url localhost/ and press enter. If the link opens an webpage saying Apache2 Ubuntu Default Page it means you have successfully Installed Apache Server on your machine ...!
Important Note: The localhost folder is located it /var/www/html/ now can can create a new folder test inside /var/www/html/ and then create a new file inside the test folder and name it index.php open that file with any text editor or your html editor and type the following :
echo "Hello World!!";
?>
(Dont worry I will explain the codes in next tutorial. If you encounter any problem please COMMENT.)