How to create localhost domain management for windows in php? - java

I am crazy about this thing, but i want to make it myself in php itself.
I have installed the following in my system.
WAMP Server 2.2 which includes following
Apache Web Server Version 2.2.222
MySQL Server Version 5.5.24
PHP Version 5.3.13
OS Version Windows 8 64Bit
Location of Hosts file:
C:\Windows\System32\Drivers\etc\hosts
Location of WAMP Server:
C:\wamp
Location of Apache Web Server:
- C:\wamp\bin\apache\apache2.2.22
- C:\wamp\bin\apache\apache2.2.22\conf\extra\httpd-vhosts.conf
Location of MySQL Server:
C:\wamp\bin\mysql\mysql5.5.24
Location of PHP:
C:\wamp\bin\php\php5.3.13
I have simple example of Create the VHost in localhost
e.g. I want to create simple domain www.mylocalsite.com on 80 port
For that I have following steps:
(1) Enagle Apache modules
rewrite_module
vhosts_alias_module
(2) Open httpd.conf file to enable Vhost settings
C:\wamp\bin\apache\apache2.2.22\conf\httpd.conf
Virtual hosts
Include conf/extra/httpd-vhosts.conf // Remove the # before Include and save file
(3) Add VHost entry in httpd-vhosts.conf file
<VirtualHost *:90>
DocumentRoot "C:/mylocalsite.com/"
ServerName www.mylocalsite.com
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "C:/mylocalsite.com/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "C:/mylocalsite.com/logs/error.log" // Logs folder should be exists
CustomLog "C:/mylocalsite.com/logs/access.log" common
</VirtualHost>
(4) Add entry in hosts file
Open file in Notepad with Admin Permission C:\Windows\System32\Drivers\etc\hosts
add following line at end of the file and Save it.
127.0.0.1 www.mylocalsite.com
(5) Restart the (From WAMP) Apache Web Server and run in browser http://www.mylocalsite.com/ will work.
Now, My Question is how can I do the above steps in dynamic nature using PHP/JSP or any other language.
Suppose I will create one Form in HTML with following fields and when submit it will create new MySQL entry for that domain.
EDIT:
Domain Type: select option or Radio Options ( Root/Sub-Domain )
Sub-Domain Name ( Optional ): Text field
Domain Name: Text field
Project Path: text field
Log Folder Path: text field
Tmp Folder Path: text field
Database Type: text field ( mysql/pgsql )
<Submit>
when i click on button it will automatically create the domain entry in hosts file, vhosts entry in httpd-vhosts.conf file.
And, when restart the Apache server it will run automatically created domain or sub-domain dynamically.
Can anyone knows how can i established the following things in any language for local system only?

Don't use web form. You can see my demo with batch file:
(1) Create vhost template template.txt
<VirtualHost *:90>
DocumentRoot "_ROOT_"
ServerName _DOMAIN_
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "_ROOT_">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "_ROOT_/logs/error.log"// Logs folder should be exists
CustomLog "_ROOT_/logs/access.log" common
</VirtualHost>
(2) Create add_vhost.bat
#echo off
set /p domain=Domain (www.mylocalsite2.com):
set lineHost=127.0.0.1 %domain%
REM Create the domain entry in hosts file
echo %lineHost% >> C:\Windows\System32\drivers\etc\hosts
set /p folder=Folder (C:/mylocalsite2.com/):
REM Create vhost entry in httpd-vhosts.conf file
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in (template.txt) do (
set str=%%i
set str=!str:_ROOT_=%folder%!
set str=!str:_DOMAIN_=%domain%!
echo !str! >> C:\wamp\bin\apache\apache2.2.22\conf\extra\httpd-vhosts.conf
)
(3) Run add_vhost.bat as Administrator (to write HOSTS file)

Related

ElasticBeanstalk - Changing java.security?

I would like to change the securerandom.source value in $JAVA_HOME/jre/lib/security/java.security on my Elastic Beanstalk instance.
How can I do that through the .ebextensions? Or is the another way to do that?
At the beginning of $JAVA_HOME/jre/lib/security/java.security file, there's a paragraph saying
# This is the "master security properties file".
#
# An alternate java.security properties file may be specified
# from the command line via the system property
#
# -Djava.security.properties=<URL>
#
# This properties file appends to the master security properties file.
# If both properties files specify values for the same key, the value
# from the command-line properties file is selected, as it is the last
# one loaded.
So you may create a java-security.config file with the following content under .ebextensions folder:
# Create a file named java-security under /usr/share/tomcat8/conf to override the default value of securerandom.source
files:
"/usr/share/tomcat8/conf/java-security" :
mode: "000755"
owner: tomcat
group: tomcat
content: |
securerandom.source=<the file you want for securerandom.source>
Then go to elastic beanstalk environment
-> Configuration
-> Software
-> Environment properties
-> type java.security.properties for Name, and /usr/share/tomcat8/conf/java-security for Value.
Then restart the tomcat. Your securerandom.source should be changed to the value you wish.
One thing to remember is that the user tomcat must have permissions to read /usr/share/tomcat8/conf/java-security file.

Redirect Apache to Tomcat on Vesta CP

I have a VPS server with Ubuntu 18 O.S. In this VPS I have installed VESTA CP, which comes with Apache 2 and Nginx. After that I have intalled Tomcat 9(port 8082) to serve a Java Spring based webapp.
If I enter the address "serverIP:8082/AppFolder" I can access the app, but I want to redirect the apache server to the tomcat one, so I can write the domain name and load the webapp.
I have tried .htaccess file but it shows an apache error page. I have no permission to view this file is the message.
What can I do to solve this?
-Nginx config:
location / {
proxy_pass http://IP:8080;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ {
root /home/admin/web/webapp.com/public_html;
access_log /var/log/apache2/domains/webapp.com.log combined;
access_log /var/log/apache2/domains/webapp.com.bytes bytes;
expires max;
try_files $uri #fallback;
}
}
location /error/ {
alias /home/admin/web/webapp.com/document_errors/;
}
location #fallback {
proxy_pass http://IP:8080;
}
-Apache config:
<VirtualHost IP:8080>
ServerName webapp.com
ServerAlias www.webapp.com
ServerAdmin info#webapp.com
DocumentRoot /home/admin/web/webapp.com/public_html
ScriptAlias /cgi-bin/ /home/admin/web/webapp.com/cgi-bin/
Alias /vstats/ /home/admin/web/webapp.com/stats/
Alias /error/ /home/admin/web/webapp.com/document_errors/
#SuexecUserGroup admin admin
CustomLog /var/log/apache2/domains/webapp.com.bytes bytes
CustomLog /var/log/apache2/domains/webapp.com.log combined
ErrorLog /var/log/apache2/domains/webapp.com.error.log
<Directory /home/admin/web/webapp.com/public_html>
AllowOverride All
Options +Includes -Indexes +ExecCGI
php_admin_value open_basedir /home/admin/web/webapp.com/public_html:/home/admin/tmp
php_admin_value upload_tmp_dir /home/admin/tmp
php_admin_value session.save_path /home/admin/tmp
</Directory>
<Directory /home/admin/web/webapp.com/stats>
AllowOverride All
</Directory>
<IfModule mod_ruid2.c>
RMode config
RUidGid admin admin
RGroups www-data
</IfModule>
<IfModule itk.c>
AssignUserID admin admin
</IfModule>
IncludeOptional /home/admin/conf/web/apache2.webapp.com.conf*
</VirtualHost>
Thanks.
Finally I have found an answer...editing the config file of nginx:
proxy_pass http://IP:8082; <--TOMCAT PORT
root /home/admin/web/webapp.com/public_html; <--JSP PAGES PATH
Default config file has the Apache port and apache html pages path.
I suppose this can be done using apache proxy_mod, but I donĀ“t know which way is better...if anyone can explain the two ways(via apache or via nginx) I apreciate it.

neo4j keeps giving erros and is not running,can you help me with its errors?

I downloaded neo4j.zip from its site and extract it.
I downloaded and installed jdk 7, I have two folders in :
C:\Program Files\Java\jdk1.7.0_75
and
C:\Program Files\Java\jre7
And I clicked on New and made a variable named JAVA_HOME and its value is
C:\Program Files\Java\jdk1.7.0_75
I have added
org.neo4j.server.startup_timeout=0
line to my neo4j-server.properties file because of timeout error and
I have changed the port number in neo4j-server.properties file from 7474 to 80 and 8085, this is my neo4j-server.properties now:
################################################################
# Neo4j
#
# neo4j-server.properties - runtime operational settings
#
################################################################
#***************************************************************
# Server configuration
#***************************************************************
# location of the database directory
org.neo4j.server.database.location=data/graph.db
# Low-level graph engine tuning file
org.neo4j.server.db.tuning.properties=conf/neo4j.properties
# Database mode
# Allowed values:
# HA - High Availability
# SINGLE - Single mode, default.
# To run in High Availability mode, configure the neo4j.properties config file, then uncomment this line:
#org.neo4j.server.database.mode=HA
# Let the webserver only listen on the specified IP. Default is localhost (only
# accept local connections). Uncomment to allow any connection. Please see the
# security section in the neo4j manual before modifying this.
#org.neo4j.server.webserver.address=0.0.0.0
# Require (or disable the requirement of) auth to access Neo4j
dbms.security.auth_enabled=true
#
# HTTP Connector
#
# http port (for all data, administrative, and UI access)
org.neo4j.server.webserver.port=8085
#
# HTTPS Connector
#
# Turn https-support on/off
org.neo4j.server.webserver.https.enabled=true
# https port (for all data, administrative, and UI access)
org.neo4j.server.webserver.https.port=7473
# Certificate location (auto generated if the file does not exist)
org.neo4j.server.webserver.https.cert.location=conf/ssl/snakeoil.cert
# Private key location (auto generated if the file does not exist)
org.neo4j.server.webserver.https.key.location=conf/ssl/snakeoil.key
# Internally generated keystore (don't try to put your own
# keystore there, it will get deleted when the server starts)
org.neo4j.server.webserver.https.keystore.location=data/keystore
# Comma separated list of JAX-RS packages containing JAX-RS resources, one
# package name for each mountpoint. The listed package names will be loaded
# under the mountpoints specified. Uncomment this line to mount the
# org.neo4j.examples.server.unmanaged.HelloWorldResource.java from
# neo4j-server-examples under /examples/unmanaged, resulting in a final URL of
# http://localhost:7474/examples/unmanaged/helloworld/{nodeId}
#org.neo4j.server.thirdparty_jaxrs_classes=org.neo4j.examples.server.unmanaged=/examples/unmanaged
#*****************************************************************
# HTTP logging configuration
#*****************************************************************
# HTTP logging is disabled. HTTP logging can be enabled by setting this
# property to 'true'.
org.neo4j.server.http.log.enabled=false
# Logging policy file that governs how HTTP log output is presented and
# archived. Note: changing the rollover and retention policy is sensible, but
# changing the output format is less so, since it is configured to use the
# ubiquitous common log format
org.neo4j.server.http.log.config=conf/neo4j-http-logging.xml
#*****************************************************************
# Administration client configuration
#*****************************************************************
# location of the servers round-robin database directory. possible values:
# - absolute path like /var/rrd
# - path relative to the server working directory like data/rrd
# - commented out, will default to the database data directory.
org.neo4j.server.webadmin.rrdb.location=data/rrd
org.neo4j.server.startup_timeout=0
but again when I run Neo4j.bat by double clicking on it, cmd window will open and java window will open and will close after some seconds and cmd window will close after it and
http://localhost:8085/browser/
is unavailable.
This is my error from
C:\Users\Fereshteh\Desktop\neo4j-enterprise-2.2.0-windows\neo4j-enterprise-2.2.0\data\graph.db\messages
2015-04-10 01:56:42.689+0000 ERROR [o.n.s.e.EnterpriseBootstrapper]: Failed to start Neo Server on port [8085]
org.neo4j.server.ServerStartupException: Starting Neo4j Server failed: Wanted record LOG_VERSION, but this record wasn't read since the neostore didn't contain it
at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:255) ~[neo4j-server-2.2.0.jar:2.2.0]
at org.neo4j.server.Bootstrapper.start(Bootstrapper.java:117) [neo4j-server-2.2.0.jar:2.2.0]
at org.neo4j.server.Bootstrapper.main(Bootstrapper.java:69) [neo4j-server-2.2.0.jar:2.2.0]
Caused by: java.lang.IllegalStateException: Wanted record LOG_VERSION, but this record wasn't read since the neostore didn't contain it
at org.neo4j.kernel.impl.store.record.NeoStoreUtil.getValue(NeoStoreUtil.java:127) ~[neo4j-kernel-2.2.0.jar:2.2.0]
at org.neo4j.kernel.impl.store.record.NeoStoreUtil.getLogVersion(NeoStoreUtil.java:150) ~[neo4j-kernel-2.2.0.jar:2.2.0]
at org.neo4j.kernel.impl.recovery.StoreRecoverer.recoveryNeededAt(StoreRecoverer.java:57) ~[neo4j-kernel-2.2.0.jar:2.2.0]
at org.neo4j.server.preflight.PerformRecoveryIfNecessary.run(PerformRecoveryIfNecessary.java:62) ~[neo4j-server-2.2.0.jar:2.2.0]
at org.neo4j.server.preflight.PreFlightTasks.run(PreFlightTasks.java:71) ~[neo4j-server-2.2.0.jar:2.2.0]
at org.neo4j.server.AbstractNeoServer.runPreflightTasks(AbstractNeoServer.java:387) ~[neo4j-server-2.2.0.jar:2.2.0]
at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:195) ~[neo4j-server-2.2.0.jar:2.2.0]
And in my C:\Users\Fereshteh\Desktop\neo4j-enterprise-2.2.0-windows\neo4j-enterprise-2.2.0\data\log
I have just README and windows-wrapper.0.0.txt and windows-wrapper.0.0.log.lck
what should I do to be able to run Neo4j and work with it?
I have windows 7 x86
thanks in advance.
I had the same error today. In my case, it was because the files in the database directory were corrupted (I unzipped an existing graph which failed on first try). After I unzipped the existing graph database correctly - and the database files were fine - it worked. So, maybe your database directory is also corrupted.
Move the neo4j folder to another directory -> \Program'thisblankisbad'Files\ <- was the cause for me. I was trying to reinstall the service on Windows with
neo4j install-service
and neo4j threw:
neo4j Error: mainclass org.neo4j.server.startup.Neo4jCommand could not be found or loaded cause: java.lang.ClassNotFoundException: org.neo4j.server.startup.Neo4jCommand
after i moved the neo4j folder to another directory (NO BLANKS!!!) it was fine
windows 10, neo4j v4.4.9

How to ensure HSQLDB properties configuration loaded on Windows?

I have a problem with HSQLDB V2.3 on Windows. I can't connect with new databases using the HSQLDB Server.
Is there a log or debug option for the server so I can check the properties loaded and file paths, etc?
Is my properties file OK? I wasn't sure how to formulate file paths for windows.
Can I use quotes on file path names?
Is the connection string I'm using for the tmp db correct?
What's the correct syntax to use the --props server argument?
--props path
--props path/filename
I have set-up two environment variables (too keep it simple*). These variables don't have any effect except to save my typing. Initially I was loading the server from the HSQLDB folder directly.
HSQLDB_HOME ... home folder for the current HSQLDB
HSQLDB_DATA ... folder for data repository
I am following the the steps from:
Running and Using HSQLDB
Every time I connect via the server it makes a database called, "test" instead of letting me connect to either of the two databases specified in the server.properties.
%HSQLDB_DATA%/
test.log
test.properties
test.script
test.tmp/ .......... (folder)
test.lck
I made a 'server.properties' file in:
%HSQLDB_HOME%/lib/
where the HSQLDB JAR file is. I want two databases: tmp and dev:
# -- tmp
server.database.0=file:hsqldb/tmp_db/tmp
server.dbname.0=tmp_db
#
####
#
# -- dev
server.database.1=file:r:/.data/hsqldb/dev_db/dev
server.dbname.1=dev_db
I expected that the properties file to be enough to set-up two databases. When I run the hsqldb manager I don't get a connection for tmp say:
"jdbc:hsqldb:hsql://localhost/tmp"
user: SA, password: ""
I get a pop-up error:
database alias does not exist (Manager)
[Thread[HSQLDB Connection #26827674,5,HSQLDB Connections #372f7a8d]]: database alias=tmp does not exist (Server)
I created these two manually using the cmd-line, e.g. named "tmp":
%JAVA_HOME%\bin\java.exe -classpath %HSQLDB_HOME%\lib\hsqldb.jar org.hsqldb.server.Server org.hsqldb.server.Server --database.1 file:r:/.data/hsqldb/tmp_db --dbname.1 tmp_db
And could connect and create tmp:
%HSQLDB_DATA%/tmp_db/
tmp.log
tmp.properties
tmp.script
tmp.tmp/ .......... (folder)
tmp.lck
as forecast in the documentation. When I start-up the HSQLDB Server with the aforesaid 'server.properties' file or specifying properties explicitly:
%JAVA_HOME%\bin\java.exe -classpath %HSQLDB_HOME%\lib\hsqldb.jar org.hsqldb.server.Server --trace true --props %HSQLDB_DATA%
The server will only let me connect with a database called "test" as described at the beginning of the question.
Because the properties file looks good and the in-process file connection string works,
jdbc:hsqldb:hsqldb/tmp_db/tmp
I am left considering that the server.properties file is in the wrong place or not loading for some reason. It would be wonderful if there's a way for the server to dump the properties file at start-time :-) Thanks in advance for your suggestions ...
I have found the problem. Firstly, thanks to this tutorial:
HSQLDB Installation
After reviewing this I realised my error.
The server.properties file must be in the current folder when the server script runs. I had read that on the Running and Using HSQLDB manual page but misinterpreted its meaning and I put the properties file in my %HSQLDB_HOME%/lib folder. Oops.
When you look at the BAT script, it actually changed the current folder to be the %HSQLDB_HOME%/data folder ...
cd ..\data
So the default location for your server.properties file should be your: %HSQLDB_HOME%/data if you want to work with the default runServer.bat script.
For those wanting to separate data from the server software. I made an improvement for the default script using the two environment variables as follows.
HSQLDB_HOME ... home folder for the current HSQLDB
HSQLDB_DATA ... folder for data repository
runServer.bat:
#cd /d %HSQLDB_DATA%
#cd
#echo.
#rem __ #pause
%JAVA_HOME%\bin\java -classpath %HSQLDB_HOME%\lib\hsqldb.jar org.hsqldb.server.Server %1 %2 %3 %4 %5 %6 %7 %8 %9
#echo.
#pause
Which now expects my server.properties file in the %HSQL_DATA% folder. And that works. Also for my server since it is for development /testing, I'm using the --trace=true option. Like a lot of these things, now I get-it, it all makes perfect sense. Hopefully my misunderstanding will assist others who haven't found a simple tutorial before resorting to stackoverflow.

Open file in Eclipse through URL handler

In my project, I have a special JSP which displays the exception stacktrace in case of Exceptions.
Is there a way to use an URL handler or something else which would have Eclipse open a file? Maybe with xdg-open?
I use Eclipse 4.3 on Kubuntu Linux.
I've ended up with this solution:
Edit xdebug.ini (it should be somewhere like /etc/php/7.0/mods-available/xdebug.ini), add:
xdebug.file_link_format="xdebug://%f(%l)"
Restart your server or php-fpm. For Apache on Ubuntu use sudo service apache2 restart.
Create eclipse-launch.sh. It is intended to parse URL and pass a file to Eclipse. You can name it as you want and put it anywhere you want, I've placed it in the eclise directory. Be sure to replace /home/user with your actual home directory and path="..." with actual eclipse path:
#! /bin/bash
arg=$1
path="/home/user/eclipse/eclipse-neon/"
# file name directly followed by a line number in parenthesis
regex="//([^(]*)\(([0-9]+)\)"
if [[ $arg =~ $regex ]]
then
file=${BASH_REMATCH[1]}
line=${BASH_REMATCH[2]}
$path/eclipse --launcher.openFile "$file"+"$line"
else
msg="Unsupported URL: $arg"
zenity --info --text="$msg"
# alternatives:
# notify-send "$msg" # another notification program
# $path/eclipse # just run eclipse
fi
Read more about Eclipse command line options here: http://help.eclipse.org/mars/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/product_open_file.htm
Give the file executable permissions: chmod +a eclipse-launch.sh
Create xdebug.desktop at ~/.local/share/applications/. It will be used by xdg-open (Chrome uses xdg-open by default).
[Desktop Entry]
Comment=
Exec=/home/user/eclipse/eclipse-neon/eclipse-launch.sh "%u"
Icon=/home/user/eclipse/eclipse-neon/eclipse/icon.xpm
Name=Eclipse xdebug Launch
NoDisplay=false
StartupNotify=true
Terminal=0
TerminalOptions=
Type=Application
MimeType=x-scheme-handler/xdebug;
Run xdg-mime default xdebug.desktop x-scheme-handler/xdebug. This should add an entry to ~.local/share/applications/mimeapps.list to [Default Applications] section. The entry itself should look like x-scheme-handler/xdebug=xdebug.desktop
For Firefox follow instructions from here: https://xdebug.org/docs/all_settings#file_link_format
Open about:config
Add a new boolean setting network.protocol-handler.expose.xdebug and set it to false
The first time you click on xdebug:/// link Firefox will prompt you to select an application to run, point to the created eclipse-launch.sh file.

Categories

Resources