apache

Get Apache & PHP working on Mac OS X 10.10 Yosemite


Three saviour commands

Start Apache
sudo apachectl start

Stop Apache
sudo apachectl stop

Restart Apache
sudo apachectl restart

Enable PHP
Open terminal and edit /etc/apache2/httpd.conf

sudo vi /etc/apache2/httpd.conf

Go to line # LoadModule php5_module libexec/apache2/libphp5.so and remove # and save the file and restart the server.

Document Root
Document Root is the folder where PHP files are shared and executed. By default in Yosemite Document Root is set to /Library/WebServer/Documents.

To change it to your custom location edit the /etc/apache2/httpd.conf again and make following lines

  • change DocumentRoot "/Library/WebServer/Documents" to DocumentRoot "/your/path/to/shared/folder"
  • change <Directory "/Library/WebServer/Documents"> to <Directory "/your/path/to/shared/folder">

save the file and restart the server.

Advertisements

Build your own android RSS applications on web server


Inspired by OVI app wizard I tried creating a small webpage to create android application on the fly.

To do this I used apache tomcat 7 and simple servlet programming.

I used apache-tomcat setup guide for installation.

Now i had my server ready so I referred Developing Web applications with Tomcat and Eclipse and created a new tomcat project “AppOnFly” inside $CATALINA_HOME/webapps/

Normal web application has following content,

anshu@Anshu-Notebook:~/apache-tomcat-7.0.14/webapps/AppOnFly$ ls -lrt 
total 40 
drwxr-xr-x 2 anshu anshu 4096 2011-05-30 16:24 bin 
drwxr-xr-x 2 anshu anshu 4096 2011-05-30 16:24 work 
drwxr-xr-x 2 anshu anshu 4096 2011-05-30 16:24 src 
drwxr-xr-x 5 anshu anshu 4096 2011-05-30 17:15 WEB-INF 

Now I created another directory “android_project” inside project folder.

anshu@Anshu-Notebook:~/apache-tomcat-7.0.14/webapps/AppOnFly$ ls -lrt 
total 40 
drwxr-xr-x 2 anshu anshu 4096 2011-05-30 16:24 bin 
drwxr-xr-x 2 anshu anshu 4096 2011-05-30 16:24 work 
drwxr-xr-x 2 anshu anshu 4096 2011-05-30 16:24 src 
drwxr-xr-x 5 anshu anshu 4096 2011-05-30 17:15 WEB-INF 
drwxr-xr-x 3 anshu anshu 4096 2011-05-30 17:26 android_project 

Inside android_project i copied my own RssReader android application. This application has simple implementation of RSS parser and it takes the RSS url from channel.prop file in assets.

Now all i had to do was get the URL from webpage and create channel.prop file and build the application. To do this, my servlet came in picture.

But before getting into servlet, I added one more file, i.e., run.sh to run ANT to build my android application.

run.sh

 #!/bin/sh 
cd ../webapps/AppOnFly 
rm -r -f *.apk 
cd ./android_project/MyRssReader/ 
ant clean 
ant compile 
ant debug 
cp ./bin/MyRssReader-debug.apk ../../MyRssReader.apk 

Now I had everything except a webpage and a servlet.

I created a simple JSP page index.jsp

index.jsp

<html>

  <head>
    <title>AppOnFly</title>
  </head>
  <body>
    <h1>Create your own android RSS Reader</h1>
    <hr>
    <h2>Please enter the URL for rss feed that you want to follow</h2>
    <br>
    <hr>
    <form action="go" method="post">
    	<input type="text" name="url">Enter URL</input>
    	<input type="submit"/>
    </form>
  </body>
</html>

Now last two steps were to create a servlet(AppCreator.java) and web.xml

AppCreator.java

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 */

/**
 * @author anshu
 *
 */
public class AppCreator extends HttpServlet {

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		PrintWriter pw = resp.getWriter();
		pw.write("<html><body>");
		File propFile = new File(getServletContext().getRealPath(
				"android_project/MyRssReader/assets/channel.prop"));
		if (propFile.exists()) {
			propFile.delete();
			propFile.createNewFile();
		}
		FileOutputStream fout = new FileOutputStream(propFile, false);
		fout.write(req.getParameter("url").getBytes());
		fout.close();

		String cmd = getServletContext().getRealPath("run.sh");
		Runtime run = Runtime.getRuntime();
		Process pr = run.exec(cmd);
		try {
			pr.waitFor();
			BufferedReader buf = new BufferedReader(new InputStreamReader(pr
					.getInputStream()));

			String line;
			while (null != (line = buf.readLine())) {
				// pw.write(line);
				// pw.write("<br>");
			}
			pw.write("<a href=\"MyRssReader.apk\">Download</a>");
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			pw.write(e.getMessage());
		}
		pw.write("</body></html>");
	}
}

web.xml


<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

	<display-name>
		AppOnFLy
    </display-name>
	<description>
		Create your own android applications.
    </description>

	<servlet>
		<servlet-name>AppCreator</servlet-name>
		<servlet-class>AppCreator</servlet-class>
	</servlet>

	<servlet-mapping>
		<servlet-name>AppCreator</servlet-name>
		<url-pattern>/go</url-pattern>
	</servlet-mapping>

</web-app>

Done.

whole workspace and look n’ feel was not good looking but it at least proved the concept.