Root path in XAMPP - php

I've had this problem for a while, and have unsuccessfully searched far and wide for an answer.
<img src="/images/test.jpg" />
Gets an image from (root path - in my case in production in LAMP)
htdocs/images/test.jpg
Whether it's called from htdocs/index.php or htdocs/foo/bar/index.php
I use XAMPP in development, and inside htdocs have project folders, so the method described above although will work when live requires me to alter it to:
<img src="/projectName/images/test.jpg" />
when working locally.
To make this simpler i define a constant BASE, which in development I use:
define('BASE','/projectname/)
And then when it's live I change to:
define('BASE','/')
<img src="<?php echo BASE;?>images/test.jpg" />
This is obviously really annoying and ends up causing several issues. Please can someone shed some light on this situation, what I'm specifically looking to do is use root path in my image/script sources but for:
<img src="/images/test.jpg" />
when called from htdocs/projectName/foo/test.php
to look for the image in:
htdocs/projectName/images/
Is this possible?

An alternate way to handle this is with the use of Virtual Hosts.
A virtual host acts like a second version of localhost that works specifically for a subfolder. For example, you could set up Apache so that when you visit http://example (no .com or anything), it shows you the content from http://localhost/example/. All CSS and JavaScript and links would act as if they were operating from the root folder of a website, since the leading example folder has been trimmed out of the URL.
I can't find a walkthrough that I used to use for XAMPP, but here a similar one that covers all of the main points. It was written for Windows, but I imagine that there are similar mechanisms that you can use for LAMP:
To summarize, here's what the article tells you to do:
Enable Virtual Hosts within Apache
Set it up so that when you visit example, you are sent to 127.0.0.1
Configure Apache so that when someone visits 127.0.0.1 (but the name of the website is example), then it shows content from the example folder.
This is how your production site (which is a single server with multiple websites) has a different "root" for each website.

Have you ever thought about the base-tag in the header of your html content? http://www.w3schools.com/tags/tag_base.asp
<head>
...
<base href="<$path />">
...
</head>
get base path:
$path = $_SERVER['SERVER_NAME'] == 'production.host' ? '/' : 'projectName';

You can either try the solution provided by others in this thread (which are programming solutions), or as an alternative, I do something different (a setup solution).
For me, I like to create an independent environment, in which my projects and development files are separate from XAMPP as much as possible (I am using XAMPP, but the principle applies to other hosting environments). This allows me to easily install new updates for XAMPP whenever they become available without worrying about my projects, and also I like to have all my projects in one folder dedicated to development. This development folder will contain projects for web, mobile, and other environments.
The way I set it up, is I have a c:\dev\ folder, that will contain a list of my projects, each project is on its own. So, for example, c:\dev\project1\, c:\dev\project2\ and so on.
Now, after I create those folders for development, I make sure that the httpd-vhosts.conf file (located at c:\xampp\apache\conf\extra\) and the hosts file (located at c:\Windows\System32\drivers\etc\) have the correct references.
Lets assume that one of my projects is called project1. and it is typically located at c:\xampp\htdocs\project1 then I would normally access it via the browser as http://localhost/project1
However, in order to have an independent environment, and as explained earlier, I would create a development folder in the c: drive called c:\dev, then I would move project1 into it, and ended up with c:\dev\project1
Then, to access this project via typing project1.dev in the web browser, I appended the httpd-vhosts.conf file located at c:\xampp\apache\conf\extra\ as follows:
<VirtualHost project1.dev:80>
ServerAdmin admin#project1.dev
DocumentRoot "C:/dev/project1"
ServerName project1.dev
ServerAlias www.project1.dev
ErrorLog "logs/project1.dev.error.log"
CustomLog "logs/project1.dev.access.log" combined
<Directory "C:/dev/project1">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Also, I have to update the hosts file (located at c:\Windows\System32\drivers\etc\, and add the following entry:
127.0.0.1 project1.dev
127.0.0.1 www.project1.dev
(where 127.0.0.1 is the same as your localhost. Also note that you have to add the second entry in the hosts file for the www alias).
This allows me to access my project as: http://project1.dev
Once this is set, I can now write my code consistently for both my development and production environments, and my references to the root will work just fine.
Also, with this setup, I do not care if I need to update my XAMPP or switch to LAMP or anything else, all I care about is making sure I take care of one file only, which is my setup file httpd-vhosts.conf. And as I mentioned, I always prefer having a separate folder for development, and I can have different types of projects in the development environemt, for example, mobile projects, web projects, ... etc.
Hope this helps.
Note about multisite (subdomain setup)
If you would like to setup a multisite (subdomain setup), then after you enable WordPress for multisite according to the WordPress instructions, you have to do the following:
Assuming you want the following structure for multisite:
project1.dev
www.project1.dev (this is an alias to project1.dev)
sub.project1.dev (this is another setup, subdomain)
Then you have to add the following entry to httpd-vhosts.conf
<VirtualHost sub.project1.dev:80>
ServerAdmin admin#project1.dev
DocumentRoot "C:/dev/project1"
ServerName sub.project1.dev
ErrorLog "logs/sub.project1.dev.error.log"
CustomLog "logs/sub.project1.dev.access.log" combined
<Directory "C:/dev/project1">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
And update the hosts file to include
127.0.0.1 www.project1.dev
Note that DocumentRoot points to the same directory for both the main site and the subdomain site.
Repeat the process for each new subdomain you add in your WordPress network.

I think the best way to do this is with a baseurl, set your baseurl in your config and use it for external files.
$config = new Config();
public $baseurl = "http://dev050.nl";
You can use it then as
$config->baseurl;
And maybe this is something interesting for you:
http://twig.sensiolabs.org/
hope it helped.

I do a similar thing to switch databases between my dev server and the hosting server if it's any use to you. No reason why it shouldn't work for a base URL.
// db connect
if($_SERVER['SERVER_NAME'] != "dev.mydomain.org"){
try{
$pdo = new PDO('mysql:host=mysql.***.net;dbname=***;charset=utf8', '***', '***');
}catch(PDOException $ex){
header('Location: error_db.php');
}
}else{
try{
$pdo = new PDO('mysql:host=localhost;dbname=***;charset=utf8', '***', '***');
}catch(PDOException $ex){
header('Location: error_db.php');
}
}

A possible solution could be to use mod_rewrite to automatically change the path on you development server
RewriteCond %{HTTP_REFERER} ^https?://localhost/testsite/
RewriteCond %{REQUEST_URI} \.(jpg|gif|png|bmp)$
RewriteRule ^ /testsite/$1
I believe the above mod_rewrite rule is correct but it would be best to verify this yourself.

Related

Errors after moving local Wordpress site outside of XAMPP\htdocs

Background
As someone who develops multiple websites I wanted to be able to serve each site from within its respective project folder in the filesystem, instead of serving them all under the htdocs directory.
So I moved my wordpress folder (whose site was usually accessed via localhost/wordpress) to my project directory, and followed the instructions in this answer to set up a virtual host with a DocumentRoot and Directory that matches the new location of the wordpress folder. This is the whole (uncommented portion) of my httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "D:\Users\User\Documents\Projects\Websites\My New Project\wordpress"
ServerName localhost.irm
<Directory "D:\Users\User\Documents\Projects\Websites\My New Project\wordpress">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
The Problem
The homepage can now be found at localhost.irm, but it's text-only, with no styles or images, and clicking on any page takes me to an "Object not found!" XAMPP page.
What I've Tried
Accessed the database with PHPMyAdmin, changing siteurl and home in the wp_options table to reflect the new domain
Used the WP-CLI tool to search-and-replace all database instances of the old domain with the new one
Unfortunately none of these solved the problem.
This seemed to be primarily caused by two problems:
The Site Ground Optimiser plugin from my live site that I wasn't even aware was activated on my local site. Deactivating using wp plugin deactivate sg-cachepress (the WP-CLI tool) solved that.
The following line in my .htaccess file, at the root of my Wordpress site:
RewriteBase /wordpress/
I assume it must have been necessary to add for my previous setup and I'd since forgotten about it. Either way, removing/commenting the line out entirely seems to have solved the rest of the problem.
I'm now able to access my website with all styles and images, just like I was before, with the advantage that my files are now being served from my project folder itself instead of from XAMPP\htdocs.

Multiple apps, multiple versions of the app under the same domain. How to configure apache server, routes and relative paths to make it work?

My team's server is set up in such as way: We have one domain name, which seems like already a subdomain of the company's domain. We want to host multiple applications under this one domain. We'd even like to have a production version and staging version for each of the apps on the server.
Document root is an empty folder. Applications sit outside of the document root.
we are trying to use the first token in the URL path to find out which app we try to access, then somehow redirect to it (internally or externally).
Here is a structure equivalent to how the directories are organized.
/usr/local/var/www <- Document Root
/usr/local/var/app1 <- application 1
------------------/public/index.php
------------------/public/css
/usr/local/var/app2 <- application 2
/usr/local/var/app1.stg <- application 1 staging version, code is exactly the same as application1
/usr/local/var/app2.stg <- application 2 staging version, code is exactly the same as application2
Here are the relevant settings in httpd.conf
DocumentRoot /usr/local/var/www
<Directory "/usr/local/var/www">
AllowOverride None
Require all granted
</Directory>
Alias "/app1" "/usr/local/var/app1"
Alias "/app2" "/usr/local/var/app2"
<VirtualHost *:80>
# rewriting rules to make the routing work
# There is only one vhost so it can actually be removed
</VirtualHost>
When we access https://sub.domain.com/app1, we expect to go to app1
When we access https://sub.domain.com/app1.stg, we expect to go to app1.stg
The applications are written in PHP. This server configuration means we have to include the "path to the application" in the routes and rewrite rules, and use the "full absolute path" in all the resource references.
For example, a route will look like
$router->map("GET", "/app1/action", SomeController);
A css reference will be: (even though relative path is given, it behaves just like a relative path to the DocRoot (with "/" in front). You can see it in this detailed post)
<link href="app1/public/css/style.css" type="text/css" rel="stylesheet"/>
These will be sufficient to make both apps work, but the staging version is not going to work, because it contains EXACTLY THE SAME copy of code (which is how it's intended to be, to test out in staging environment, then push to production environment).
If I want both versions to work, I have to code the paths dynamically, namely using CONTEXT_DOCUMENT_ROOT or some other server variable to figure out which app version it's in, and have two copies of routes, one starting with app1, the other app1.stg. I also have to have separate rewriting rule for each version.
QUESTION
With the server setup restriction applied (one domain name, distinguish apps with the way I described, etc..), is it possible to use only relative paths, write routes with respective to only the app itself? Some like:
<link href="css/style.css" type="text/css" rel="stylesheet"/>
$router->map("GET", "/action", SomeController);
In other words, I have to change the server setup within the constraints, so that the app can be written in a way without caring how the server is set up.
I know one way is to use different ports for each app/version, but apparently the server admin doesn't like the idea.
I've broken down the problem into steps in this question. It's quite long but if you are willing to follow through, it should provide much more details.
If the question is not clear enough, the per-user directory looks quite like what I want to achieve. But instead of user directory, I want the app directory in place of it. Of course I never used per-user directory so I dont know if it actually behaves the way I think it does.
So I understand that we can have multiple hostnames in /etc/hosts mapped to one IP address. Can I just use that hostname as the ServerName in apache config, and access in the browser by typing that hostname? The website is for internal usage so should only be accessed within company's network.
In /etc/hosts:
123.45.67.89 app1.team-server-name app2.team-server-name
In httpd.conf:
<VirtualHost>
ServerName app1.team-server-name
DocumentRoot /usr/local/var/app1/public
</VirtualHost>
<VirtualHost>
ServerName app2.team-server-name
DocumentRoot /usr/local/var/app2/public
</VirtualHost>
This is quite the lengthy question, thank you for providing so much detail.
I would opt for a different approach than you are currently attempting. Instead of trying to serve each of these applications out of a folder, set up each of them as a domain based vhost. Use something like app1.local or whatever for the hostname and be sure to add the entries to your /etc/hosts file under 127.0.0.1. Make sure the listen directive for these vhosts is on the loopback (127.0.0.1:80). Each of these apps should function as if they were installed at the document root of their own server. All the CSS should assume its at 'css/style.css' relative to /.
Now that you have all of the apps setup on the loopback, you can setup a reverse proxy from the vhost listening on the public interface to proxy all of the application locations to their appropriate loopback vhost after you remove the /app1 prefix from the request.
I haven't used Apache 2.x for a very long time, but the concepts are the same as nginx.
location /foo {
rewrite /foo/(.*) /$1 break;
proxy_pass http://app1.local;
proxy_redirect off;
proxy_set_header Host $host;
}
The biggest issue with this approach is that the applications that are being proxied either need to use relative paths everywhere, or they need to have some kind of configurable prefix that is prepended to the urls. Most frameworks will support the prefix option. For Example: https://laravel.com/docs/5.6/urls This prefix can be used for asset (css/js/jpg) loading as well, but only from files that execute PHP.
I end up finding a solution with one compromise.
DocumentRoot "/usr/local/var/www"
Alias /app1 /usr/local/var/app1/public
<Directory "/usr/local/var/www">
RewriteEngine On
RewriteRule ^/?$ /app1/ [R,L]
RewriteRule (.*) /app1/$1 [R,L]
</Directory>
<VirtualHost *:80>
<Directory "/usr/local/var/app1">
Require all granted
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# calls index.php (REQUEST_URI is still the same as before)
RewriteRule ^ index.php [L]
</Directory>
</VirtualHost>
All relative paths can be rewritten normally.
Routes and requests will need to start with app name.
$router->map("GET", "/app1/hello2", SomeController);
// navigation bar. URI for another tab:
<li>Hello 2</li>
If we want to have multiple versions of the app, the main thing to do is to know which version we are in so the app can send the correct request uri. This can be done by checking the REQUEST_URI and remember which version is being called when index.php is called up. Then in the request (e.g. navigation src), append it in front of the action.
There are different ways to do this, such as writing your html templates in php, so you can access php variables. I used twig so I can pass the value to the twig templates from php. But I still don't like to have all these stuff in my static code, so I decided to just get rid of the staging version.
If the project is serious enough to require a staging version, then a better suitable environment should be provided.

How to setup private folders for PHP includes files for local testing AND live use.

Bit of a noob here. There is a probably a simple solution here - but I can’t get it to work or create a non-kludgey environment for testing. This may be answered in part elsewhere, but I'm still pulling hair out - so I'm going to ask.
The live path on a Linux VPS (with many sites in vhosts directory):
/var/www/vhosts/mysite.com/subdomains/mysubDomain/httpdocs/index.php /* the public, everyone can see web root directory */
I want to be able to configure a private level includes file folder:
/var/www/vhosts/mysite.com/subdomains/mySubdomain/includes/myincludes.php /*where I want the webserver only to read */
Note: I’d also like to use a same-level directory for moving private files after upload.
Locally, I’ve tried to create a similar structure at:
C:\xampp\htdocs\mySubdomain\httpdocs
One bad ideas is to set DocumentRoot in a local vHosts file to the mySubdomain folder – but that exposes the directory structure in things like:
<img src=”/httpdocs/images/image.png">
– and will not be acceptable in the live site.
On my XAMPP testing server, I’ve set up the vhosts file, for mysite.local to create the following
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
DocumentRoot C:/xampp/htdocs/
ServerName localhost
</VirtualHost>
<VirtualHost mysite.local>
DocumentRoot "C:/xampp/htdocs/mySubDomain/httpdocs"
ServerName mysite.local
<Directory "C:/xampp/htdocs/mysite" ></Directory>
</VirtualHost>
But, then I can't access my includes in the the mySubdomain folder.
Questions:
Is this whole approach provide any real benefit over htaccess in ‘live’ level folders (ie httpdocs/includes)? I’ve seen multiple references that storage “below public” will be a more secure file and preferred folder structure.
Is it includepath and the Document Root settings? Some other magic and delicate balance of settings? How does one create local testing access where the httpdocs(not the htdocs local folder is identified as the public directory?
Bonus (and the noob giveaway), if it’s possible to setup DreamweaverCS5.5 in this config for leveraging some of it’s fine features(like auto-discovery of the includes file) for testing and browser checking.
Yes, it does. For instance, if somehow something or somebody screws up the webserver enough the break PHP, but not the webserver itself, people maybe able to download public/somebusinesslogic.php, but NOT private/somefilewithpasswords.php. .htaccess files can also be disabled on Apache, which depending on the actual contents of it can take a while to notice.
At no single point did you provide the contents of your errors, so I cannot tell you what goes wrong, but it should not be a problem to mimic this setup on Windows, provided you use relative includes...
I have enough hate for products created with DreamWeaver that I have seen then I wouldn't touch it with a ten foot pole. Granted, this was 5+ years ago. It may have become less awful.

What is the proper way to configure Magento + Apache while running multiple stores on multiple domains?

This question has been asked amply all over the internet and on SO -- The available answers are obscured by specific details about everyone's particular installation. Hopefully this question will help everyone, including me, understand this better.
My question is "How should we configure the Apache .conf file to handle multiple domains?"
(I know the answer "depends". Hopefully, 80% of the people out there are going to have a basic setup at first and then make it more complex later.) I hope that's a good assumption.
I'm comparing Magento's install to Wordpress. Under Wordpress, the "best way" to install it seems to be to put the whole core into a folder called /wordpress. Then, using Apache rewrite rules and permalinks, obscure the /wordpress folder. In a multi-domain situation, the Wordpress core smartly handles the whole process for you without much modification of the .htaccess files. Further, whatever modifications do need to be made, Wordpress can do it for you - or a plugin can. Gosh, I wish Magento was as easy to install as Wordpress. But it's not. (yet!)
Under Magento, the term "store" is very misleading when we think about URLs. So let's ignore it for now and just worry about the lowest level -- the "Store View". In my case, I have the following:
Main Web Site -> Main Web Site Store -> Default Store View
www.site1.com -> Main Store -> site1_english
www.site2.com -> Main Store -> site2_english
The first column is the domain.
The second column is the store --
misleading title for this discussion.
The last column is the "Store View".
As for where to physically place the files. Most people, including me, want to leave the Magento core alone. No changes at all. So we put that into the htdocs root as follows:
/var/www/html/magento
This is where everyone gets confused I think. The Linux distros are not consistent about where this location is. And worse, lots of people are trying to do this on an economical hosting account. I'm using EC2 myself. Ignoring all that... Stick /magento in your document root. The next thing you might add is a /wordpress folder. Yay. Do it later.
In my apache config, I have it setup like this:
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot /var/www/html/magento
<Directory /var/www/html/magento/>
AllowOverride All
</Directory>
# Other directives here
SetEnv MAGE_RUN_CODE "site1"
SetEnv MAGE_RUN_TYPE "website"
</VirtualHost>
<VirtualHost *:80>
ServerName site2.com
ServerAlias www.site2.com
DocumentRoot /var/www/html/magento
<Directory /var/www/html/magento/>
AllowOverride All
</Directory>
# Other directives here
SetEnv MAGE_RUN_CODE "base"
SetEnv MAGE_RUN_TYPE "site2_en"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/nowhere
</VirtualHost>
The /nowhere folder has an index.html that says "no where".
The situation that I'm seeing is as such:
Navigate to www.site1.com -> Magento redirects to the Default Store View (on the IP address)
Navigate to www.site2.com -> Magento redirects to the Default Store View (on the IP address)
Navigate to the IP address of my server -> Magento displays the Default Store View
The Default Store View's BASE URL is http://my.ip.add.ress
Here are my questions:
What are we supposed to put in MAGE_RUN_CODE and MAGE_RUN_TYPE? Some sites say "website", some say "store". What is supposed to go in there?
Why don't I ever get to my nowhere site?
Why does the www.site1.com keep redirecting to the Default Store View?
Some of the documentation out there talks about creating dedicated folder or copying around index.php or .htaccess. Or making our own .htaccess. In this article, I selected the Apache config file.
Why won't that work right?
Why does the www.site1.com keep redirecting to the Default Store View?
Go to
System->Configuration->General->Web
There you should find Base secure and Base unsecure URL for you store. Moreover to the upper left corner you should see the scope of your settings. So for each store view you should change(if possible) URL of your store view.
What are we supposed to put in MAGE_RUN_CODE and MAGE_RUN_TYPE? Some sites say "website", some say "store". What is supposed to go in there?
If I don't mistake in code you specify the code of the "object" you want to launch, and in type you specify the type of this object - store or website. But this is not 100% info.

PHP Domain Mapping Script

I don't know what is the exact term for this, so my title could be incorrect.
Basically what I what to do is to write a PHP script that has an input field:
Domain Name: <input type='text' name='dname' id='dname' value='http://example.com' />
<input type='submit' name='addname' value='Add A Domain' />
When user type their own domain into the text field and press submit, the script will automatically make a directory, copy some PHP scripts there and map the domain name to there. (The domain name is pointing to our server, of course.)
I have already figured out the mkdir() and copy() part, but I couldn't figure out the mapping part. How to add an entry to map http://example.com to /home/user/public_html/copy1/ automatically, using PHP?
While you could do that directly from your PHP page, I suggest not to do that, for many reasons, from high failure risks (in case page execution gets interrupted suddenly, for example) to security risks (your httpd user will have write access to its own configuration + some stuff on the filesystem where it shouldn't).
Some times ago I wrote a similar control "website creation control panel" that works pretty much this way:
The php script receives the website creation request and stores it somewhere (e.g. in a database). dot.
Another script, running as root via cron each, let's say, five minutes checks the website creation requests queue. If there is any:
Mark the site creation task as "locked"
Create the directory at appropriate location, populate with scripts etc.
Change all the permissions as needed
Create new virtualhost configuration, and enable it
Make the webserver reload its own configuration
Mark the site creation task as "done"
The second script can be written in whatever language you like, PHP, Python, Bash, ...
About apache configuration
To create a directory "mapped" to your domain, you could use something like this:
First of all, "slugify" your domain name. I usually take the (sanitized!) domain name, and convert all dots with double-dash (that is not a valid domain name part). I don't like dots in file/directory names a part from file extension separation.
Then, you can create something like this (assuming domain is www.example.com):
<VirtualHost *:80>
ServerName www.exampple.com
DocumentRoot `/my-sites/wwwroot/www--example--com`
<Directory "/my-sites/wwwroot/www--example--com">
Options -Indexes FollowSymLinks
Order allow,deny
Allow from all
AllowOverride All
</Directory>
ErrorLog /var/log/apache2/www--example--com_error.log
CustomLog /var/log/apache2/www--example--com_access.log vhost_combined
</VirtualHost>
<VirtualHost *:80>
## redirect non-www to www
ServerName www.example.com
ServerAlias example.com
RedirectMatch permanent ^(.*) http://www.example.com$1
</VirtualHost>
Assuming you are placing your site files in directories like /my-sites/wwwroot/www--example--com.
Some security-related improvements
In my case, I also preferred not running the second script by root either; to do so you have to add some changes in order to let a less privileged user do some things on your system:
Create a directory with write access for your user, let's say /my-sites/conf/vhosts
Create an apache virtualhost containing the following line: Include "/my-sites/conf/vhosts/*.vhost", and enable it
Then, let your user reload apache configuration, by installing sudo and adding this to your /etc/sudoers:
Cmnd_Alias A2RELOAD = /usr/sbin/apache2ctl graceful
youruser ALL=NOPASSWD: A2RELOAD
%yourgroup ALL = NOPASSWD: A2RELOAD
And, of course, also give write permissions to your websites base directory to the user that will be used to run the script.
I think you need to add VirtualHosts to apache config (such as httpd.conf)
like this:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /home/user/public_html/copy1/
</VirtualHost>
Apache documents for virtual host config:
http://httpd.apache.org/docs/2.2/vhosts/name-based.html
http://httpd.apache.org/docs/2.2/vhosts/mass.html
It is over 10 months now, so I'll just suggest what I have found.
While writing directly to httpd.conf seems the only way, but recently our site change the server. It has cause us so much trouble in those file / folder permission, and the hosting company refuse to help us due to security concern.
So I have a second look and discovered I am using CPanel for hosting, I can certainly use Addon Domain feature to create and add in new domains.
But it has its limits. Since it is an addon domain, we can no longer limit the bandwidth and disk usage per domain. Everything is shared. But that doesn't matter to us anyway.
So far it works. You can do it by either using the CPanel API library available on the official cpanel website, or you can use the direct URL request way to create the domain. Since we are making a new wordpress install, we create a new database as well.
http://{username}:{password}#{mysite.com}:2082/frontend/x3/sql/addb.html?db={dbname}
http://{username}:{password}#{mysite.com}:2082/frontend/x3/sql/adduser.html?user={dbuser}&pass={dbpass}
http://{username}:{password}#{mysite.com}:2082/frontend/x3/sql/addusertodb.html?db={dbname}&user={dbuser}&ALL=ALL
http://{username}:{password}#{mysite.com}:2082/frontend/x3/addon/doadddomain.html?domain={newsite.com}&user={ftp_user}&dir={ftp_dir}&pass={ftp_pass}&pass2={ftp_pass}
It doesn't have to be wordpress. You can use this to install joomla, drupal, phpbb or even you custom script.
Hope it helps anyone who is reading this. Thanks.

Categories