I have a wordpress website (I can make a new one if its not compatible) I want to send a command from there to my remote ubuntu server how would I do this.
Your issue will be that to start the service you need escalated privileges. You'll need to add an exception to your sudoers.
You could add something like this to /etc/sudoers.d/mycommand
Defaults:www-data !requiretty
Cmnd_Alias MYCOMMAND = /usr/bin/service myservice start
www-data ALL=(ALL) NOPASSWD:MYCOMMAND
Then you can use a php command such as
exec("/usr/bin/sudo /usr/bin/service myservice start");
Related
create a cmd process and call netstat may get listening ports, but it's complicated and create may be slowly, any build-in method can does this?
I found IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners(), but this will return all tcp listener and without process info.
There is a way to get current Address:Port, which i figure out, while starting the project.
The critical thing is that you must define at least once 'ASPNETCORE_URLS' somehow from out-source. If you dont do that .net core doesn't set DefaultEnpoints which causes unreachable address:port directly.
Startup.cs
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
String ServerAddress = app.ServerFeatures.Get<IServerAddressesFeature>().Addresses.FirstOrDefault();
Console.WriteLine($"ServerInfo: {ServerAddress}");
...
}
CMD (Windows)
set ASPNETCORE_URLS = http://localhost:2020 && dotnet MyProject.dll
Docker
docker run --rm -it -p 2020:80 -e ASPNETCORE_URLS="http://localhost:2020" MyProjectImage
note:
if try without using environment variable(ASPNETCORE_URLS), you will see empty Addresses collection
I am already running ngnix as root user in my redhat server. but I want to run ngnix as non root user now because of some security concerns.
Please help me to do it.
Thanks
youll need an user nginx with the specified rights or you use the existing group www-data. In either your service or your upstart file you need to specifie the user .
service / init
use sudo -u <username> <cmd>
systemd / upstart
There are options like group=
But we will need more informations about your system. is there alrady a service file? A redhat version number? Can you post your service file
I have symfony2 project which I moved from a shared host to a VPS. I had a cron job command working in the shared host but I am unable to make it work in the VPS (WHM/cpanel CentOs 6).
The command I used in cpanel in the shared host was:
/usr/local/php-5.6.12/bin/php /home/a155r66t/public_html/mydomain.com/app/console api:import
In the VPS the route to the Symfony command is /home/mydomain.com/app/console api:import but I am unable to find which would be the route to the php in VPS. I tried these with no success:
/usr/local/php-5.5.29/bin/php /home/mydomain.com/app/console api:import
/usr/bin/php
/usr/local/bin/php
root php
Can you please indicate how could i find the correct route to the php? Or what should it be? Thanks.
Finally, with some good help I managed to sort it out. The correct sentence for the cron task in my VPS is: php /home/mydomain/app/console api:import
I create Fedora instance in horizon by giving public key. But i didn't get any user and password to ssh the instance. Also tried to create instance from shell by running this,
nova boot --config-drive=true --flavor 3 --key-name testkey --image be1437b9-b7b4-4e56-a2c3-f92cdd0848ce --user-data cloud-config.txt test
Instance launched successfully in both case and when i try to login with root it ask me for password.
So please tell me what is the exact way to create a fedora instance in Openstack and what would be its user and password for ssh.
Just to confirm, I suppose that you have the corresponding .pem file for the keyname that you create (testkey) and this file has the appropriate permissions to be used to access using ssh. I mean chmod 600 of the .pem file.
If this is the case, you should go into the instance only executing the following sentence:
ssh -i testkey.pem root#<IP address>
Have you installed cloud-init package from epel repository?
So, you can get into the server using 'fedora' or 'cloud-user' user account.
http://docs.openstack.org/image-guide/content/ch_obtaining_images.html
Let leave cloud-init option in nova boot, I have also tried this one,
nova boot --flavor 3 --key-name testkey --image be1437b9-b7b4-4e56-a2c3-f92cdd0848ce test
In this command Instance launches successfully, but still I can't ssh the instance.
Where as now when I create instance from horizon I do ssh in that instance easily.
For the first time login it is recommended that you generate a key-pair (In ubuntu, https://help.ubuntu.com/community/SSH/OpenSSH/Keys) and inject into the image (http://docs.openstack.org/grizzly/basic-install/yum/content/basic-install_operate.html) and do SSH to the instance using the key-pair. Once you are logged in, you can create a user and using this user you can login through VNC console.
I am using Symfony and creating a soft with 3 tiers (client, apache, mysql). So I don't know how to get the statut when the symfony application persists and flushs something?
When I add something in database I display an alert like "Add done!" but if my database is down I will display "Add done" despite the fail...
So how can I get the statut of these functions (flush/persist)? How can I change my alert switch the statut?
Best regards,
Use a try & catch block:
try {
$article = new Article(); //Example entity
$em = $this->getDoctrine()->getEntityManager();
$em->persist($article);
$em->flush();
$this->get('session')->setFlash('flash_key',"Add done!");
} catch (Exception $e) {
$this->get('session')->setFlash('flash_key',"Add not done: " . $e->getMessage());
}
In case you get errors try using "\Doctrine\ORM\ORMException $e", \Doctrine\DBAL\DBALException $e" or "\Exception $e" inside catch()
My issue was that I was passing a complex object into a field that expected a string even though I had set that column up to be a ManyToOne. Apparently #ORM\Column overrode that.
However! It's not what the error was that's interesting, it's how I fixed it.
I was having a PDOException. I had to deep dive into the code with xdebug and PHPStorm. xdebug is supported by many PHP IDEs. xdebug is tough to set up the first several times that you set it up. There's always some firewall hassle or hassle getting it to show up in your phpinfo() or xdebug.enable_remote or xdebug.remote_host.
Get used to it. JUST DO IT! No seriously. Don't write another line of code in PHP until you have got xdebug working; even if you run into 8 million issues. You will save years of your life in coding.
I don't know about Symfony, but ZF3 now comes with a Vagrantfile. You install vagrant and Oracle VirtualBox, type vangrant up in your Zf3 project directory, and you have a fully-functional local web server running your ZF3 application at http://localhost:8080. From there all I had to do was:
... Well first, before I called vagrant up for the first time, I added the following line to the Vagrantfile
config.vm.network "private_network", ip: "192.168.33.10" ... then I called vagrant up
vangrant ssh
sudo -s
apt-get install php-xdebug
echo "xdebug.remote_enable = 1" >> /etc/php/7.0/apache2/php.ini
echo "xdebug.remote_host = 192.168.33.1" >> /etc/php/7.0/apache2/php.ini
apachectl restart
In your phpinfo(), you should see xdebug somwhere. Just ctrl + f for it. If it's there, you're mostly in business.
Then I added a rule for port 9000 on my firewall. Then I started an xdebug session. If it doesn't work You can temporarily shut down Windows Firewall just to check if it works, but remember to enable it right away and make sure it's not just the firewall. Setup a firewall rule for incoming on port 9000 and allow ip 192.168.33.10. If you don't know how to do this ... why are you trying to develop web software?
Learn to use xdebug!!!