Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 500295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:04:21+00:00 2026-05-13T06:04:21+00:00

From the command line, I can get the home directory like this: ~/ How

  • 0

From the command line, I can get the home directory like this:

~/

How can I get the home directory inside my PHP CLI script?

#!/usr/bin/php
<?php
echo realpath(~/);
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:04:22+00:00Added an answer on May 13, 2026 at 6:04 am

    Use $_SERVER['HOME']


    Edit:

    To make it complete, see what print_r($_SERVER)gave me, executed from the command line:

    Array
    (
        [TERM_PROGRAM] => Apple_Terminal
        [TERM] => xterm-color
        [SHELL] => /bin/bash
        [TMPDIR] => /var/folders/Lb/LbowO2ALEX4JTK2MXxLGd++++TI/-Tmp-/
        [TERM_PROGRAM_VERSION] => 272
        [USER] => felix
        [COMMAND_MODE] => unix2003
        [__CF_USER_TEXT_ENCODING] => 0x1F5:0:0
        [PATH] =>/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin
        [PWD] => /Users/felix/Desktop
        [LANG] => de_DE.UTF-8
        [SHLVL] => 1
        [HOME] => /Users/felix
        [LOGNAME] => felix
        [DISPLAY] => /tmp/launch-XIM6c8/:0
        [_] => ./test_php2
        [OLDPWD] => /Users/felix
        [PHP_SELF] => ./test_php2
        [SCRIPT_NAME] => ./test_php2
        [SCRIPT_FILENAME] => ./test_php2
        [PATH_TRANSLATED] => ./test_php2
        [DOCUMENT_ROOT] => 
        [REQUEST_TIME] => 1260658268
        [argv] => Array
          (
            [0] => ./test_php2
          )
    
        [argc] => 1
        )
    

    I hope I don’t expose relevant security information 😉

    Windows Compatibility

    Note that $_SERVER['HOME'] is not available on Windows. Instead, the variable is split into $_SERVER['HOMEDRIVE'] and $_SERVER['HOMEPATH'], meaning if you want both Unix-and-Windows compatibility, do:

    $homepath = $_SEVER['HOME'] ?? (/*windows compatibility: */$_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH']);
    // $homepath looks like /home/username or C:\Users\username
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I execute a command line from within a WiX script? I want
This command: /usr/bin/mysqldump --add-drop-table -u myuser -pmypass mydb > /home/myuser/dbBackups/`date +%Y%m%d`.sql works fine from
I'm on a mac server. From my home directory, I can get to mysql
Using the Android SDK from the command line, I can get a list of
Is there anyway we can take input from command line in Objective-C, the way
As I know, when I run cs myConsoleApp.cs from windows command line, I can
I can import MySQLdb from the interactive python command line but Zope gives me
I have a python script that, once executed from command line, performs the needed
I'm running a script fine from the command line, but it fails when put
How can I sync local and remote folders using rsync from inside a php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.