LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-10-2011, 08:58 PM   #1
sourdough
LQ Newbie
 
Registered: Sep 2011
Posts: 7

Rep: Reputation: Disabled
Question how do I use PHP scripting for Linux commands


Ive just signed on with a VPS Linux hosting service and I would like to know if it's possible to use PHP scripting to invoke Linux FTP commands.

Specifically I would like to generate new FTP accounts "on the fly" for new users on my web site. These FTP accounts need to be restricted to a user folder.

For example for a new FTP user Mike -- username "mike@myemail.net" password "ABCdef". Mike needs to be restricted to the directory hostdoc/mywebsite.com/users/mike

I have a little PHP scripting experiance but I'm unfamiliar with Linux or Linux commands -- so showing what the code would actually look like in a PHP file would be a great help.

Ron Lemire
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 09-11-2011, 01:36 AM   #2
kasl33
Member
 
Registered: Oct 2004
Location: USA
Distribution: Ubuntu-Server, Mac OS X, Arch Linux
Posts: 356

Rep: Reputation: 48
In Php, executing a Linux shell command is as simple as this:

Code:
$var = shell_exec("ls -l ~"); // execute command to view home directory
echo $var; // shows the output of the ls -l ~ command
It should work the same with ftp commands as long as apache has permissions to do what you want on the server (Php runs as the Apache user in the web browser).

If you run the Php script on the server directly, then you can have it run as whatever user you want (su to the user you want, and execute the Php script).
 
3 members found this post helpful.
Old 09-11-2011, 02:29 AM   #3
sourdough
LQ Newbie
 
Registered: Sep 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thumbs up Thanks Kasl_33

That's exactly what I wanted... I tried the code snippet on my server and it worked. Now that I know the syntax for passing commands to the Linux system using PHP - it's just a matter of figuring out what commands I need.

It's amazing how confusing a simple task can be when you don't know where to begin.

I'd seen some online references for using the shell_exec in PHP before -- but I couldn't figure out how it was used until I saw your PHP code.

Thanks very much for your help..
 
Old 09-11-2011, 04:03 AM   #4
kasl33
Member
 
Registered: Oct 2004
Location: USA
Distribution: Ubuntu-Server, Mac OS X, Arch Linux
Posts: 356

Rep: Reputation: 48
Glad I could help. Don't forget to mark the thread as solved just above your first post in "thread tools."
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run linux commands in php ramakrishnankt Linux - Newbie 9 11-25-2009 12:16 AM
Running linux commands through PHP Nzo Linux - Server 3 06-16-2008 12:16 PM
PHP and Linux commands eggoz Linux - General 2 03-06-2004 04:19 PM


All times are GMT -5. The time now is 12:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration