.env file wont load variables into config.php - student setting up first php dev environment

前端 未结 2 1848
栀梦
栀梦 2021-01-27 02:42

Afternoon everyone,

I\'m a student studying Computer Science and I\'m trying to recreate the environment my friend is using to host their PHP based web app. They\'re on a

相关标签:
2条回答
  • 2021-01-27 03:22

    I'm using WSL and am similarly having problems with my .env not working properly.

    Although I'm still looking for a more elegant fix, the hack I'm relying on now is:

    1. Copy the contents of your .env to a temporary text file.
    2. In that text file, do a regex find-and-replace searching for "\n" and replacing with "\nexport " (with a trailing space).
    3. Move the final line's "export " to the first line.
    4. Copy the contents of this temporary text file.
    5. Paste into your terminal to run these commands.
    6. Now you should be able to run your app.
    0 讨论(0)
  • 2021-01-27 03:33

    Straightforward Method

    You can do this very simply by adding the environment variable to your .bashrc file, assuming that your Windows Environment variables are set correctly and WSL is installed, I'm going to use Java as an example, but any environment variable will work.

    Use text editor in WSL or type code .bashrc from WSL home to initialize the WSL VSCode editor. Add the environment variable to the file:

    # Shared environment variables
    export JAVA_HOME=/mnt/d/Java/jdk11.0.4_10
    

    Just ensure that you change the directory to point to your directory. In my case, it's in D:\Java\jdk11.0.4_10 which in WSL is /mnt/d/Java/jdk11.0.4_10

    Also, since you're using Windows binaries, you must specify the file type when running from a WSL bash shell:

    Example

    Windows:

    javac MyClass.java
    java MyClass
    

    WSL:

    javac.exe MyClass.java
    java.exe MyClass
    

    Note that the .exe file extension is being used, since we're calling the Windows binary. If it was a native Linux distribution of the JDK you could simply use java command.

    This holds true for any Windows binary that is being run through WSL.

    0 讨论(0)
提交回复
热议问题