Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chern123's avatar

Laravel and Wordpress Together

Well, the title is a little bit vague -- but basically this is my first time hosting a little sample laravel project on the web alongside a CMS (Wordpress).

-I'm using Laravel Forge and Digital Ocean (running Ubuntu 14.04). -I have successfully gotten my project up, as well as installed Wordpress.

The installation directories are as follows:

/home/forge/default/ -> Wordpress
/home/forge/default/app/ -> Laravel app

My default NGINX directory is configured to:

    root /home/forge/default/;

I haven't set any .htaccess files or anything of that nature. That being said, if I want Wordpress to just act as one of those 'information' sites that just lists a bunch of information in regards to the project, and have the laravel app do its own thing, how would I go about configuring this?

Currently Wordpress seems to sabotage all URLs (even those in the /app/ directory).

Is there a good guide/tutorial to look at? I am vaguely familiar with web administration, and could use some pointers. I don't even know how htaccess files truly work.

Any help appreciated!

0 likes
7 replies
robgeorgeuk's avatar
Level 14

Currently Wordpress seems to sabotage all URLs (even those in the /app/ directory).

Can you give some info exactly what happens here?

NGINX doesn't use htaccess files so you'll need to recreate any necessary rules in the NGINX site config file. Mostly this is fine but some WordPress plugins write directly to the htaccess file so watch out for those.

Here is my NGINX site config file for a WordPress site. If a file/folder exists then it will serve that directly otherwise it will pass the uri along to the WordPress index.php where it will be dealt with.

server {
    listen 80;
    server_name example.com;
    root "/home/vagrant/Code/example.com/public";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/example.com-error.log error;

    sendfile off;

    client_max_body_size 100m;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }

    location ~ /\.ht {
        deny all;
    }
}

1 like
chern123's avatar

Thanks for the response!

Basically Wordpress throws me a 404 page (in the theme of my choice) every time I try to enter valid Laravel URLs.

Had no idea -- thanks for telling me that, I would definitely be pulling my hair out trying to figure out why my .htaccess file isn't doing anything.

We have surprisingly similar NGINX files:

server {
    listen 80 default_server;
    server_name default;
    root /home/forge/default/;

    # FORGE SSL (DO NOT REMOVE!)
    # ssl_certificate;
    # ssl_certificate_key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/default-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

Which part is responsible for the re-directing of the uri's?

Kryptonit3's avatar

@mdobrenko not sure of your site setup, like if you use SSL and if so, is it a wildcard cert. What I would do is decide which site is more important/used and make that site sit on the base domain like so

mysite.com -> more important/used (wordpress or laravel) maps to /home/forge/default

faq.mysite.com -> (subdomain) other of the two, like if you use wordpress for static faq and maps to /home/forge/another-folder

set your nginx server blocks accordingly. problem solved. No need to worry about sub-folders and the parent folder app corrupting it.

Just how I would approach it if I were using wordpress and laravel on the same domain. Another benefit of doing this is that you won't have to append a constant folder to the domain like mysite.com/app/{laravel base}/{urls}

Just a lot cleaner

{sub-domain}.mysite.com/{urls} [ wordpress or laravel ]

mysite.com/{urls} [ other of the two ]

1 like
bashy's avatar

What I would do is have the files in separate folders and then alias one or the other (whatever one is not on the root of the domain).

alias /blog /home/sites/wordpress;
1 like
chern123's avatar

@robgeorgeuk That sounds like what I was going for -- I would probably have my Laravel app as my subdomain.

Do you know of any courses/literature/resources that I should look at to learn more about this kinda 'stuff' (not sure if this is all NGINX, or falls within web server administration, etc)... could use some pointers as to where to start digging!

@bashy Hmm that's an interesting approach... not sure which of these two I will end up implementing...

Thanks for the replies fellas!

robgeorgeuk's avatar
location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

This part handles the primary routing. If the uri is a real file/folder then it will be returned otherwise it will pass the uri to index.php where WordPress (or whatever) will handle it. The NGINX docs are pretty comprehensive but not always easy to read. http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files

Personally I think @fideloper at https://serversforhackers.com is doing a great job of teaching server admin stuff.

1 like
chern123's avatar

@robgeorgeuk After looking through the content, I picked up a three-month subscription. Should keep me busy and help me out a bit :-). Thanks a ton!

Please or to participate in this conversation.