How to make xampp automatically update the localhost - php

I honestly don't have a clue what to put here... I have searched all over the web and can't seem to find anything useful :(
I am looking to make a website, but then I would like it to update each time I write something in the notepad (or at least when I save it) so I don't have to manually press F5 in my browser each time.
Does anyone know how to do so?

This is going to refresh your page every 10 seconds or whatever amount of milliseconds you input, but that is usually a bad solution, but it is easy and works! Hope this helps, dont forget to remove or disable it when you are done!
setInterval(function(){location.reload(true);}, 10000);

Prepros solved my problem.
PrePros
Open PHP project folder in Prepros
Goto Server options and Select External Server
Check Use External Server option and paste the Xampp Project Url.
:)

here is a free solution for you
you need to:
First install nodejs from nodejs official website,
Then go to your windows command prompt and install browser-sync by writing the following code npm install -g browser-sync, where npm is node js package manager, -g is for global
Then you open the folder you want browser-sync to follow refresh updates in your terminal or command prompt and write the following code browser-sync start --server --files <files which browser-sync wants to follow and refresh for you> some files like *.html *.css css/*.css *.js dont put commas in between
one thing you need to remember is that you need to write the last command every time you want browser-sync
happy codding :)

You can build a php script which check if your files are updated then you create an infinite loop or a timed loop on the client side to request this script. If it returns true (updated), you reload your page.
Theoricaly, it works but I discourage you to do it. It will consume a lot of cpu and will not be really usefull...

Related

Do i really have to restart the server everytime i made changes?

i want to use AMP PHP and create a Project. So i started with one of the examples on github and i can see hello world.
Now if i make changes to my code, i have to restart everytime the server. but this is not how it should work right?
Do i have to run some kind of filewatcher which restarts the server everytime i change the code? or should the AMP PHP Server work as Proxy which then call php-fpm instances like an NGINX server would do? If so, can i use the async libraries without the Loop? (since the loop is on server)
How to work the framework? it seems that i understand here something wrong.
Best regards
Yes, you'll need to restart the server on changes. You can use a file watcher to do this automatically. PHP doesn't provide a hotreload feature currently.
You can't use cooperative multitasking without a scheduler / event loop, no.

PHP XAMPP Restart Apache Through Browser

I'm trying to create a WHM / Plesk Type Control Panel for my Clients to use. I am running XAMPP on a VPS and want users to be able to, for example, ban IP's however for the change to take effect Apache needs to be restarted.
Is there a way using PHP the user can click a button and the Apache Service will restart?
I have tried using the following PHP code but all this does is Stop the Apache Server, it doesn't bring it back up?
<?php shell_exec("apache_stop.bat"); ?>
<?php shell_exec("apache_start.bat"); ?>
Both bat files are in the same directory as the php file and I have amended them so that the files are relative to them by adding this ..\..\ to the file paths.
Is there one file that I can run that will do both tasks automatically or is there a better way to do this?
After you stop apache, it exit and do not start second job. You may use script that get this two jobs
You cannot restart Apache from a script. When the first shell_exec is called, the server process ends, and so the second call will never be made.
As an alternative, I suggest you ban devices/IPs using PHP - perhaps save them in a text-file or database and check from there.
Or, you can refer to the answers given for this question.

PHP Git Pull from GitHub Script SSH

This is the first time I've tried to use the GitHub service hooks to automatically deploy to my server; and after slowly working my way over every obstacle it looks like the very last one is the one that has done me in.
The initial clone of my git repository onto my web server was done through SSH, and I'm pretty sure that has something to do with my problems now. My current script is the basic:
<?php
echo(shell_exec('git pull 2>&1'));
?>
But it returns "Permission denied (publickey). fatal: The remote end hung up unexpectedly"; which I know is where the script is failing to put in the SSH pass phrase I created. I tried doing research on how to maybe get past it, but I don't even know if those would be the correct/securest things to do.
So can this be modified to work from here or do I need to backtrack a few steps and step away from using SSH to begin with?
Thanks
Can you try to replace (in your git.config file )
ssh://github.com/<username>/<project>.git
or
https://github.com/<username>/<project>.git
with
git#github.com:<username>/<project>
Apache is probably running as a different user than the one you normally run git with via the CLI. You'll probably need to copy your .ssh/id_rsa file from /home/regularuser/ to /home/webuser/.

Unable to call system commands and shell scripts from PHP Fedora 10

I am working on an application that runs locally on a Fedora 10 machine through PHP and Apache. It depends on a process that runs in the background.
The higher-ups want to be able to start/stop/restart the process, through the browser. I was trying to get this to work by having PHP make calls to the system using exec() and shell_exec, but it doesn't seem to work.
When I try to start the process using "exec('processName')", nothing happens.
When I try to use "exec('killall processName')", SELinux starts constantly popping up warnings that the process was permitted (because I put it into permissive mode), however it doesn't actually kill the process! But this seems to go on even after the page is fully loaded!?!?
I AM able to call another script in a similar fashion: "exec('/var/www/cgi-bin/ControlProgram START')". So I'm not really sure what the major differences are between the two calls/commands.
I also put the script call into the /etc/rc.local file to have the script run at login. However, will I be able to kill this script from PHP since its run by... the system?
I'm not a guru when it comes to permissions/SELinux, so don't spare on the gory details! Thanks in advance!
If you have administrative control over this system you will want to check the PHP configuration (make sure it is the config profile for the web server).
Safe_Mode will prevent PHP from executing anything outside a particular folder. In a shared hosting environment, this usually means you can only execute things that are relative to your home/www folder--which seems to be the case based on your notes.
I believe I found the problem. I'm still not exactly sure what the problem is, but it looks like it has something to do with file/directory permissions. When I moved the scripts into my /var/www/html directory, the scripts ran. I moved them into /var/www/cgi-bin and they work there too. So it might be something where apache can't execute scripts that are outside the /var/www directory, or at least it can't do it directly. Thanks for your help though!
It sounds like old school unix permissions and how apache operates. I do recall (though it has been some time) that apache is careful on what it will execute. Double check your octals.
To verify that it isn't SELinux you can disable it instead of putting it in permissive. though this will cause a file system relabel (or should). At that point your extended attributes with the SELinux contexts could get out of wack and cause SELinux problems once in enforcing again.

Can PHP restart Apache?

I have a local server which needs to make changes to a virtual hosts apache config file and then restart apache so the new config takes effect.
Can PHP do this? I tried passthru and exec but they didn't work. Maybe the problem is that I'm trying to restart PHP's parent process?
Thanks for any help!!
I've used a cron script (written in PHP, not executed from the webserver) to check a server is up and restart the server.
However, I wouldn't do this from a server-created process, because you know you're about to kill the parent process, which has bad implications for the child.
The simplest method would be to have a file /tmp/RESTART_APACHE which PHP can create, and which the cron script checks for. If the cron script sees the file /tmp/RESTART_APACHE then it does a proper restart of Apache.
Using a cron script will introduce a delay (up to 60s if you run it each minute), but apart from that should work as you want.
Depending on how you intend using this, that may do the trick.
(You probably want to use a different directory than /tmp/ to set permissions and prevent anyone on the server being able to create the file.)
EDIT: Please see Aaron H's comment to this post. I agree with what he says: you really do want to be careful that the ability to restart your webserver is not a service generally available to the public.
Restrict access to the system which can trigger the restart; ensure that the file which triggers the restart has restrictive permissions so only the web process can create that file, and generally be smart.
I've done this for the very exactly thing. However it was solely for a development environment, to quickly create virtual host for our developers on demand. Worked very pleasing well so far.
My approach was to create a new user on the system, give this user sudo rights to reload apache and from Apache->PHP I used SSH to localhost with an authorized key without passphrase to that user, issuing the command.
The reason for this was that I didn't wanted to give the apache user (usually www-data) the power in general to reload itself. I named the new user wwwctrl.
The command I used was:
ssh -i /path/to/key-file wwwctrl#localhost sudo /etc/init.d/apache2 reload
I had to execute this command manually one time as wwwctrl user to have the local host key being added to ~wwwctrl/.ssh/known_hosts.
I used proc_open() to watch the execution of the command.
In fact I was generating a batch of virtual hosts for different Apache installations on different systems so on every system I had this wwwctrl user to reload Apache, basically doing this in a "foreach hosts as host do ... wwwctrl#host#".
Wouldn't you want to pass a 'reload' instead of a 'restart?'
To do this you would need to edit the sudo file and then execute the restart command that is used on your system, using sudo of course. If you give details, I could tell you but do you even have access to do that? Is it hosted? Cron would probably be a better choice here though.
at will be able to do that, not sure if you can schedule down to the second but I guess that depends on the implementation
I would create a daemon to monitor the sites-enabled directory and restart Apache when files are added or modified. Then you don't have to wait up to 60 seconds as with a cron job.
This sorta thing violates the standard chain of command since apache invokes php, not the other way around. I second the cron suggestion. Just set a cron job with sufficient privileges to check for changes to the host file, and restart apache if any are found.

Categories