Secure Linux Server Setup To Run Scripts via PHP exec()? - php

I'd like to run a script (phantomJS) via php exec() or shell_exec(). Everything is working fine on my development system.
I've installed phantomJS on my production server, and have run it successfully from the terminal after logging in via SSH.
But when I run it from PHP via exec() or shell_exec(), I get messages saying:
GLIBCXX_3.xx not found
GLIBC_2.xx not found
The support team at the web hosting provider is saying they don't know how to enable the server to access the script and still maintain security:
We're not familiar with the specifics of it, so we'll either have to
go through with disabling the chroot, but as our supervisor mentioned
this will allow all accounts on the server to account with each other
which is what the chroot prevents.
You can have your own system administrators look at the setup as you
do have root access, and see if they can devise a workaround, but on
our end this is the only thing we can suggest.
They are running CentOS, which is a 64-bit Linux OS.
I have very good experience with this web host up to this time, so I'm hoping there's a way to address this without changing hosts.
I have full root access to the account, so I can configure it in any way necessary.
Can anyone make some suggestions about how I might configure my production server to access phantomJS while maintaining a secure server?
UPDATE
Apparently my app is in a "chrooted environment" without full root access to GLIB on the server. The web host is saying there will be a lack of security if my php user is given full root access.

You have to remove your PhantomJS system call and create an API layer or a service that subscribes an MQ queue and then integrate it with PHP to avoid several problems, including the chroot limitation.

Related

SOS! How do I deploy multiple Laravel apps on a windows IIS server in a LAN

I am setting up an IIS server in readiness to host multiple PHP web apps. These will be used within our local network so no need internet access. I have read a lot of stuff on how to go about it but am getting lost even more. someone please help.
You can refer to this document for detailed steps about deploy php application on IIS.
Here are some main important points:
Install IIS in control pannel(windows) or server manager(windows server).
Configure php. Youcan download it from php official website or Web PI(more recommand). The version over php8 may not work on IIS.
Make the physical path of site points to root folder of application. It will auto generate web.config. Set the permission of root folder to avoid 500 error.
If you have multiples version of php, you can isntall php manager to configure them.

PHP - Transfer file from Server to Windows PC

I have tried a few SSH and SCP snippets to transfer files from a web server to a windows pc and I can't quite get it working. There are a combination of things I believe I need such as firewall permissions, php modules, etc.
What boggles my mind is, it is so easy to ssh to a linux machine because I know the username and password but for Windows, you don't REALLY have a username and sometimes don't even have a password.
That being said, here is what I need to do. I have a linux server online and need to send a XML file to a windows pc. Out of your experiences, what are the best php modules, snippets, and any tips that you followed to achieve this? I believe the IP I would use for my windows machine would be my public ip but what in the world would the password be.. I have no pw on my computer? Do I need extra software installed on my windows pc as well?
Any help is appreciated.
Without getting into your IP potentially being dynamic.
It sounds like you need a cron job on the web server. You could then set up a FTP/SSH server on your Windows PC to receive the file.
On the other hand if this file is in a website folder which has FTP access. You could FTP to the server from your Windows pc and get the file with an FTP client.
Programs such as FTPBox could sync this for you or Curl from the command line.
With a command line program like Curl on your Windows PC you could set up a cron job on your Windows pc to automate getting this file if you want to do this automatically.
There are a few other options like a virtual linux machine on your windows pc. Then you could SSH from there and set up shared folders etc.
But to put it as simply as my experience has taken me.
If you have a webserver use FTPS and use a FTP client on your PC.
or use a command line program like Curl to automate from windows pc
From the server you need a cron job to automate the process, but you need to setup some type of server to receive this reliably. You could have a PHP file call a script file with php exec() depending on your webservers permissions.
Your router and software firewall may need to be configured to allow the ports you use for the transfer.
Easiest option is FTP server on webserver and FTP client on windows machine.
There are a few options, so I hope this has helped somewhat, I haven't taken into account a few things like security, automation, permissions etc. So none of these could be your best option. :)
Hope this helps a bit
Edit: Just to add Windows doesn't come with SSH which might explain some of the username/password issues. When you set up a FTP server on your Windows pc you can set your credentials
Here is a guide for setting up FTP Server on Windows PC
https://www.howtogeek.com/140352/how-to-host-an-ftp-server-on-windows-with-filezilla/
Once you have a server setup on your pc, if you wish to go down the route of a creating a cron job on your webserver for automation, you will havve your credentials from your server setup.

Is there any other security/performance issue of XAMPP for production on windows server except those listed in official FAQ?

Usually I prefer using Linux CentOS / Ubuntu for production server. However currently I got a customer who don't want to pay extra for hosting. In return he provides a server running windows server 2003. To save setting time, I would like to see if it is safe to use XAMPP as production server.
After some Google searches, many people says that it is not recommended, but usually with no reason given. The only exception is the official Q&A section, stating that there are the following security issue:
The MySQL administrator (root) has no password.
The MySQL daemon is accessible via network.
ProFTPD uses the password "lampp" for user "daemon".
PhpMyAdmin is accessible via network.
The XAMPP demopage is accessible via network.
The default users of Mercury and FileZilla are known.
So, if I am not installing ProFTPD and Mercury during XAMPP installation, setting a password for MySQL root account and set up a firewall that only allow public access on port 80, it seems that all 6 problems are solved?
If so, except the security issue listed above, are there any other security / performance issue that I should not be using XAMPP for production?
I think your approach is correct.
The most important points are to create a root password and configure the .htaccess file.
There are also guides how to make XAMPP more secure.

PHP shell_exec doesn't work in Windows Azure

We need to execute an .exe file in a remote Windows Azure Server.
We call it from PHP with shell_exec. The .exe should create new files in two different folders into the server and generate data entries in a data base and returns a string, but it doesn’t work.
We don’t have any problem executing it in our local server with windows 7 Enterprise and IIS 7. That’s why we thought it could be a permissions problem, and then we have created a .user.ini file with the following content:
safe_mode= off
safe_mode_exec_dir= off
Unfortunately it doesn’t work too.
Any suggestions?
Thanks in advance.
You are most probably working with Windows Azure Web Sites. This is a high-density shared hosting with tightened security. If you need things like shell_exec you shall move to Windows Azure Cloud Service (Web Role), where you have full control over the OS and web server / php settings.
Using Cloud Service you will be able to use shell_exec. However when you move to Cloud Service you have begin thinking of saving files in Azure Blob Storage, as the local storage for cloud service is:
Not persistent
not synchronized across role instances
If you want don't yet know what Role and Role Instance is, or are little confused, please go through this article.

Windows network drive from PHP running on a linux environment

I have to check something if it works.
We have limited access to a Debian server via ssh. We have a PHP intranet solution running on this server, so we can run PHP scripts. We got the following scenario:
A windows network drive given: \\IP\folder$
We have to read this windows network drive from PHP under linux. I never did such thing.
We have no any rights to mount anything on the server. This drive may or may not accessable from the linux machine, I don't know. (I guess it's accessable, due to the scenario).
We didn't receive any user&pass for the drive, so I guess we don't need it.
The question is: is it possible to do this in this situation if everything was set up correctly on the customer side? If yes, how?
We can ask more information and configuration changes if we need it, but I'm wondering if we can do this now, because it's interesting.
Thanks in advance,
negra
You can use smbclient to access the share. You could consider it as a sort of 'ftp' client, but for accessing Windows shares instead. It can work without need for mounting, and you should be able to talk to it directly from PHP using popen() for bi-directional communication of commands/results.
However, this depends on the share actually being remotely accessible, and you having access rights to it (via a windows account or the share having 'everyone/read' permissions). If windows networking is firewalled and/or you don't have access permissions, then there's nothing you can do to access the files directly.

Categories