Load CSS with image urls from a different path than root? - php

I am currently working on a CMS where each websites has his own folder to contain dependencies, images, files and scripts, specific for this website.
The folder structure looks like:
/http_docs
|
|--- CMS root
| |
| |---- index.php
| |
| |---- includes
| | |
| | |--- js
| | |
| | |--- css
| | |
| | |--- other dependencies
| |
| |---- scripts (etc..)
|
|---- Somewebsite
| |
| |---- files
| | |
| | |---- images
| | |
| | |---- uploads
| |
| |---- sources
| |
| |---- css
| |
| |---- js
|
|---- some-website...
Some of the CSS files in the website contain relative URLs to the image path. These URLs look like this:
.robot {
background-image: url('/files/images/some-image.jpg');
}
This works well if the website is loaded from an URL outside the CMS. E.g. http://some-website/files/images/some-image.jpg.
In the httpd.conf the root of the external domains is set to the website root and thus the files are loaded without problems.
The problem arises however, when the CSS-files are loaded into the CMS builder, which is a specific page in the CMS where you can add and remove elements from the page, the images are not loaded.
This is because, of course, the root of the CMS is not the same root of the some-website.
Question
Is there a way to solve this without completely rewriting all the CSS files?
If the answer is no, would you know of a tool that would make my work easier?

Related

hosted Laravel not storing images but works perfectly on localhost

I have a Laravel project hosted in CPanel and it’s running but when I upload an image, it supposed to store in the public folder like ("public_path()/posts/theactualimage.jpeg").
in my local machine things are going pretty well but not on the hosted
I don’t know if there’s any configuration that I should do …
here is the structure of the folders
./
| public_html
| | posts
| | index.php
| | some other files
|
| myapp
| | all the other files controllers views
here is the function that stores the images
public function uploadImage($location, $imageName){
$name = $imageName->getClientOriginalName();
$imageName->move(public_path().'/'.$location, date('ymdgis').$name);
return date('ymdgis').$name;
}
the uploaded image is automatically creating new folder inside myapp/public/posts/(image.jpg)
if possible please log the public path and location, see if you getting expected results

Voyager in Laravel project can't find CSS on a live server

Currently I'm working on a Laravel project where I use Voyager for the back-end.
Everything was working well until I moved it towards the live server.
Now when I go to example.net/admin I get a page without styling.
Voyager admin page without css...
The front-end works normally as I wanted it to be.
I assume this is a path issue yet I have no idea how and where to fix this..
The weird thing is that it worked yesterday night, everything worked normal but today, when I tried to login, it seemed like it didn't load in the .css file...
My folder structure looks like:
domains
|- example.net
| |- app
| |- awstats
| |- bootstrap
| |- config
| |- database
| |- hooks
| |- logs
| |- private_html
| |- public_ftp
| |- public_html
| |- resources
| |- routes
| |- storage
| |- tests
| |- vendor
|- .env
|- [all the other files on here]
When I try to open the Voyager image on my browser, it shows me this path:
https://example.net/admin/voyager-assets?path=images%2Flogo-icon-light.png
The voyager.php in the /vendor/tcg/voyager/routes/ map shows me
//Asset Routes
Route::get('voyager-assets', ['uses' => $namespacePrefix.'VoyagerController#assets', 'as' => 'voyager_assets']);
But I'm not sure if this is related to this issue...
Can someone tell me what I'm doing wrong so I can fix this?
Thank you in advance

Load php class located outside symfony project

I am building a frontend symfony app for a project with the current folder structure:
+---app
| +---conf
| +---lib
| | +---ca
| | | +---Search
+---frontend
| +---app
| +---bin
| +---src
| | \---PublicBundle
| | +---Controller
The app folder on root is where another (non symfony app) is located. It is a php app.
Inside the frontend folder is where symfony project is being built.
I am trying to load from inside the symfony app (from the public controller) a class from the other php app (a class inside the ca subfolder) but when I try to, symfony returns a namespace exception with the tip: Did you forget a "use" statement for another namespace?
It is correct to load a class from outside a symfony project like is, and if it is how is it done?
Thanks in advance,

MVC Architecture from Development to Production

I am trying to gain a better understanding of MVC architecture. I write both front end and back end web applications using LAMP stack. I don't use any frameworks yet. I code in Notepad++ and use WinSCP for file transfer (Putty for terminal). All of the server side coding is done in PHP.
Based on the reading I've done, this is my best guess on how MVC's files are structured:
+ -- Project1
| + -- models
| | + -- model.php
| + -- views
| | + -- view.php
| + -- controllers
| | + -- controller.php
+ -- Project2
| + -- models
| | + -- model.php
| + -- views
| | + -- view.php
| + -- controllers
| | + -- controller.php
So, while there are a lot of articles and blogs about what models, views, and controllers are, I haven't seen anything about how to set this up past what I've gathered above.
I have no idea how this becomes integrated in relation to my public folder on my server. Here is my guess, assuming that /var/www/html/ is my public directory.
+ -- var
| + -- www
| | + -- html
| | | + -- my-application-1.php
| | | |
| | | + -- my-application-2.php
| | + -- Project1
| | | + -- models
| | | | + -- model.php
| | | + -- views
| | | | + -- view.php
| | | + -- controllers
| | | | + -- controller.php
| | + -- Project2
| | | + -- models
| | | | + -- model.php
| | | + -- views
| | | | + -- view.php
| | | + -- controllers
| | | | + -- controller.php
I am assuming based on what I've read (maybe I'm wrong) that people put their entire project "behind" their public folder. I am also assuming that you take your final application file (my-application1.php or my-application-2.php), put it in your public folder for people on the internet to use, and reference (php's include/require) your models, views and controllers from that application file. I've never referenced files behind my public file, but I'm assuming a lot here.
Can someone verify any of this for me? How is this supposed to be set up in relation to the rest of my linux server? Is there anything I am assuming that is incorrect that you'd care to correct?
I am trying to gain a good understanding of this before I pick up any frameworks (probably leaning toward Zend, Laravel, or CakePHP). I have read that frameworks help with this, but I currently don't have the resources to set up a framework and I would like to gain a full understanding of this before trying to pitch this to my team.
You're saying in your question that you don't have the resources to set up a framework but yet you have to resources to build one from scratch without even having the slightest idea what you're doing?
Believe me, you don't want to do it yourself. At the very least, you should first try some existing framework like symfony2 or zf2 or whatever you like.
When you'll become familiar with some of these and understand how they work, you will be able to create your own and give up in front of the tons of work it require.
Anyway, to answer the question, here's how zend framework 1 is structured
project
|-- application
| |-- Bootstrap.php
| |-- configs
| | `-- application.ini
| |-- controllers
| | |-- ErrorController.php
| | `-- IndexController.php
| |-- models
| `-- views
| |-- helpers
| `-- scripts
| |-- error
| | `-- error.phtml
| `-- index
| `-- index.phtml
|-- library
|-- public
| |-- .htaccess
| `-- index.php
With this framework, you would setup your web root to /path/to/project/public.
As you can see, none of the application code is directly accessible from the web. All incoming requests come throught the index.php where all the magic is.
If you're interested in knowing what the magic really is, all the php web framework are open source so feel free to check it out for yourself :
ZF2 on github
Sf2 on guthub
It's very dependant on the framework you choose to use, but the general idea is that the actual source directory is NOT stored in the web root. I use /web/projects on my deployments, then symlinking the public folder out to the htdocs
> cd /var/www/html
> ln -s /web/projects/myProject/public myproject
You'll then usually have an index.php file in the public file that kicks things off. There's also usually a .htaccess file that intercepts all requests and points them at that file.
Best option is to choose a framework (Laravel and Symfony are excellent options) and follow the getting started guides.

Dynamically map domains to folders in Apache

I have multiple versions of the same software package in sub folders like this (simplified):
/var/www/version1
/var/www/version2
/var/www/version3
In a database I have a table similar to this:
+-----+-------------+----------+-----+
| ... | domain | version | ... |
+-----+-------------+----------+-----+
| ... | example.com | version1 | ... |
| ... | samepl.com | version2 | ... |
+-----+-------------+----------+-----+
Is there any way, using a database as a source (MySQL as an example), to map URLs to the correct subfolder based on version and domain? I would like something dynamic that does not require an Apache restart.
The purpose of this setup is to allow customers to choose which version of the software they want. If there's a better way to do this I would love to hear that as well.
Thanks!
I figured out a solution on my own that involves VirtualHost variables.
http://httpd.apache.org/docs/2.2/vhosts/mass.html

Categories