Dynamic subdomain with .htaccess (centOS) - php

I have a dedicated server, on which I'm running several project. Lets say this is example.ro.
The server is running CentOS 6.
I've created a unix user 'dev' and a subdomain: dev.example.ro.
Lets say that I want to work on a project called 'cpl', and I have to test it live on this server (it is a php project).
I would like to use the subdomain dev.cpl.example.ro, and on the filesystem it would be under /home/dev/public_html/cpl folder.
How should I modify my .htaccess in the public_html folder in order to dynamically use subdomains?

I don't think you need to edit the .htaccess file to achieve this. But you have to create a separate site in Apache server. To demonstrate I am using am ubuntu lamp server but I think you can do the same on your CentOS.
Create a virtual site in Apache
sudo nano -w /etc/apache2/sites-available/example.conf
paste the following into the file and make necessary changes
<VirtualHost *:80>
ServerName cpl.example.ro
ServerAlias *.cpl.example.ro
DocumentRoot /home/dev/public_html/cpl
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Save the file. After that you need to enable the newly site.
sudo a2ensite example
service apache2 restart
Edit the host file to resolve the dev.cpl.example.ro
sudo nano -w /etc/hosts
add the following line to the end and save the file
127.0.0.1 dev.cpl.example.ro

Related

Change Apache directory to show Wordpress homepage

I have Wordpress installed using an AWS EC2 instance. The public IP is as here. I used LetsEncrypt to get SSL, that worked fine. But after that, my homepage now shows the 'Apache2 Ubuntu Default Page'. It should be showing me the Wordpress homepage. I still have ssh access to the EC2 (Bitnami Wordpress), so my data is supposedly still there.
I've been doing some research at it seems that I need to change something with Apache so it direct to the Wordpress directory/page.
Any help in the matter would be most appreciated :)
Bitnami Engineer here,
It seems you installed the Apache2 system's service in the machine and it got started at boot time. The Bitnami apps don't use the system's services. That's why the Bitnami's Apache service can't be started because other service is already running in the 80 port. In order to stop and disable it, please run these commands
sudo service apache2 stop
sudo service apache2 disable
sudo /opt/bitnami/ctlscript.sh start apache
Happy to help!
The fact that you're getting the Apache default page is a good sign, it means everything from a networking standpoint is working correctly. Now, you just need to show Apache where to serve your files.
Apache stores their default configuration typically in /etc/httpd/httpd.conf or /etc/apache2/sites-available/default and looks something like below.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Before making changes to this file (whenever you find it), you will also need to know where the DocumentRoot is. This is essentially the directory that your index.php is located. In the example above it's located in /var/www, and that's typically a good place to start looking.
If you're having a hard time finding your root directory, you can do something like find / -type f -name "index.php".
Assuming your index.php is in /var/www/wordpress your configuration could look as simple as this.
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/wordpress
</VirtualHost>

VPS ubuntu apache server - web page

I bought a VPS server, where I installed apache, mysql, php and phpmyadmin. I created database (like in my local project).
So, now I want to migrate a local project to my server and please, tell me I am right:
Files .php has to be in folder var/www on my apache server? (here is index.html too) and from this folder connect with database?
I have to download NPM on ubuntu
I have to download GIT on ubuntu
Download repo from my github where I've got whole code (webpack dist files, node modules, src and whole config) to /var/www catalog
index.html has to be in top-level directory (just in var/www not for example var/www/src
Please help me and tell if I am thinking right.
Files .php has to be in folder var/www on my apache server? (here is index.html too) and from this folder connect with database?
It depends on what you set in /etc/apache2/sites-available/000-default.conf. I assume that you installed with default configuration from apt-get.
index.html has to be in top-level directory (just in var/www not for example var/www/src
If for example your source codes are in /var/www/src instead of /var/www, the just modify the 000-default.conf. Example:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName your_domain_name.com
DocumentRoot /var/www/src/
<Directory />
Options FollowSymLinks
AllowOverride None
Options -Indexes
</Directory>
<Directory /var/www/src>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
Options -Indexes
</Directory>
ErrorLog /var/log/your_log_file.log
LogLevel warn
CustomLog /var/log/your_access_log_file.log combined
</VirtualHost>
Restart Apache and try open in your browser to see if it works.
As for the database, since you have phpmyadmin, just export the sql data from your local machine and import it into the VPS phpmyadmin.

Index of / with blank page output on server

I uploaded my PHP(codeigniter) project on server. But when I run it I get below window
Index of /
Name Last modified Size Description
Apache Server at 'ip address here' Port 80
project folder is in /var/www/
DocumentRoot is set in projectName.conf directory as /var/www/projectName
Make sure your site .conf points to the public folder and not the site root.
<VirtualHost *:80>
ServerName site.co.uk
DocumentRoot /var/www/site.co.uk/public
<Directory "/var/www/site.co.uk/">
Options -Indexes +FollowSymLinks
Order allow,deny
Allow from all
AllowOverride FileInfo All
Require all granted
</Directory>
</VirtualHost>
You have to make sure about 3 points for this issue
Need .htaccess file in /var/www/projectName/.htaccess which is provided by Codeigniter
Must have rewrite module enabled.
If you are using Ubuntu OS and apache2 then execute sudo a2enmod rewrite in your terminal to enable this.
Must allow override URL by .htaccess rule in apache.conf for /var/www folder.
If you are using Ubuntu OS and apache2 then edit file /etc/apache2/apache.conf and change AllowOverride none to AllowOverride All in block/section of <directory /var/www> and then restart apache by sudo service apache2 restart command.

What is wrong in the deploy of this Laravel application? Need I an effective domain instead the vhost used on my local environment?

I am pretty new in PHP and moreover in Laravel and I am pretty desperate trying to deploy a Laravel 5.4 application that works fine on my local environment on my Linux remote server.
So I think that it is something related to virtual host configuration or something like this (maybe also something related to the .htaccess file)
In my local environment (I am using XAMPP on Windows) I have setted this virtual host into the C:\xampp\apache\conf\extra\httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/HotelRegistration/public"
ServerName laravel.dev
</VirtualHost>
So opening the laravel.dev URL I obtain the standard Laravel homepage (I have yet not replaced it with a landing page).
Then if I open this URL: http://laravel.dev/registration
I obtain the user registration page developed by me, this because I have this route into my web.php file into my project:
Route::resource('/registration', 'RegistrationController');
Then into my RegistrationController.php there is this method showing the resources/views/registration/index.blade.php view
public function index(){
return view('/registration/index');
}
All works fine.
Now I have uploaded this Laravel website into my remote Linux server, into this folder: /var/www/html/HotelRegistration
But now my problem is that in this remote environment I have not virtual host (correct me if I am doing wrong assertion: from what I have understand the virtual host is used on the local environment to simulate a domain that Laravel need to point to the public folder, is it this reasoning correct?)
Anyway, this is the URL of the public folder of my deployed web site on my remote server:
http://89.36.211.48/HotelRegistration/public/
As you can see opening it the Laravel landing page is correctly shown, the problem is that I can access to the previous registration page, the only way that I have found is to open this URL:
http://89.36.211.48/HotelRegistration/public/index.php/registration
but it is pretty horrible and above all when the registration form is submitted it is generated a POST request toward this URL http://89.36.211.48/registration that end into a 404 Not Found error.
So I think that it depend by the fact that in this remote server I can't use a virtual host that simulate a domain (as I have on my local environment), but I am not sure about it.
What can I do to solve the situation? Do you think that using a effective domain (something like: www.myregistration.com) that points to this directory of my remote server http://89.36.211.48/HotelRegistration/public/ I can solve this problem?
You need to configure your domain in your server and need to reconfigure the apache. I'm considering you are having apache2 server so here you can do:
Step 1 Go to the apache2 folder cd /etc/apache2
Step 2 You can see sites-available folder go inside it cd sites-available
Step 3 Make a new file name it laravel.dev.conf
Step 4 Write down the following sudo nano laravel.dev.conf
Step 5 Write down the following option:
<VirtualHost *:80>
ServerAdmin webmaster#laravel.dev
ServerName laravel.dev
ServerAlias www.laravel.dev
DocumentRoot /var/www/html/laravel.dev/public/
ErrorLog /var/www/html/laravel.dev/logs/error.log
CustomLog /var/www/html/laravel.dev/logs/access.log combined
<Directory /var/www/html/laravel.dev/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Step 6 Now go to this folder/create a new one cd /var/www/html/laravel.dev
Step 7 Copy/Install your laravel application here.
Step 8 Now you can enable your site by typing sudo a2ensite laravel.dev.conf
Step 9 Now restart the apache2 sudo service apache2 restart
Now you can have proper access to your domain. Hope this helps.
Since you are using XAMPP
Add the following into your VirtualHost Directive:
<Directory "LINUX PATH TO /HotelRegistration/public">
AllowOverride All
</Directory>
Your final VirtualHost Directive should look like:
<VirtualHost *:80>
DocumentRoot "LINUX PATH TO /HotelRegistration/public"
ServerName 89.36.211.48
<Directory "LINUX PATH TO /HotelRegistration/public">
AllowOverride All
</Directory>
</VirtualHost>
After the configuration changes, restart Apache then you are good to go.

How to create virtual hosts in apache ubuntu 11.04

I want to create virtual hosts for my project in zend framework. I have frontend and backend (admin) functionality. I created the virtual host for my frontend functionality with necessary configuration and it running properly.
Example: In /etc/apache2/sites-available I created the file roomstays and my code is in var/www folder.
<VirtualHost *:80>
DocumentRoot "/var/www/roomstays/public"
ServerName localhost
#This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "/var/www/roomstays/public">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And it running properly with localhost.
Now I have admin i.e.backend code and as previous one I want to run this code. I put my newer code into same var/www directory with named roomstaysback. My question is how to create virtual host for this backend code. I want to run both frontend and backend side code.
Please give me any solution I am completely new in it thanks.....
You can handle both front end and back end from same virtual host. zend framework provides the concept of modules. Here is one example. Have a look
Setup multi modules in Zend Framework v1.9 with 13 steps
and the detailed one is here
Using a Conventional Modular Directory Structure
1.Create a conf file for virtual host
$sudo gedit /etc/apache2/sites-available/HOST_NAME.conf
2.then paste following contents to this file
<VirtualHost *:80>
ServerName www.HOST_NAME.com (set host name here)
DocumentRoot /var/wwww/HOST_FOLDER (point to host path )
</VirtualHost>
Add host name
$sudo gedit /etc/hosts
Then paste following contents
127.0.0.1 www.HOST_NAME.com
enable the site
$sudo a2ensite HOST_NAME.conf
Restart apache server
$sudo service apache2 reload
The process is over and you can browse www.HOST_NAME.com :)

Categories