$ sudo apt install php libapache2-mod-php php-mysql After installing PHP, create info.php file in the Apache root document folder. Usually, the apache root document folder will be /var/www/html/ or /var/www/ in most Debian based Linux distributions.
Saturday, February 21, 2015
Would you like tolearn Apache, PHP, or MySQL, but don't want to invest in a webserver?
Would you like avery friendly development environment for creating websites?
If you answered YESto any of these questions, then read on; this blog entry is for you.
In this blog entry,I will be explaining how to install Apache, PHP, and MySQL on yourLinux Mint computer (workstation or laptop), how to set it up, andget you started on the road to using it as a website developmentplatform and learning tool.
![Linux Linux](http://www.hackourlife.com/wp-content/uploads/2010/06/Selection_0021.png)
So, what exactly areApache, PHP, and MySQL?
Here is a veryshort, and very simplified answer to the question.
Apache is a softwarepackage that allows an Internet server to 'serve up' web pages. Whenyou use your web browser on your computer to access a web site, it isan Apache server some where on the Internet that sends the text andimages to your computer.
PHP is a scriptinglanguage that runs on top of Apache. It allows you to add 'logic' toyour web page. If a web page does anything other than just shows textand pictures, chances are good that it's PHP doing the work.
![Mysql Mysql](http://www.hackourlife.com/wp-content/uploads/2011/06/Linux-Mint-Tasksel.jpeg)
MySQL is a databasepackage. If you buy something on-line, looks up a street address,sign up as a new user on a website, or so forth, it's most likelythat this information is being stored in a MySQL database.
These 3 packagescombined, plus Linux, create what is commonly called a LAMP server;Linux, Apache, MySQL, Php. LAMP servers are the heart and sole of theInternet. The vast majority of Internet web sites and services run onsuch servers.
This blog entrydescribes how to install Apache, PHP, and MySQL on your Linux Mintlaptop/workstation. Basically, creating your own private LAMP server.Since it's YOUR server, you are the admin and user, and you can dopretty much what you please with it.
Please note that weare NOT taking anything away from the way your computer works. Youwill still be able to use it to surf the Internet, do email, writedocuments, and anything else that you are currently using yourcomputer for. We will simply be adding some really cool abilities toyour computer.
This blog entry willalso describe how to install a package called Bluefish. For those ofyou who might not have ever heard if it, Bluefish is a very simplytext editor that makes writing html, PHP and Javascript code, veryeasy. It has some very nice functions that makes developing web pagesvery simple and fast, and it's very easy to learn.
In order to do theinstall described in this blog post, you will need a working Internetconnection. After everything has been installed and configured, youcan then use your LAMP server without having to be connected to theInternet. Since both the Server and Client (web browser) will berunning on the same physical hardware, you won't need the Internetconnection to use it.
IMPORTANT: You willalso need a pen and paper to take notes and record passwords. If youdon't have such, this is a good point to stop and get it.
To do the install,open a terminal window (click on 'Menu' at the bottom of the screen,then on 'Terminal'), and enter each of these commands one at atime. You will need to wait for each command to complete beforeentering the next. You will be prompted to create a new password forthe MySQL root account, and the PHP Admin account. Be sure to recordthese on your paper and keep this info in a safe place. This installprocesses should take you about 10 minutes depending on the speed ofyour Internet connection.
< enter yoursystem password when prompted >
sudo apt-get installphp5 libapache2-mod-php5 -y
sudo apt-get installmysql-server -y
sudo apt-get installlibapache2-mod-auth-mysql php5-mysql phpmyadmin -y
sudo apt-get installbluefish -y
echo '<?phpphpinfo(); ?>' > /var/www/html/testphp.php
IMPORTANT:For safety reasons, you should only use the MySQL root account forcreating new databases and users. Never use your root account fordaily tasks, it's just too easy to accidentally do somethingdamaging.
So, our next step isto use the MySQL root account to create a new database called'sandbox', a new user called 'user1', and grant user 'user1' fullrights to database 'sandbox'. After this is done, you can then safelyuse the user1 account to learn and work with MySQL.
Using the sameterminal window you used to install the software, enter this command:
mysql -u root -p
Enter your MySQLroot password when prompted. This is the password you created whenyou installed the MySQL server.
You should now see aprompt that looks like this:
MySQL>
If you see thisprompt, you are successfully logged into your MySQL server as 'root'.
Now, cut and pastthis text into your terminal window. Note that MySQL commands alwaysend with a semi-coluon. The 'GRANT ALL' command shown bellow is onelong command on several lines. It's not until it sees the ';' that itactually does anything.
USE sandbox;
CREATE USER'user1'@'localhost' IDENTIFIED BY 'xxx123';
WITHMAX_QUERIES_PER_HOUR 320
MAX_CONNECTIONS_PER_HOUR 350
SET max_error_count= 65530;
Next, you will wantto set up the password for the user1 account. Enter this command atthe MySQL> prompt, replacing the word 'yourpassword' with thepassword you want for this account. Be sure to also record thispassword on your paper so you won't forget it.
SET PASSWORD FOR'user1'@'localhost' = PASSWORD('yourpassword');
And finally, enterthe word 'EXIT' to sign out of the MySQL root account.
Using your webbrowser on your computer (Chrome, FireFox, Opera, or other) bring upeach of these web pages. Note that these pages are ON YOUR OWNHARDDRIVE, and not on the Internet. Your web browser will see yourcomputer as if it was an Internet web host server, by the name of'localhost'.
If you get a 404error on any of these, something went wrong with the install, and youshould try again.
To test the Bluefisheditor, enter this command into the terminal window. You should seethe contents of the index.html file. To leave Bluefish, just do afile/quit like any other application.
bluefish/var/www/html/index.html
To test MySQL, enterthe following commands in the terminal window.
mysql -u user1 -p
use sandbox;
exit
If you are aWordpress user, or would like to learn Wordpress, now would be a goodtime to install it as well. There is an extremely good article on howto do this at http://community.linuxmint.com/tutorial/view/828.
Step 5. A few thingsyou should know.
You can create newhtml or PHP documents (web pages) and save them into the folder/var/www/html Any files saved into this folder will be visible to your web browseras http:localhostfilename
For example: If you create a file called /var/www/html/aboutme.html you will be able to see it from your web browser as http:localhostaboutme.html
Your web browser will be able to access files in your /var/www/htmlfolder even if your computer does not have an active Internetconnection. So you can use the Bluefish editor to create new html orphp documents, any ware, any time, and test them, regardless if youhave an Internet connection or not.
The Bluefish editor can be used to create or change html or PHPfiles. Just remember to save them into the folder /var/www/html sothat your browser can see them. It's a fairly simple and straightforward editor, and most users will be able to use it right from thestart. But if you feel that you really need to see the documentation,it can be found at:http://bfwiki.tellefsen.net/index.php/Manual_2_ToC
Most Internet web hosting providers (like FatCow, HostGator, andothers) have a function in their file manager that will allow you toupload your html and PHP files from your computer to your webaccount. So after you have your web page looking the way you want iton your computer, you can then move it into 'production' so that thewhole world can see it.
You might want to think about creating a new folder in your homefolder called something like 'notebook', and downloading any manualsand documentation about web page development to that folder. Thatway, you can have all your documentation and notes available even ifyour laptop does not have an Internet connection. A few documents youmight want to consider are in the links at the bottom of this blogentry.
IMPORTATN..IMPORTATN..IMPORTATN:
Always remember to make backup copies of ANYTHING you write(including notes, scripts, and web pages), to an external hard driveor USB thumb drive. I suggest you make this a daily 'end of the day'ritual.
Always remember that your hard drive, especially in a laptop that youcarry around with you and is subject to bumps and vibrations, couldfail AT ANY TIME!!
You should keep your backup external hard drive orUSB thumb drive in a safe place, like the top shelf of a closet orbehind a book on your book shelf.
You should keep your backup external hard drive orUSB thumb drive in a safe place, like the top shelf of a closet orbehind a book on your book shelf.
Please DON'T carry your backupdevice around with you in a backpack. If you feel that you reallyneed to carry your backup device with you, I suggest you have asecond, or maybe even a third backup device for that purpose. Thumbdrives don't cost that much, and you can NEVER have too many backupcopies.
A few words about PHP and Javascript:
Javascript, like PHP, is a scripting language that allows your webpages to do stuff other than just display text and images. A greatmany web pages use Javascript to display side shows, videos, run userlogin scripts, games, and a great many others things.
You may have notices that I have not said anything about installingJavascript yet. The reason why is...well...there is nothing that youneed to install. The Bluefish editor will allow you to write yourscripts, and everything you need to run them is already installed.
A script written in PHP runs (executes) on the the LAMP server, andonly passes the output to the client computer. If your security isset up right, the end user CAN'T see your PHP script. So anyIDs, passwords, or database scripts inside your PHP are secure (theuser can't see them). This makes PHP an excellent language for doinganything for a business, working with money, or working with a user'spersonal information.
A script written in Javascript is first downloaded from the LAMPserver to the client computer, and then runs (executes) on the clientcomputer. A savy computer user will be able to view your Javascript,along with any IDs and passwords you may have in it. This makesJavascript very un-secure as compared to PHP. However, Javascripttends to be much faster than PHP, and has many more capabilities.Javascript is an excellent choice if speed, and NOT security is whatyou are looking for.
So...which one to use for your website?
BOTH!
There is no reason why a web page can't use a mix of PHP andJavascript. In fact many do just that. So...I would recommend thatthe student learn, and use, BOTH PHP and Javascript.
There is no reason why a web page can't use a mix of PHP andJavascript. In fact many do just that. So...I would recommend thatthe student learn, and use, BOTH PHP and Javascript.
Now that you have a development environment installed and running,it's time to start learning and doing. I recommend the followingwebsites to learn more. I will also be writing additional blog postson these subjects.
HTML5 Tutorials at W3Schools:
Javascript Tutorial at W3Schools:
Using and configuring the Apache web server (YouTube video):
Introduction to Bluefish by Jon Morin:
How To Build a Website: HTML, CSS and HTML Editors, By Michael Rohde
Debian GNU/Linux installation notes for PHP
Interpreted Languages: JavaScript, PHP, Python, Ruby (Sheet One)
The PHP Security Cheat Sheet
That's it for this time. So long for now, and good luck.