1. Run the following command:
sudo yum install httpd
2. Keep a backup copy after httpd.conf
cp /etc/httpd/conf/httpd.conf ~/httpd.conf.backup.timestamp
3. Check installed version with:
httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Oct 19 2017 20:39:16
4. Right now httpd is installed and not running:
service httpd status
Redirecting to /bin/systemctl status httpd.service
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:httpd(8)
man:apachectl(8)
5. Create document root folder:
cd /var/www/html && mkdir test.com
6. Add document root to httpd.conf
vi /etc/httpd/conf/httpd.conf
...
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html/test.com"
...
7. Configure virtual host:
cd /etc/httpd/conf.d
touch vhost.conf
vi vhost.conf
....
<VirtualHost *:80>
ServerName localhost
ServerAlias www.test.com
DocumentRoot /var/www/html/test.com/
ErrorLog logs/error.log
CustomLog logs/access.log combined
</VirtualHost>
...
8. Test httpd configuration by running:
service httpd configtest
Syntax OK
9. Start apache httpd:
service httpd start
10. Check service is running:
service httpd status
Redirecting to /bin/systemctl status httpd.service
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2017-11-29 07:44:34 PST; 7s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 21159 (httpd)
Status: "Processing requests..."
CGroup: /system.slice/httpd.service
├─21159 /usr/sbin/httpd -DFOREGROUND
├─21160 /usr/sbin/httpd -DFOREGROUND
├─21161 /usr/sbin/httpd -DFOREGROUND
├─21162 /usr/sbin/httpd -DFOREGROUND
├─21163 /usr/sbin/httpd -DFOREGROUND
└─21164 /usr/sbin/httpd -DFOREGROUND
11. Make sure Inbound port 80 is enabled on CentOS 7 Firewall:
firewall-cmd --zone=public --add-port=80/tcp
success
12. Test from within browser apache is accessible:
Thursday, December 28, 2017
Tuesday, December 26, 2017
Create embedded Jetty Java application
Here are the exact steps:
1. Download and install Eclipse:
https://www.eclipse.org/downloads/
2. Crete New Maven Project:
3. Create a simple project (skip archetype selection)
4. Configure project with following values:
5. In the end, your project structure shall look like this:
6. Edit pom.xml by adding latest Jetty dependencies. You can find it from here:
https://www.eclipse.org/jetty/download.htmlhttps://www.eclipse.org/jetty/download.html
pom.xml shall look like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dtechnotes</groupId>
<artifactId>embedded-jetty-java</artifactId>
<version>1.0.0</version>
<dependencies>
<!--Jetty dependencies-->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<!--Jetty dependencies end-->
</dependencies>
</project>
7. Add 2 new packages as per below:
8. Add 2 new Java classes for each of the above packages:
9. JettyJavaMain.java
package com.dtechnotes.jettyjava;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import com.dtechnotes.jettyjava.servlet.TestServlet;
public class JettyJavaMain {
public static void main(String[] args) throws Exception {
Server server = new Server(8082);
ServletContextHandler handler = new ServletContextHandler(server, "/dtech");
handler.addServlet(TestServlet.class, "/");
server.start();
}
}
10. TestServlet.java
package com.dtechnotes.jettyjava.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpStatus;
public class TestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setStatus(HttpStatus.OK_200);
resp.getWriter().println("<b>This is my first Jetty Test</b>");
}
}
11. You can run directly JettyJavaMain.java class and get result by navigating to:
http://localhost:8082/dtech/
12. Additionaly, you can export to single jar file using the Eclipse export feature:
File -> Export -> Runnable Jar File
13. And run the jar file with the same results as step 11 above:
1. Download and install Eclipse:
https://www.eclipse.org/downloads/
2. Crete New Maven Project:
3. Create a simple project (skip archetype selection)
4. Configure project with following values:
5. In the end, your project structure shall look like this:
6. Edit pom.xml by adding latest Jetty dependencies. You can find it from here:
https://www.eclipse.org/jetty/download.htmlhttps://www.eclipse.org/jetty/download.html
pom.xml shall look like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dtechnotes</groupId>
<artifactId>embedded-jetty-java</artifactId>
<version>1.0.0</version>
<dependencies>
<!--Jetty dependencies-->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<!--Jetty dependencies end-->
</dependencies>
</project>
7. Add 2 new packages as per below:
8. Add 2 new Java classes for each of the above packages:
9. JettyJavaMain.java
package com.dtechnotes.jettyjava;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import com.dtechnotes.jettyjava.servlet.TestServlet;
public class JettyJavaMain {
public static void main(String[] args) throws Exception {
Server server = new Server(8082);
ServletContextHandler handler = new ServletContextHandler(server, "/dtech");
handler.addServlet(TestServlet.class, "/");
server.start();
}
}
10. TestServlet.java
package com.dtechnotes.jettyjava.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpStatus;
public class TestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setStatus(HttpStatus.OK_200);
resp.getWriter().println("<b>This is my first Jetty Test</b>");
}
}
11. You can run directly JettyJavaMain.java class and get result by navigating to:
http://localhost:8082/dtech/
12. Additionaly, you can export to single jar file using the Eclipse export feature:
File -> Export -> Runnable Jar File
13. And run the jar file with the same results as step 11 above:
Sunday, December 3, 2017
How to fix following error: Failed to execute goal org.apache.rat:apache-rat-plugin on project org.apache.sling.samples.path-based.rtp: Too many files with unapproved license:
1. Run Maven build command:
mvn clean install -s /home/user/.m2/settings.xml
2. Getting the following Build Failure message:
[ERROR] Failed to execute goal org.apache.rat:apache-rat-plugin:0.11:check (default) on project org.apache.sling.samples.path-based.rtp: Too many files with unapproved license: 1677 See RAT report in: /home/scaunasu/path-based-rtp/target/rat.txt -> [Help 1]
3. To solve the above, run Maven command with the following additiona parameter:
mvn clean install -s /home/user/.m2/settings.xml -Drat.numUnapprovedLicenses=2000
mvn clean install -s /home/user/.m2/settings.xml
2. Getting the following Build Failure message:
[ERROR] Failed to execute goal org.apache.rat:apache-rat-plugin:0.11:check (default) on project org.apache.sling.samples.path-based.rtp: Too many files with unapproved license: 1677 See RAT report in: /home/scaunasu/path-based-rtp/target/rat.txt -> [Help 1]
3. To solve the above, run Maven command with the following additiona parameter:
mvn clean install -s /home/user/.m2/settings.xml -Drat.numUnapprovedLicenses=2000
Subscribe to:
Posts (Atom)