I'm running
nginx 1.17.4
php 7.4
arch linux 5.4.2
Trying to execute the following command to get my user MAC address from IP (this script will run on my lan server) and $_SERVER['REMOTE_ADDR'] does return a valid ip
shell_exec("sudo /usr/bin/nmap -n -sn ".$_SERVER['REMOTE_ADDR'])
But it returns null so I tried the following to get a more info
shell_exec("sudo /usr/bin/nmap -n -sn ".$_SERVER['REMOTE_ADDR'] ." 2>&1")
And got the following: sudo: effective uid is not 0, is sudo installed setuid root?
I don't understand why I get this error because I have added the following in my sudder file
http ALL=NOPASSWD: /usr/bin/nmap
I've modified my passwd to allow login from HTTP to try it in shell and it works but not when I run it in the browser.
Help please!
Thanks
since my server is arch linux I decide to go ask in that arch forum and found was able to fix my issue. so for anybody interested please view
https://bbs.archlinux.org/viewtopic.php?pid=1877560#p1877560
Basically for me it was changing the php-fpm service file to the following
/etc/systemd/system/multi-user.target.wants/php-fpm.service
Set NoNewPrivileges=false
comment CapabilityBoundingSet
I have this command and it works fine on shell.
I want to run it with php but it does not work
what i missed :
edited :
$arg="arg1"; $arg2= "arg2";
echo shell_exec("sshpass -p ".escapeshellarg($arg)." ssh -t root#00.00.00.00 'asterisk -rx ".escapeshellarg($arg2)."'");
after this change no error on output but still commande not executed
edited :
the original commande is like this :
sshpass -p 'arg1' ssh -t root#00.00.00.00 'asterisk -rx "arg2"'
and i want to around the probleme with external parameters but it does not work
If the php is running on safe mode, it won't allow to execute shell_exec as it's described in the php manual:.
https://www.php.net/manual/en/ini.sect.safe-mode.php
You can disabled the safe mode for a certain folder as it's described in the Stack Overflow question:
How to turn off php safe_mode off for a particular directory in a shared hosting environment?
Finally I found a good solution for who still search :
I installed php-ssh2 with this link (i use debian 8, php7)
blog.programster.org
and in my case i use codeigniter i follow the link to implement this class
bitbucket.org
now i can execute any commande on shell without probleme
and the probleme is solved :)
Hope its help someone :)
Following this tutorial for setting up a LEMP stack on Ubuntu 16.04, I am unable to load the default page in the browser:
https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04
I am trying to pull up the page by requesting the server IP address in the browser, i.e. typing http://server_ip_address into Chrome.
The connection times out. However, I am able to run
$ curl server_ip_address
and return the html in the terminal.
What am I doing wrong here?
Update: Resolved. Ended up being an issue with Cloudflare; had non-Cloudflare IP addresses blocked. So, there was no Nginx issue.
Check if you have the service running on the server by using: netstat -lt command
If the service is running then check if you have the security group rules against it
If both the above conditions are good then try accessing the start page on the port on which the service is running
Note:
Make sure nginx is running on port 80
Make sure you stopped apache2
(1)Run "curl" test at another host, not in the ${server_ip_address} itself.
(2)If you get the right result at step 1, then you will get the same result at chrome.
(3)Check the firewall of ${server_ip_address} host,such as:
netstat -ntpl | grep ${port_of_nginx}
iptables -L -n | grep ${port_of_nginx}
I'm having a problem starting my Laravel installation. Whenever I type in the terminal php artisan serve, I get this error:
Failed to listen on localhost:8000 (reason:une tentative d'access un
α socket de maniere interdite par ses autorisation d'access a 0t0
tent0e)
What's the problem, and how can it be fixed?
img problem http://i.imgur.com/rOt3Lat.png
it's working now I just changed the listen port from 8000 to 8888 or any other port your services didn't use it
php artisan serve --port="8888"
Fixing Error: Failed to listen on localhost:8000 (reason: Address already in use)
List processes with php in it
ps -ef | grep php
Example output
501 **9347** 393 0 1:29PM ttys000 0:00.21 php artisan serve
501 9351 **9347** 0 1:29PM ttys000 0:02.01 /usr/local/php5-5.6.14-20151002-085853/bin/php -S localhost:8000 .../laravel/server.php
501 9781 393 0 1:56PM ttys000 0:00.00 grep php
Then kill the process
kill -9 9347
Are there any other services running on port 8000?
You can use this command on Windows:
netstat -aon | more
or on Linux / OSX
sudo netstat -plnt
to see what services are running. Then disable the service that is running on port 8000 or use another port.
List process using ps -ef | grep php
Then below only works for me
kill -9 9347
which is a force kill of the process
501 9347 393 0 1:29PM ttys000 0:00.21 php artisan serve
Option 2:
If above not works, Change the default laravel serve port number if you can, like
php artisan serve --port=8088
8000 is the default port. Use instead of :
php artisan serve --port=8005
It is because something already running on that port and you can change the port by command itself, by running following command
php artisan serve --port 8001
Use killall -9 php and if you want to close other services use killall -9 node or killall -9 mysql
When php artisan serve command given, below mentioned problem occured.
macridmi1109#Ridmis-MacBook-Pro kcnk % php artisan serve
Laravel development server started on http://localhost:8000/
[Thu Aug 6 11:31:10 2020] Failed to listen on localhost:8000 (reason: Address already in use)
Then try this line of code,
macridmi1109#Ridmis-MacBook-Pro project_laravel % ps -ef | grep php
Result will be,
501 66167 1 0 11:24am ttys002 0:00.77 /usr/bin/php -S localhost:8000
/Users/macridmi1109/Documents/Laravel/project_laravel/server.php
501 66268 64261 0 11:31am ttys002 0:00.00 grep php
Finally run the below code and, then again php artisan serve
macridmi1109#Ridmis-MacBook-Pro project_laravel % kill 66167
SOLUTION EXPLAINED BELOW
I use the command, ps -ef | grep php. After that, you will be able to find Process ID. After recognising the correct Process ID, use this command kill 66167 (kill "Process ID"). Then try php artisan serve. This worked for me.
Happy Coding😊
For me, it was silly mistake. I have installed php in new machine but php.ini was missing. So, I have created php.ini file from php.ini-production file and then php artisan serve command worked fine as expected.
for me php -S localhost:8080 from the terminal in vs code will sometimes crash, but still be running in the background.
-9 to force kill did it for me
thanks #hemss
I did
php -S localhost:8080
[Wed Dec 12 13:48:03 2018] Failed to listen on localhost:8080(reason: Address already in use)
then I..
sudo netstat -plnt
find the process running on port 8080
tcp 2 0 127.0.0.1:8080 0.0.0.0:* LISTEN 10312/php
then force kill it..
kill -9 10312
I get
[1] + 10312 killed php -S localhost:8080
then restart...
php -S localhost:8080
best way if you 8000 port is busy or you have more one project running is run your project in new port such as 8088 or another free port.
php artisan serve --port=8088
The solution I found a problem we face several times in Ubuntu.
*Failed to listen on 127.0.0.1:8000 (reason: Address already in use)*
What we do, we change the port, right?
This problem can be solved also in few seconds following below steps.
1. Open Terminal
2. **sudo su**
3. **netstat -plnt**
_find the process running on port 8080_
4. **kill -9 PROCESSNUMBER**
For more details, see my blog, click here
If you have all your configurations ok in the .env file then you should:
Use the answer from mayorsanmayor in this post to kill all php processes.
Then php artisan config:clear
Finally, php artisan serve
Good luck!
I am trying to run the CLI version of this PHP databse Search and Replace Script, but I think this a more general MySQL problem relating to Mac OS X and MAMP. I receive the following error whenever I attempt to run the CLI script locally:
db: SQLSTATE[HY000] [2002] Connection refused
Here is the command I'm running:
./srdb.cli.php -h 127.0.0.1 -u root -n mydbname -proot -c utf\-8 -s mywebsite.com -r dev.mywebsite.com
What I've tried
I am able to connect to mysql using these settings, no problem, using mysql -u root -proot etc...
Swapping 127.0.0.1 for localhost gives the same error.
All my my.cnf files are blank.
Apache and MySQL are running fine.
I have succeeded in replicating this problem on another Mac running MAMP
I am using this mysql: /Applications/MAMP/Library/bin/mysql
And this php: /Applications/MAMP/bin/php/php5.3.28/bin/php
Anybody any ideas? Thanks!
Edit
Here is the source code showing how the script connects to MySQL:
https://github.com/interconnectit/Search-Replace-DB/blob/master/srdb.cli.php
which in turn imports this:
https://github.com/interconnectit/Search-Replace-DB/blob/master/srdb.class.php
As stated in my comment already, chances are that you're not running the PHP binary you thought you were running. Even if the MAMP php binary is in your path, the shebang line in srdb.cli.php reads #!/usr/bin/php and that points to the Apple-provided php binary.
So if you invoke the script with the full path to your MAMP php binary, the problem should be avoided:
/Applications/MAMP/bin/php/php5.3.28/bin/php srdb.cli.php -h 127.0.0.1 -u root -n mydbname -proot -c utf\-8 -s mywebsite.com -r dev.mywebsite.com
Another solution might be to replace the shebang line with:
#!/usr/bin/env php
This works only if the MAMP binary is in your $PATH in front of /usr/bin. Using #!/usr/bin/env phpensures however, that you're always using the same binary no matter if you're invoking the script via ./srdb.cli.php or with php srdb.cli.php.
Stop mysql :
sudo service mysql stop
And then start it :
sudo service mysql start
It resolved the problem
To add onto z80crew's brilliant solution, for anyone else unfamiliar/uncomfortable with altering path variables, specifying the full location paths for both the MAMP php binary and the search-replace-db script in the cli script provided by interconnect solved the problem for me. I put the strings to search for and replace with in quotes. I also increased the php timeout limit in wp-config.php with: set_time_limit(3000);
I was consistent with the server name between the options passed to the script and what's in my wp-config.php file (using localhost in wp-config, using localhost in the script as well)
/Applications/MAMP/bin/php/php7.4.2/bin/php /Applications/MAMP/htdocs/test/Search-Replace-DB-master/srdb.cli.php -h localhost -u root -proot --port 8889 -n test -s "http://olddomain.com" -r "http://localhost:8888/test" -v true