Apache PHP script to Start Tomcat Server in Linux - php

I made a php script to start Tomcat Server (catalina.sh start) thats works well from command line in Linux. It was run as ROOT with a different set of ENV.
However, I would like to do the same from the Web, Please note due to security issues, this script would only be accesible via localhost (for administration only), so we ironed out the security issue.
Problem is, Tomcat is not starting (we could confirm that from the logs, nothing was initiated). We coded lots of Echo around catalina.sh and its providing the right echo output.
Im sure theres an easier way to do this. Any Ideas?
The PHP script does the following:
Changes Dir to th Tomcat Bin
Starts Catalina.sh Script vis startup.sh
OUTPUT FROM COMMAND LINE PRINT ENV:
ORBIT_SOCKETDIR=/tmp/orbit-root
HOSTNAME=localhost.localdomain
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
XDG_SESSION_COOKIE=c111d8f81ff89709b78252c50000000d-1338310776.433586-1797694621
GTK_RC_FILES=/etc/gtk/gtkrc:/root/.gtkrc-1.2-gnome2
WINDOWID=73400323
QTDIR=/usr/lib/qt-3.3
QTINC=/usr/lib/qt-3.3/include
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
SSH_AUTH_SOCK=/tmp/keyring-bsFAQz/socket.ssh
GNOME_KEYRING_SOCKET=/tmp/keyring-bsFAQz/socket
USERNAME=root
SESSION_MANAGER=local/unix:#/tmp/.ICE-unix/1788,unix/unix:/tmp/.ICE-unix/1788
PATH=/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
MAIL=/var/spool/mail/root
DESKTOP_SESSION=gnome
PWD=/programs/tomcat/bin
GDM_KEYBOARD_LAYOUT=us
GNOME_KEYRING_PID=1779
LANG=en_US.UTF-8
GDM_LANG=en_US.UTF-8
GDMSESSION=gnome
HISTCONTROL=ignoredups
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SHLVL=3
HOME=/root
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
LOGNAME=root
QTLIB=/usr/lib/qt-3.3/lib
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-9HtQtRhCr9,guid=e1755bf07ea8a916f0a4e3f70000001c
LESSOPEN=|/usr/bin/lesspipe.sh %s
WINDOWPATH=1
DISPLAY=:0.0
G_BROKEN_FILENAMES=1
COLORTERM=gnome-terminal
XAUTHORITY=/var/run/gdm/auth-for-root-IT2DiY/database
_=/usr/bin/printenv
OUTPUT FROM APACHE PRINT ENV:
TERM=xterm
PATH=/sbin:/usr/sbin:/bin:/usr/bin
PWD=/programs/tomcat/bin
LANG=C
SHLVL=4
_=/usr/bin/printenv

try using exec()
exec('full path to your script')

Related

"-1" file created in app root directory when running php artisan

I am running Laravel on Homestead, and whenever I run any php artisan XXX command, the file named -1 is created in the root directory of the app.
Contents of the file are similar to these ones:
Log opened at 2017-12-22 13:54:00
I: Connecting to configured address/port: 10.0.2.2:9000.
E: Time-out connecting to client. :-(
Log closed at 2017-12-22 13:54:00
I am 99% sure it is related some changes I made in my failed attempts to make XDebug breakpoints work with artisan commands. I have exported some shell variables, as recommended in this answer, but when I run export -p I don't see any of them.
Did anyone have a similar issue? What setting can be causing such behavior?
Following the suggestion of LazyOne, I found the answer:
It seems that paths in .ini file have to be absolute. So instead of:
xdebug.remote_log=~/code/xdebug.log
I had to set it to:
xdebug.remote_log=/home/vagrant/code/xdebug.log
and now it works as supposed to.

php command is not recognized in wamp

I'm working on websocket. I came across this article, and simply downloaded their file and try running it in my localhost.
https://www.sanwebe.com/2013/05/chat-using-websocket-php-socket
What I understand is, they want to sue local server's websocket server.
But I have problem in starting up the server. I'm using windows 10 with wamp 2.2. As I checked webscket is enabled in my php.ini's extention.
I followed this example to cmd the right path to start it but to no avail:
https://www.sanwebe.com/2013/05/chat-using-websocket-php-socket/comment-page-1#comment-5593
It says 'php.exe' is not recognized as an internal or external ...
I then searched online again, thus set the path to my php folder in the system's environment variable. The path is: C:\wamp\bin\php. Then I closed the cmd and relaunched. Nothing worked out. The same error shows up.
This is what I did on cmd:
1) cd C:\wamp\bin\php
2) php.exe -q C:\projects\myfolder\server.php
Please help me to connect to wamp server's websocket to run the example I've downloaded.In the console, the error shown is:
WebSocket connection to 'ws://localhost:9000/demo/server.php' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
I found the answer from this site: http://rodrixar.blogspot.my/2011/07/how-to-run-php-sockets-in-wamp.html
I did the following,
1) open cmd
2) cd C:\wamp\bin\php\php5.6.19
3)php.exe -q C:\projects\mysite\server.php
4) Firewall open up and allow access for CLI
5) now connection made already..

MySQL Database won't start in XAMPP Manager-osx

I downloaded XAMPP about a month ago and it was working just fine. Today I installed a voice recognition software and then restarted my computer. Ever since, MySQL won't start in my manager-osx application. It doesn't throw me an in the application log. This is what it says:
Stopping all servers...
Stopping Apache Web Server...
/Applications/XAMPP/xamppfiles/apache2/scripts/ctl.sh : httpd stopped
Stopping ProFTPD...
Checking syntax of configuration file
/Applications/XAMPP/xamppfiles/proftpd/scripts/ctl.sh : proftpd stopped
Restarting all servers...
Starting MySQL Database...
Starting Apache Web Server...
/Applications/XAMPP/xamppfiles/apache2/scripts/ctl.sh : httpd started
Starting ProFTPD...
Checking syntax of configuration file
/Applications/XAMPP/xamppfiles/proftpd/scripts/ctl.sh : proftpd started
Both my ProFTPD and my Apache Web Server are running. MySQL isn't.
When I go to phpmyadmin, it throws me this error message.
#2002 - No such file or directory
The server is not responding (or the local server's socket is not correctly configured).
Please help me. I have no idea what to do.
UPDATE:
After looking around the internet a bit, I found a similar problem a user had with MAMP, another user recommended killing the mysql process, what ever that means. Could this be a fix to my problem?
UPDATE 2:
I found the answer to my problem but I can't answer it yet. So here's the answer:
1) Open terminal and type
sudo su
and then put in your password
2) Then type
ps aux | grep mysql
(just copy and paste this)
3) You will need to get the process id of mysql. There should be number near the top, something like 739 or 8827
4) Kill the process using
kill -9 {process id}
this should look something like this: kill -9 739
5) Restart MySQL in manager-osx
This should work:
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
Minimal Guide
1.
sudo killall mysqld
2.
manager-osx > start mysql
If that didn't work...
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
Google the error...
Examples:
Error:
ERROR! The server quit without updating PID file (/Applications/XAMPP/xamppfiles/var/mysql/<computername>.local.pid)
My Solution:
In /Applications/XAMPP/xamppfiles/etc/my.cnf change user = <uid> s that <uid> is uid from id command.
$ id
uid=...
$ vim /Applications/XAMPP/xamppfiles/etc/my.cnf
...
If these commands don't work for you:
sudo killall mysqld
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
Try this:
For XAMPP 7.1.1-0, I changed the port number from 3306 to 3307.
Click on Manage Servers
Select MySQL Database
Click on Configure on your right
Change your port number to 3307
Click OK
Close your Control Panel and relaunch it.
You are now good to go.
check the err log on your /Applications/XAMPP/xamppfiles/var/mysql/ with filename like your_machine_name.local.err, if you find something like: "Attempted to open a previously opened tablespace. Previous tablespace ... uses space ID"
the following works for me:
edit file:
/Applications/XAMPP/xamppfiles/etc/my.cnf
find the [mysqld] section, add one line:
innodb_force_recovery = 1
then run
sudo /Applications/XAMPP/bin/mysql.server start
everything is ok again.
and then the last step:
edit the my.cnf again and remove the line you just added :
innodb_force_recovery = 1
and restart mysql again. Otherwise all your tables will be read only
Try running these two commands in the terminal:
sudo killall mysqld
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
For me the following worked: Change permission into 'read only' for 'everyone' to the file /Applications/XAMPP/xamppfiles/etc/my.cnf. Then start MySQL from XAMPP manager.
close XAMPP control
sudo killall mysqld
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
it happened to me. and
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
not work for me.
so, i reinstall the xampp, then fix it.
attention:
reinstall the xampp, will not delete mysql data, no need to worry about that.
I first couldn't manage to kill mysql daemon with the commands posted here. So I remembered my linux times and did the following:
I monitored the running processes by running top in one terminal window. Then I killed mysqld via sudo killall mysqld (screw the PID ;-) ) in another and restarted via sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start.
There's been a lot of answer, but I think I found what is causing it, at least for me. It looks like if you put your computer to sleep (or it falls asleep on its own), when it reopens, it tries to open the the mysql process again. At one point I looked at my activity monitor and I had 5 instances running - killing all of them and then starting mysql works.
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
This worked for me.
I had success with easy killing all active mysql processes in Monitor Activity tool:
1) close XAMPP control
2) open Monitor Activity
3) select filter for All processes (default is My processes)
4) search for: mysql
5) force quit all the mysql
6) relaunch XAMPP control and launch apache again
Enjoy
try these two line from terminal
sudo killall mysqld
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
on
macOs High Sierra
if mysql is not getting started from manager- oxs and have tried direct command i.e
sudo /Applications/XAMPP/bin/mysql.server start
too than
go to path edit
/Applications/XAMPP/xamppfiles/etc/
find file :
my.cnf
edit it
under the [mysqld] section, add following line:
innodb_force_recovery = 1
after it save and run or can be done from manager-osx
sudo /Applications/XAMPP/bin/mysql.server start
it should start the mysql.
once its run you need to again
edit the
my.cnf
file and remove the line just added
innodb_force_recovery = 1
stop and start mysql again. by command
sudo /Applications/XAMPP/bin/mysql.server start
or
by manager-osx
it will be working fine.
It can cause because of the software you installed or may be any other software which is using the same port 3306. This 3306 port is used by the Mysql in XAMPP. Similar kind of problem I faced for Apache. I was running skype and trying to run the XAMPP but the skype uses the same port as Apache so it was not working. Then I sign out from skype then the port was free and the apache started. So you should look for the software in you laptop which is blocking or making busy this port. Free that port by closing the software and then run XAMPP and It will work.
What I did was the following: In XAMPP Control Panel I edited the my.ini file of configuration of MySql and changed the port from 3306 to 3307 and it worked, hope it helped!
Edit: after you save this changes be sure that the service is off and then restart the service. I had this same problem when I installed MySQL, it's just the port.
I encountered this problem just now. I checked log file and found it is caused by the server was not shutdown correctly. So I found this http://rivenlinux.info/how-to-recover-innodb-corruption-for-mysql/ and add a simple configuration "innodb_force_recovery = 1" in [mysqld] in my.cnf. Then the problem was solved.
The log file is located /Applications/XAMPP/xamppfiles/var/mysql and it named accroding to your server name. Just link this XXX-MacBook-Pro.local.err
All the answers stated above in relation to changing the port number are in this situation the best way to solve this problem since you need your voice recognition software to coexist with MAMP. However, you must remember that changing this port number is going to affect all you subsequent connections to MySQL (i.e, terminal,php code,phpmyadmin,etc). Hence It would be advisable to change the port on which the voice recognition software runs. Hope this was helpful.
:)
if you are getting this error
.............ERROR! The server quit without updating PID file
Try this
Go to /Applications/XAMPP/xamppfiles/var/mysql/
if there is no file with the name Your_Username.local.pid
Your_Username should replace with your Mac Username
Create a file with this name
Then try
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
its worked for me
It had the same problem, all I did was give read-only permissions for ALL users (system included) and all items included in the following folders:
/Applications/XAMPP/xamppfiles/etc
/Applications/XAMPP/xamppfiles/sbin
and relaunch XAMPP control and launch mysql server again
or
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
I have same problem and get this error in hostname.err in directory /Applications/XAMPP/xamppfiles/var/mysql
2016-09-06 15:32:45 140735322399488 [Note] Plugin 'FEEDBACK' is
disabled. 2016-09-06 15:32:45 140735322399488 [Note] Heuristic crash
recovery mode 2016-09-06 15:32:45 140735322399488 [Note] Please
restart mysqld without --tc-heuristic-recover 2016-09-06 15:32:45
140735322399488 [ERROR] Can't init tc log 2016-09-06 15:32:45
140735322399488 [ERROR] Aborting
2016-09-06 15:32:48 20004 mysqld_safe mysqld from pid file
/Applications/XAMPP/xamppfiles/var/mysql/hostname.pid ended
Then I removed tc.log and It works fine after restart mysql through manager-osx
This could be due to the fact that another instance of mysqd is already running in your mac-book-pro (MacOs-10). It's next to impossible to kill/pkill mysqld or ....I tried that route many times, with out any success. Finally the following worked for me :
launchctl unload -w /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
wait a few minutes and check with
ps -ef|grep mysqld
It should be gone!
It might be the possibility that your voice recognition software has a installer of mysql internally and when u installed this software, it has installed mysql too and added it to the service and this mysql service starts once your system starts. So now u r having two mysql servers (one from voice recognition software and second is from XAMPP) that's why killing the previous process (mysql service) solved your problem. But this is not a permanent solution, you have to repeat it every time when ever you start your machine. So better is to find out that mysql server (service) and change its port no. OR change settings so that mysql service should not start when your machine start (but might be your voice recognition software won't work properly)
I hope it will help you.
Cheers
You seem to have found a work-around by killing the process, but make sure you check for free space on your MySQL partition. If your logs or db files are consuming all your drive space, mysqld will not start.
Restarting the computer, or using the 'kill' commands listed above solve the problem. AS for preventing it from happening, I've found this occurring anytime my computer goes to sleep. The port is obviously kept reserved, and then on wake, mysql tries to reconnect to that port, but can't. This could be your problem also.
I am running XAMPP 5.6.3-0 for OS X Yosemite 10.10.2 and ran into the same issue twice, the first time was with Mavericks. With a bunch of different solutions to the issue with MySQL Database not starting using Manager App I wanted to confirm what had worked for me. The workaround that always worked and forced MySQL to start was by opening Terminal and using:
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
I had the Manager App open and started ProFTPD and Apache and then ran the sudo command.
The other suggestion by wishap that worked was to locate /Applications/XAMPP/xamppfiles/etc/my.cnf file and change the permissions for "everyone" to Read only.
The other problem I had that seems to be another issue with many solutions is the problem after everything is started then entering localhost which brings me to the xampp splash screen and then nothing. The only thing that worked for me, to at the very least, to access the phpMyAdmin page is by entering localhost/phpmyadmin
I hope this helps others reading through a bunch of threads for an answer.
Regards,
Erik
Try this, sudo service mysql stop it will stop any other mysql services and then restart xampp
Just Click on Managed Servers Tab in XAMPP MANAGER , Now select MySQL Database, Click on configure on right side.
Change port from 3306 to 3307 and it will work.
It had the same problem, all I did was give read-only permissions for all users and all items included in the following folders:
/Applications/XAMPP/xamppfiles/etc
/Applications/XAMPP/xamppfiles/sbin
Well, sometime there is just ERROR! message is shown in mysql comment on terminal.
Then, just reinstall (overwrite) XAMPP, then it can be solved.

$PATH environment variable for apache2 on mac

I am trying to get apache/php to recognize the path to my git. I have been researching and looking in all corners of the web and cannot find how to do this. Basically, no matter what I try, when I run echo phpinfo(); the Apache Environment path does not change from /usr/bin:/bin:/usr/sbin:/sbin. And when I run system('echo $PATH'); in PHP, it reads the same.
System Information:
Mac OSX (Lion)
Apache 2 (running as _www)
PHP 5.3.6
Here is what I have tried editing so far:
/etc/profile
~/.bash_profile
~/.profile
/etc/path
/etc/path.d/{NEW_FILE}
Nothing I have tried so far has changed the $PATH variable. Any ideas?
SOLUTION
So here is the final solution. I edited the
/System/Library/LaunchDaemons/org.apache.httpd.plist
and added
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin</string>
</dict>
You can set the PATH environment variable in /System/Library/LaunchDaemons/org.apache.httpd.plist.
More in the docs.
Did you update the PATH environment variable of user '_www'? Apache will read environment variables from the user runs itself. Or, it looks like you didn't restart apache after updating PATH environment variable.
Check out the older discussion :
How do I add paths to the Apache PATH variable?
Setting environment variables in OS X?
And if you want to modify environment variable in PHP, getenv() and putenv() can be a better choice.
getenv : http://php.net/manual/en/function.getenv.php
putenv : http://www.php.net/manual/en/function.putenv.php
$path = getenv('PATH');
putenv( "PATH=$path:/new_path_that_you_want_to_add" );
Important note for El Capitan (Apologies for the new answer - I don't have enough Rep to comment)
On OSX 10.11, the /System/Library folder is protected, so the files can't be edited.
You need to:
Reboot into Recovery Mode (hold CMD + r after the startup sound)
Once in recovery mode, go to Utilities > Terminal
Run:
csrutil disable
Reboot back into OSX - you should now be able to change the files
Once done, go back to recovery mode and run
csrutil enable
Hope that helps
I created this gist that helped me out from the information above:
https://gist.github.com/srayhunter/5208619
My problem was that PHP was not finding a program that we had installed under /usr/local/bin. Once we did the above it all worked and played nice on mac osx.
for ubuntu server, in /etc/apache2/envvars,
for centos server, in /etc/sysconfig/httpd,
to add:
export PATH=<your php cli path>
and restart apache
A similar problem to what I was having installing Derby. The way I solved it was by opening TextEdit. Select File > Open at this point press Shift + Command + . , this will allow you to view all the documents. Head to the user directory and search for a file called ".profile" . Open it and add the export VARIABLE= Value line for example:
export DERBY_HOME=/opt/local/share/java/derby/
Save the document and restart your terminal to see if the changes went into affect.

PHP cli command line safe_mode restriction

I'm using the Kohana framework (3.0.9), which generates daily logs. I want to mail the log file if one was made the day before CRON runs the script, but after days trying I can't figure out how to put off safe_mode in PHP CLI modus.
When I'm running my script on the web, there is no problem. But I want to run the script as a CRON task on my Plesk 9.5.2 server (or on the command line as root user) I'm getting the following error:
ErrorException [ 2 ]: dir(): SAFE MODE Restriction in effect. The script whose uid is 10001 is not allowed to access /var/www/vhosts/mydomain.com/subdomains/mysubdomain/httpdocs/application/logs/2011/01 owned by uid 48 ~ APPPATH/classes/controller/ajax.php [ 181 ]
I've allready put SAFE MODE off in my Plesk control panel, which works fine for the web request, but not in on the command line or as an CRON task.
I'm using the following code to test if its working:
$d = dir(APPPATH.'logs/2011/01/');
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
echo $entry."\n";
}
$d->close();
I can read the directory APPPATH.'logs/', and also the directory APPPATH.'logs/2011', but the directory's representing each month with the daily log files always give an error.
At nowadays you can schedule php script execution from UI like this:
In case you still need execute script via command line pay attention that Plesk's PHP binaries are placed in:
# 7.0
/opt/plesk/php/7.0/bin/php
# 5.6
/opt/plesk/php/5.6/bin/php
# 5.5
/opt/plesk/php/5.5/bin/php
# and so on
Original answer:
I know this is a few months old, but for the next person that comes across a problem while using Plesk and cron and PHP, here's the answer.
While Plesk does run cron as ROOT, it also runs PHP by default with safe mode ON, which means that when you setup a cron in Plesk that needs PHP, it's going to have restrictions that you do not experience from the shell or from the web.
So what you do is use the CLI /etc/php.ini option override, like so:
/usr/bin/php -q -d safe_mode=Off /var/www/vhosts/path-to-your-php-file.php
Have you disabled safe_mode in the php.ini for CLI?
You can find the location of this file by running the following command php --ini. Search for safe_mode in this file and change the line to safe_mode = Off.

Categories