Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
Write an article for LinuxForums Today! Win Great Prizes!
In this article I will compare Java and PHP for building dynamic websites. The comparison will include speed, writing code, development cycle, maintainability , community support, security, cost, manpower and the availability of third party hosting service. Then I will cover the installation of LAMP server (Linux, Apache, MySQL and PHP).
I have covered the installation of Java for stand-alone and web application in a previous article. Please read the previous article before you move on to this one.
Reasons for using Java:
1- Java is both compiled language and interpreted language. The Javac compiler converts the source code to byte code classes which is then interpreted by the Java virtual machine (JVM) for execution. The speed is almost similar to PHP as the Java class is only compiled once.
2- Java is hard to write (so it has longer development cycle) but easy to read. This makes the maintainability and further development much easier task than in PHP.
3- Java is executed in the virtual machine (the sandbox feature which restrict the access for local resources for codes/applets that come from none trusted sources. The code/applet first has to be executed in the sandbox before allowing it to be executed in the JVM). Thus, security in Java is better than in PHP (Java is OS independent).
4- Java handle multi-threading much better than in PHP (in PHP it is achieved by the non native cURL) so it allows resource sharing and provides better responsiveness.
5- Java is better suited for government, banking and health-care sectors applications (complex domains generally).
6- Java is more expensive but better solution.
7- Java is a multipurpose language. So the integration of the web application with the corporate system is more straight forward (unlike PHP because it is only a scripting language so a bridge is required for the integration with the corporate system)
8- The availability of standard professional qualification from Oracle currently (it was Sun certification in the past).
9-Java has a richer API.
Reasons to choose PHP:
1- PHP is interpreted language. As mentioned above the speed is almost similar to Java.
2- PHP is easy to write (so it has shorter development cycle) but hard to read and most of the times leads to spaghetti code (especially in complex domains as most coders do not separate the presentation from the business logic). However, for small tasks it is the better solution.
3-PHP as being the Internet most popular language, you will find a lot of online support and a lot of examples for solving problems.
4- PHP has numerous third party hosting services.
5- PHP is cheaper but dirtier solution.
6- There are a lot of good PHP coders out there as it requires no background in computing generally and it is easier to understand.
7-The availability of good content management system like Joomla and Drupal.
8- PHP applications are mostly done by the prototyping methodology or agile development where as Java has the much longer the unified process
To install lamp there are two ways to do it. The first is installing each component individually then configure them and the second is by using a single command. I will use the latter for the sake of simplicity.
Run the terminal and type the following command:
$sudo apt-get install lamp-server^
MySQL was previously installed when I installed Java and MySQL and GlassFish (check the link in the first paragraph). So it has not been reinstalled as I have already configured it in the first installation.
Now Point your browser to localhost, if it's successfully installed you should see a message saying (It works!) To test PHP go to /var/www/ directory and create a new file(call it test.php) and add the following line:
<?php phpinfo(); ?>
Now restart Apache web server by typing $sudo service apache2 restart Then point your browser to (http://localhost/test.php) and the page should display a table about your PHP installation or configuration.
Now install phpMyAdmin by typing:
$sudo apt-get install phpmyadmin
Follow on-screen instructions then choose the web server (Apache in our case) by pressing space then ENTER. If you have not installed and configured the database in the Java tutorial choose Yes option, otherwise choose No.
If somehow you have not linked phpMyAdmin to Apache in the previous command type: $sudo dpkg-reconfigure phpmyadmin Then a prompt will appear asking you for the re-installation of MySQL Choose No as you might not want to wipe out your data. Then choose Apache and proceed with the rest of the installation. After that reload Apache by typing: $sudo service apache2 reload
To start MySQL type:
$sudo service mysql restart
To stop mysql type:
$sudo service mysql stop
To start apache type:
$sudo service apache2 start
To stop apache type:
$sudo service apache2 stop
Changing password and issuing MySQLqueries and general administration could be done from the terminal but it does not make sense to do so if we have installed phpMyAdmin. In my own opinion phpMyAdmin is the best user interface for managing MySQL databases.
My name is Amin Salim and I am Sudanese born in Kuwait. I hold a degree in Information Systems (BSC) from the University of Leeds. I have worked as a research assistant for a local expertise and consultancy firm called (SUDEXAM). Then I travelled to Sierra Leone and worked for the project development unit as an Information Systems engineer. My role was doing the financial analysis and the whole editing for the feasibility studies and providing technical support. I am flexible, and a good team player as realized from conducting feasibility studies with people from different backgrounds and qualifications. Afterwards I came back to Sudan and worked as self-employed software engineer and have developed a system by myself from scratch for a charity eye-hospital. The system functionality was to keep track of stock and sales (written in Java). I am very versatile individual as proven from working on different disciplines and always looking to improve my skills.