Virtual Host won't run Symfony2 - php

I have Apache2 installed and I have this setup up on my virtual host pointing out to my symfony project.
<VirtualHost *:80>
ServerName topbesterp
ServerAlias www.topbesterp.tld
DocumentRoot /var/www/topbesterp/web/
<Directory /var/www/topbesterp/web/>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
<Directory /var/www/topbesterp/web/>
Options FollowSymlinks
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
I have added the codes up at the end of the apache2.conf.
And these are the things i added for hosts file
127.0.0.1 localhost
127.0.0.1 topbesterp
Whenever I run http://topbesterp on my browser, I receive a blank page.
But whenever I change the Directory of the virtual host to a project that is non-symfony based, it runs okay. Why?

Assuming that you're on LAMP environment so follow the steps below. If MAC then this.
1.
sudo nano /etc/apache2/sites-available/topbesterp.local.conf
<VirtualHost *:80>
ServerName topbesterp.local
ServerAlias www.topbesterp.local
ServerAdmin admin#topbesterp.local
DocumentRoot /var/www/topbesterp/web
<Directory /var/www/topbesterp/web/>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/topbesterp.local.error.log
CustomLog ${APACHE_LOG_DIR}/topbesterp.local.access.log combined
</VirtualHost>
2.
sudo a2ensite topbesterp.local.conf
sudo service apache2 restart
3.
sudo nano /etc/hosts
127.0.0.1 topbesterp.local www.topbesterp.local

replace /var/www/topbesterp/web/
for
/var/www/topbesterp/web/app_dev.php
or
/var/www/topbesterp/web/app_dev.php

In fact, you don't specify a directory index in your virtual host, try this to get symfony2 first page (app_dev.php is used in development/app.php in production) :
<VirtualHost *:80>
ServerName topbesterp
ServerAlias www.topbesterp.tld
DocumentRoot /var/www/topbesterp/web
<Directory /var/www/topbesterp/web>
DirectoryIndex app_dev.php
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
<Directory /var/www/topbesterp/web/>
Options FollowSymlinks
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>

As per my comment, you would need to check app/logs/dev.log or app/logs/prod.logdepending on what environment you are running your application.
If you see some writing errors in the cache/logs folder, you'd need to set up the proper permissions to the app/cache/* and the app/logs/* folders.
Alternatively, you can add umask(0000); at the beginning of the following files:
app/console
web/app_dev.php
web/app.php
And you'd be good to go.

Related

How can I run my Laravel project without cmd command "php artisan serve"?

<VirtualHost *:80>
ServerAdmin webmaster#hujjaj.dev
DocumentRoot "C:\xampp\htdocs\hujjaj_app_new\public"
ServerName hujjaj.dev
ErrorLog "logs/hujjaj.dev-error.log"
CustomLog "logs/hujjaj.dev-access.log" common
I am doing so in my virtual host file and update 127.0.0.1 hujjaj.dev then i restart XAMPP and after that I navigate to localhost/hujjaj.dev but showing 404|Not Found.
Please try the following
<VirtualHost 127.0.0.2:80>
DocumentRoot “D:\laravel-gkb\public”
DirectoryIndex index.php
ServerName laravel-gkb.test
<Directory “D:\laravel-gkb\public”>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
Then add the save domain in your hosts file
127.0.0.2 hujjaj.dev
Refer this for more details : link
Yes, There is another way to run laravel project, with following command..
php -S 127.0.0.1:8001 server.php
This will run your application at 127.0.0.1:8001 mentioned address.
Note: laravel default entry point is server.php thats why we mentioned it. other wise it will be index.php

apache2.conf and httpd.conf

After reading ubuntu AMP community and Apache 2.4 configuration.
I was wondering if there is a way to imitate the same behavior of the http docs used in XAMPP or bitnami stacks but using the default LAMP. Which uses apache 2.4
In XAMP you would assign an extra number to your httpd-vhost.conf like this:
Listen *:9000
<virtualhost *:9000>
ServerName localhost
DocumentRoot "~/xamp/apache2/htdocs/html/app-name/"
</virtualhost>
<Directory "~/xamp/apache2/htdocs/html/app-name/">
Options Indexes FollowSymLinks
AllowOverride all
</Directory>
Then Edit your httpd.conf files like:
//....Some code..... */
<Directory>
AllowOverride all
<Directory />
//...Some code...
and uncomment this line:
//....Some code..... */
# Virtual hosts
include conf/extra/httpd-vhosts.conf
//...Some code...
My question is:
Is there is a way to configure Apache 2.4 just by dropping all my vhost's in one single file, without having to go through the process of configuring etc/apache2/sites-available and then adding names to etc/hosts?
Then completing the process by including some things like above just like Bitnami or Xamp stacks will do so your localhost will be able to serve not only static html files but an entire application's folder.
What works is the following in (for example) your 000-default.conf:
<VirtualHost *:80>
ServerName site1.vm
ServerAdmin webmaster#localhost
DocumentRoot /var/www/site1/web/
ErrorLog ${APACHE_LOG_DIR}/site1_error.log
CustomLog ${APACHE_LOG_DIR}/site1_access.log combined
<Directory /var/www/site1/web/>
Options All
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName site2.vm
ServerAdmin webmaster#localhost
DocumentRoot /var/www/site2/web/
ErrorLog ${APACHE_LOG_DIR}/site2_error.log
CustomLog ${APACHE_LOG_DIR}/site2_access.log combined
<Directory /var/www/site2/web/>
Options All
AllowOverride All
</Directory>
</VirtualHost>
This way all you have to do is add the site to the conf file, add the host to your hosts file, and reload apache2 service. Hope that is what you were looking for.

Several virtual hosts on the same port with Apache 2.4

I'm trying to do something simple with virtual hosts in Apache 2.4 (using Wampserver 2.5)
I want to be able to have several virtual hosts and access them simply by :
www.project1.dev
www.project2.dev
So I made the following configuration in httpd.conf by reading the official guide :
NameVirtualHost \*:80
#
# Project 1
#
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/myProject1/"
ServerName www.project1.dev
ErrorLog "logs/project1-error_log "
CustomLog "logs/project1-access_log" common
<Directory "C:/wamp/www/myProject1/">
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
#
# Project 2
#
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/myProject2/"
ServerName www.project2.dev
ErrorLog "logs/project2-error_log "
CustomLog "logs/project2-access_log" common
<Directory "C:/wamp/www/myProject2/">
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
I also added them to my hosts file
127.0.0.1 http://project1.dev
127.0.0.1 http://project2.dev
But while I'm testing after restart wamp services, both http://project1.dev and http://project2.dev point at C:/wamp/www/myProject1/
The second path C:/wamp/www/myProject2/ related to project2.dev seems to be ignored.
Am I missing something?
Thanks.
You have not defined http://project2.dev anywhere - just http://www.project2.dev. So Apache defaults back to first config as it can't find a match.
Add the following config to the first vhost:
ServerAlias project1.dev
and similarly this to the second:
ServerAlias project2.dev
Then restart Apache.
The simple answer is that as of Apache 2.4 the NameVirtualHost *:80 syntax is no longer required or allowed! It throws an error and causes Apache not to start. The error will appear in the apache error log if you look for it.
Oh and NameVirtualHost \*:80 was never right!
So just remove the line NameVirtualHost \*:80 completely.
As soon as you define a Virtual Host, the localhost in httpd.conf gets ignored so you should define that in httpd-vhost.conf as well, otherwise the other 2 VH defs look fine, except for the ServerName and missing ServerAlias and the missing Options
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/"
ServerName localhost
<Directory "C:/wamp/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require local
</Directory>
</VirtualHost>
#
# Project 1
#
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/myProject1/"
ServerName project1.dev
ServerAlias www.project1.dev
ErrorLog "logs/project1-error_log "
CustomLog "logs/project1-access_log" common
<Directory "C:/wamp/www/myProject1/">
AllowOverride all
Options Indexes FollowSymLinks MultiViews
Require all granted
</Directory>
</VirtualHost>
#
# Project 2
#
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/myProject2/"
ServerName project2.dev
ErrorLog "logs/project2-error_log "
CustomLog "logs/project2-access_log" common
<Directory "C:/wamp/www/myProject2/">
AllowOverride all
Options Indexes FollowSymLinks MultiViews
Require all granted
</Directory>
</VirtualHost>
Quote: But while I'm testing after restart wamp services, both http://project1.dev and http://project2.dev point at C:/wamp/www/myProject1/
If there is an error in your VH definitions, Apache will default to the first correctly defined VH in the httpd-vhosts.conf, so thats what is probably happening
As to your HOSTS file it should include references to the IPV4 and IPV6 stack, especially as windows seems to use the IPV6 stack more and more, afterall that where we are moving to, eventually, and it should not include httpd:// so it should be like this :-
#IPV4 stack ip addresses
127.0.0.1 localhost
127.0.0.1 project1.dev
127.0.0.1 project2.dev
#IPV6 stack ip addresses
::1 localhost
::1 project1.dev
::1 project2.dev
Once you have changed the HOSTS file, you either need to reboot, or do the following in a command windows launches with "Run as Administrator"
net stop dnscache
net start dnscache

Laravel virtual server routing doesn't work

I have installed newest Laravel on my Apache2. I run in Terminal
php artisan serve --port=8080
And It works. I have sub-pages and everything I need. But I want to have access without run this command.
I have next mylaravel.com.conf file in /etc/apache2/sites-available
<VirtualHost *:80>
ServerName mylaravel.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/mylaravel/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
My Laravel files is of course in /var/www/mylaravel. In this configuration mylaravel.com works, but when I try for simple mylaravel.com/auth/register Apache return
When I used php artisan [...] this works fine. How can I fix it?
I had this same problem a while ago. From here:
If you don't have AllowOverride set to All, your Laravel .htaccess file (/public/.htaccess) won't be able to enable mod_rewrite, and your routes won't work.
Try adding the following to your <VirtualHost> block:
<Directory "/var/www/mylaravel/public">
Options All
AllowOverride All
Allow from all
</Directory>
So all up you'd have:
<VirtualHost *:80>
ServerName mylaravel.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/mylaravel/public
<Directory "/var/www/mylaravel/public">
Options All
AllowOverride All
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I found something. I added Sadurnias code and run in Terminal
sudo a2enmod rewrite
sudo service apache2 restart
Of course I changed chmod of /var/www to 755.
It's working fine, only when I run mylaravel.com/css FireFox doesn't end this request, but others is fine.

Apache virtual host without domain name

I have a VPS with apache2 installed and I would like to access some PHP projects without a domain name just with the IP address. For example:
http://162.243.93.216/projecta/index.php
http://162.243.93.216/projectb/index.php
I have other projects with domain like example.com, in my directory /var/www/
/html/
info.php
/projecta/
/projectb/
/example/
When I go to
http://162.243.93.216/info.php then /var/www/html/info.php is opened.
My file 000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
" http://162.243.93.216/info.php then /var/www/html/info.php is opened "
I am assuming this already works (If not, uncomment the ServerAlias line shown in the conf below)
You now want to map
http://162.243.93.216/projecta/ to /var/www/projecta
http://162.243.93.216/projectb/ to /var/www/projectb
For this you need to use the Apache Alias directive.
Update your 000-default.conf file to:
<VirtualHost *:80>
# ServerAlias 162.243.93.216
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
Alias /projecta /var/www/projecta
Alias /projectb /var/www/projectb
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Create a new virtual host file, and setup like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerAlias 192.168.1.1
DocumentRoot /somewhere/public_html
<Directory /somewhere/public_html/>
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride Authconfig FileInfo
Require all granted
</Directory>
</VirtualHost>
add the serveralias and it will recognize the IP address as well ...
if you want to add more IP addresses (like local network second interface), you can add more serveralias lines ...
Step Six — Set Up Local Hosts File (Optional)
If you have been using example domains instead of actual domains to test this procedure, you can still test the functionality of your virtual hosts by temporarily modifying the hosts file on your "LOCAL COMPUTER". This will intercept any requests for the domains that you configured and point them to your VPS server, just as the DNS system would do if you were using registered domains. This will only work from "YOUR COMPUTER", though, and is simply useful for testing purposes.
Note: Make sure that you are operating on your local computer for these steps and not your VPS server. You will need access to the administrative credentials for that computer.
If you are on a Mac or Linux computer, edit your local hosts file with administrative privileges by typing:
sudo vi /etc/hosts
If you are on a Windows machine, you can find instructions on altering your hosts file here.
The details that you need to add are the public IP address of your VPS followed by the domain that you want to use to reach that VPS:
127.0.0.1 localhost
127.0.1.1 guest-desktop
server_ip_address example.com
server_ip_address example2.com
reference:https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-7?utm_source=Customerio&utm_medium=Email_Internal&utm_campaign=Email_CentOSDistroNginxWelcome&mkt_tok=eyJpIjoiTnpWbU5tUTJPV1F5TVRBMyIsInQiOiJhd0JCQVI0NDd0ZWprUDFaaDlhbENcL0lyTjdSbnhwMEpkTE1QcXJTcHl1ZXFhNURKVmVBZHFKMk92RW1kSFwvMHowOW0zcExhaUdyOU42U2lLbk1Cd2FRYzB4XC9lbkhlWnd1ekZOcW1sZVhRYlwvT0xrTUpmQ2dEK2dNVUw4alFrc00ifQ%3D%3D

Categories