Setting LAMP development environment with Linux
Lamp developers work on open source technologies. We proudly say that we support FOSS (Free and Open Source Software) movement. How still several open source developers work on Microsoft windows, which is a proprietary operating system from Microsoft and putting its user’s freedom at stake.
The reason most users use proprietary operating system is they feel (although its not true) that learning linux is not easy. No doubt learning new OS need some time and patience but still it is not a rocket science. If you wish to start development on Linux, this document will help you to setup PHP development environment on Open SUSE 12.1 on your Laptop (Well it will also work for desktop). However be prepared to download some software (approx 2-3 GB) and prepare CD/DVD of them.
Installing Open SUSE
This document is designed with installation of Open SUSE 12.1 but it should work with any Open SUSE version and to some extent, any Linux distribution.
Here I’m making a system running entirely on Open SUSE but not dual boot. Instead of dual boot, I prefer to load SUSE and install any other OS, if needed, through Oracle Virtual Box.
To install open SUSE 12.1, obviously you need to download it. Go to opensuse.org and select proper (32/64 bit) distribution and download its DVD through torrent. Once you burn OpenSUSE DVD, make sure your first boot drive is DVD ROM.
Put Open SUSE DVD in DVD drive and start the system so that it boot from DVD.
If you are new to Linux, keep all settings default. Don’t worry, when you get some experience with Linux, you may change anything except hard disk partition & you will not need to change hard disk partition. So follow on screen instructions and install Open SUSE with default settings. Default settings are properly optimized for majority of users and will work for 95%+ users.
Setting internet
Installing LAMP
Once you have open SUSE installed with internet running, you are ready to install LAMP. (Well ‘L’ of LAMP already installed, just AMP remaining :D)
LAMP stands for Linux, Apache, MySQL, PHP
Installing MySQL
Open terminal and login as root.
To login as root, enter command “su” obviously without quotes. It will ask root password, enter correct password and you are in as root.
Now enter following command to install MySQL
yast2 -i mysql mysql-client mysql-community-server
Now we might want MySQL to start automatically with system. If that is the case, enter following commands
systemctl enable mysql.service
systemctl start mysql.service
Now we need to secure MySQL. Please run the command:
mysql_secure_installation
This will ask few set of questions as follow. Please select answers as shown below
NOTE:RUNNINGALLPARTSOFTHISSCRIPTISRECOMMENDEDFORALLMySQL
SERVERSINPRODUCTIONUSE!PLEASEREADEACHSTEPCAREFULLY!
InordertologintoMySQLtosecureit,we’llneedthecurrent
passwordfortherootuser.Ifyou’vejustinstalledMySQL,and
youhaven’tsettherootpasswordyet,thepasswordwillbeblank,
soyoushouldjustpressenterhere.
Entercurrentpasswordforroot(enterfornone):
OK,successfullyusedpassword,movingon…
SettingtherootpasswordensuresthatnobodycanlogintotheMySQL
rootuserwithouttheproperauthorisation.
Setrootpassword?[Y/n]y
Newpassword:
Re-enternewpassword:
Passwordupdatedsuccessfully!
Reloadingprivilegetables..
…Success!
Bydefault,aMySQLinstallationhasananonymoususer,allowinganyone
tologintoMySQLwithouthavingtohaveauseraccountcreatedfor
them.Thisisintendedonlyfortesting,andtomaketheinstallation
goabitsmoother.Youshouldremovethembeforemovingintoa
productionenvironment.
Removeanonymoususers?[Y/n]y
…Success!
Normally,rootshouldonlybeallowedtoconnectfrom‘localhost’.This
ensuresthatsomeonecannotguessattherootpasswordfromthenetwork.
Disallowrootloginremotely?[Y/n]y
…Success!
Bydefault,MySQLcomeswithadatabasenamed‘test’thatanyonecan
access.Thisisalsointendedonlyfortesting,andshouldberemoved
beforemovingintoaproductionenvironment.
Removetestdatabaseandaccesstoit?[Y/n]Y
–Droppingtestdatabase…
…Success!
–Removingprivilegesontestdatabase…
…Success!
Reloadingtheprivilegetableswillensurethatallchangesmadesofar
willtakeeffectimmediately.
Reloadprivilegetablesnow?[Y/n]Y
…Success!
Cleaningup…
Alldone!Ifyou’vecompletedalloftheabovesteps,yourMySQL
installationshouldnowbesecure.
ThanksforusingMySQL!
Congratulations, MySQL is now set and secure.
Installing Apache2
Next step is to install Apache2. Run the following command for that
yast2 -i apache2
Above command will install Apache2. As like MySQL, we would like to start Apache2 automatically with system boot. Enter following commands for that
systemctl enable apache2.service
systemctl start apache2.service
Now open browser and visit http://localhost. You will probably get “Access Forbidden” screen with error 403. Don’t worry about 403 error, it happen as index.php is not present and we will soon fix it after installing PHP
Installing PHP5
We can install PHP5 and Apache-PHP module with following command.
yast2 -i apache2-mod_php5
Once PHP is installed, we need to restart apache server. Run the following command for that:
systemctl restart apache2.service
Now we have Apache in place and PHP installed. We can not run our first PHP file. Document root of default website is /srv/www/htdocs. We need to create a basic php file, that we can do from console only. Enter following command:
vi /srv/www/htdocs/info.php
Pleasenote,weareexpectingvieditorisinstalledonthesystem,whichgetsinstalledbydefault.Howeverifyougeterrorwithabovevicommand,runfollowingcommand
yast-ivim
Runabovecommandonlyifyougeterrorwithvicommand.IFnot,skipthisstep
In vi editor, press ‘I’ to go to insert mode. In insert mode, write following code
<?PHP
phpinfo();
Press Escape key to get out of insert mode. Now press :wq (colon, ‘w’, ‘q’) and press enter. Colon define vi command, w saves the file and q exits from vi editor.
Now enter “http://localhost/info.php” in browser. PHP info command will display details about installed PHP and its modules. Please note MySQL & MySQLi is not present there. This is because we didn’t installed PHP-MySQL modules.
Getting PHP-MySQL modules
To install MySQL modules, run following command
yast2 -i php5-mysql php5-bcmath php5-bz2 php5-calendar php5-ctype php5-curl php5-dom php5-ftp php5-gd php5-gettext php5-gmp php5-iconv php5-imap php5-ldap php5-mbstring php5-mcrypt php5-odbc php5-openssl php5-pcntl php5-pgsql php5-posix php5-shmop php5-snmp php5-soap php5-sockets php5-sqlite php5-sysvsem php5-tokenizer php5-wddx php5-xmlrpc php5-xsl php5-zlib php5-exif php5-fastcgi php5-pear php5-sysvmsg php5-sysvshm
After that, we need to restart apache. Run following command
systemctl restart apache2.service
Refresh browser with info.php file. Check the difference, you will get info about MySQL too.
Installing PHPMyAdmin
Another most commonly used tool for PHP developers is PHPMyAdmin. To install it, run following command:
yast2 -i phpMyAdmin
If you are setting production server, (Although since you are linux novice, you are probably not :D), you might want to allow PHPMyAdmin access to all hosting account. For this, open phpMyAdmin configuration file with following command.
vi /etc/apache2/conf.d/phpMyAdmin.conf
In this file, enter following two lines at the top:
Alias /phpMyAdmin /srv/www/htdocs/phpMyAdmin Alias /phpmyadmin /srv/www/htdocs/phpMyAdmin
Above command will install PHPMyAdmin. Restart apache server as above and we have PHP development environment set up.
Installing (oracle) Java
As PHP developer, we might (will most probably) need some IDE like netbeans and/or eclipse. They both run on Java. Thus before we can install them, we must need to install Java. (I’m also a java developer so I’ve dual reasons for installing java :P)
Again OpenSUSE do not include Oracle Java but it include Open Java due to licensing issues. To install oracle java, download its rpm package from oracle website.
After download, open console and login as root. If you are not sure how to login as root, you need to enter command ‘su’ to login as root. It will also prompt for root password
As root user, go to folder having downloaded jdk and run following commands from install directory
rpm -e jdk-7u5-linux-i586.rpm
rpm -ivh jdk-7u5-linux-i586.rpm
rpm -Uvh jdk-7u5-linux-i586.rpm
Please note file name might be different for you based on downloaded java version.
You might need to find where java is installed but most probably it will be installed in folder “/usr/java/jdk1.7.0_05”, again folder name might change according to java version.
Now we have two (maybe more) set of java installed. Linux gives us facility to switch between them. However before we can use that facility, we must tell linux that we might want to use newly installed java as a switch option. For this, we must register newly installed java. Use following command for that.
sudo /usr/sbin/update-alternatives –install /usr/bin/java java /usr/java/jdk1.7.0_05/bin/java 3
Please note path ‘/usr/java/jdk1.7.0_05/bin/java’ might be different for you. Again ‘sudo’ at the starting of command is needed only if you are not loggedin as SU.
Lets also register javac, if you want to compile few java programs but if you are not java developer, you can skip following command. In that case, you wont be able to compile java programs.
sudo /usr/sbin/update-alternatives –install /usr/bin/javac javac /usr/java/jdk1.7.0_05/bin/javac 3
Now we registered oracle java. We might want to see the list of all registered java. Use following command for that.
sudo /usr/sbin/update-alternatives –list java
Above command displayed following output for me
/usr/java/jdk1.7.0_05/bin/java
/usr/lib/jvm/jre-1.6.0-openjdk/bin/java
First one is newly installed java. Second one is SUSE default openjdk.
Now before we really switch, enter following command to check default java.
Java -version
Above command will display information about java.
Now lets switch java. Enter following command
/usr/sbin/update-alternatives –config java
Above command displayed following output
There are 2 choices for the alternative java (providing /usr/bin/java).
SelectionPathPriorityStatus
————————————————————
* 0 /usr/lib/jvm/jre-1.6.0-openjdk/bin/java 17105 auto mode
1/usr/java/jdk1.7.0_05/bin/java3manualmode
2/usr/lib/jvm/jre-1.6.0-openjdk/bin/java17105manualmode
Pressentertokeepthecurrentchoice[*],ortypeselectionnumber:1
update-alternatives: using /usr/java/jdk1.7.0_05/bin/java to provide /usr/bin/java (java) in manual mode.
‘1’ in red is option chosen by me. Select correct option and java will be switched. Now again enter following command
java -version
You will see the difference between them.
Installing Netbeans
Installing SVN
Developers generally work in team and and different versions of program. For that, we need some version control system. I’m mostly working with SVN so for now I’m covering SVN but soon will add few more version control like CVS, mercurious etc.
http://software.opensuse.org/download.html?project=devel:tools:scm:svn&package=subversion
Select OS and follow onscreen instructions. However you might need to learn SVN commands. Like windows user, I do not prefer to work with Tortoise SVN, which takes away few powers. SVN through commands is more powerful. Just google to know SVN commands. Believe me, they are easy to learn & gives you unlimited power.
Check out.
Now you have SVN installed. Next you would probably need to checkout some code and start working on that.
Probably you would like (& you should) to take checkout in you folder but not in system folder. So that you do not need to login as root frequently. Just go to directory /home/kapil/public_html. Here kapil is my name, For you, replace kapil with your name.
cd /home/kapil/public_html
Now take checkout
svn co http://host/projectname name
svn co – command for checkout
http://host/projectsname – project svn URL, change it as your SVN URL.
name – A new directoru with ‘name’ will be created. Change it to project name.
Done. You have checkout.
Setting hosts and virtual host
You now have check out of running PHP project but your apache dont know about it. Lets tell apache about it.
Apache is installed by root so you need to login as root for following settings.
We first need to create new file ‘prohectname.conf’ at /etc/apache2/conf.d/
Enter following command
vi /etc/apache2/conf.d/ragsexchange.conf
This will open vi editor. Now press ‘i’ to enable insert mode and paste following code
<VirtualHost *>
ServerName local.projectname.com
DocumentRoot /home/kapil/public_html/projectname
ServerAdmin kapil@kapilsharma.info
ErrorLog /var/log/apache2/local.projectname.com-error_log
CustomLog /var/log/apache2/local.projectname.com-access_log common
</VirtualHost>
There are few text in red, that you might want to change according to your project.
We have created a virtual host so if apache is running (which will be if you configured it to start with system), putting local.projectname.com should load the project. However it will not and you will probably get error.
The reason is, your browser is looking at internet and on internet, you will not find that site. Thus apache is now fine (provided you restart apache) but linux should also know that it must look apache to load above site. To do that, we need to make an intry in ‘hosts’ file. Run following command as root
vi /etc/hosts
This will open hosts file in vi editor. Look for the line
127.0.0.1 localhost
Just below that line, add following line
127.0.0.1 local.projectname.com
Now restart apache. I’m not giving command to restart apache again. I already gave it quite a few times and you must need to learn it. If you forget, scroll up to find it again and remember it.
Once apache is restarted, enter ‘http://local.projectname.com‘ in browser. Congratulation, your project is not running.
I’mm update few more supporting documents to make linux experience fun but for now, yu are up and running with development account.
If you have any doubts, try to figure our respective forums to get quick answer. Putting questions in comments will not help you as I do not see comments on daily basis.
Congratulation, you are now free (from proprietary software vendors). Enjoy the freedom of using computer as you wish but not as your vandor wish.
Leave a Reply