How to solve PHP warning: mkdir(): No such file or directory


I was on a Linux server and working on a Laravel project. All were working fine. Suddenly, we found that all mail related functionalities were crashing. From the log, we saw the SwiftMailer was trying to create cache in default /tmp folder and crashes with a warning saying:

warning: mkdir(): No such file or directory

I tried to run a simple PHP script that would create a folder or file under /tmp folder. It also produced the same warning.

PHP Code:


To solve the issue, I’ve changed the TMPDIR environment variable in the boot() method of app/Providers/AppServiveProvider.php.

     * Bootstrap any application services.
     * @return void
    public function boot()
         * Somehow PHP is not able to write in default /tmp directory and SwiftMailer was failing.
         * To overcome this situation, we set the TMPDIR environment variable to a new value.
        if (class_exists('Swift_Preferences')) {
        } else {
            \Log::warning('Class Swift_Preferences does not exists');

Please make sure that the new “tmp” folder location is writable by the web server.

This is the quickest solution that we had. For any other PHP frameworks, you can set a new TMPDIR location to solve this issue. If anyone knows the exact issue that causes the warning, please feel free to leave a comment.

Thank you for reading the post.


I will be happy to answer your queries

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s