In my operational Wordpress enabled Ubuntu instance, I have a 000-default.conf file with the settings:
./apache2/sites-available/000-default.conf: ServerName $domain
./apache2/sites-available/000-default.conf: ServerAlias www.$domain
grepping for \$domain inside etc gives me basically only this file.
Where does Apache get this value when running my site?
full 000-default.conf:
UseCanonicalName On
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName $domain
ServerAlias www.$domain
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<FilesMatch \.php$>
# 2.4.10+ can proxy to unix socket
SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
$domain is not a pre-defined variable in Apache HTTPD. The list of variables in the documentation does not have it.
As Environment variables are accessed using a %{VAR}-notation in Apache, so it is not read from the environment either.
It's also not in my 000-default.conf - which means it must be something specific to your setup.
And indeed it is! Wordpress includes that file in sites-available with $domain as a placeholder. During setup, the file gets copied into sites-enabled and the placeholder gets replaced. Look in sites-enabled/000-default.conf and instead of $domain, there should be your domain.
Related
I'm trying to change Laravel base URL to localhost/laravel5, I tried to change APP_URL variable in .env file, I did the same changes to this line in config/app.php file:
'url' => env('APP_URL', 'http://localhost/laravel5')
And here my /etc/apache2/sites-available/laravel.conf file:
<VirtualHost *:80>
ServerName localhost/laravel5
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/laravel5/public
<Directory /var/www/html/laravel5>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I also tried to restart apache2 service, but nothing changes
Make your virtual server like this in apache
<VirtualHost *:80>
ServerName laravel5.app
DocumentRoot /var/www/html/laravel5/public
<Directory /var/www/html/laravel5/public>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and run
sudo a2ensite laravel5.app
service apache2 reload
Finally, make sure to edit your /etc/hosts file and add an entry for laravel5.app:
# other entries...
# your entry...
127.0.0.1 laravel5.app
And then you can access your app at http://laravel5.app
I recommend You to use something like Homestead or Valet for developing Check the docs here
everybody.
I have a Cent OS 6.6 server with Apache + mod_php site (site1.local). I need to configure second site (site2.local) with php_cgi. So, I created a user, gave him permissions on www-folder, configured site1 as mod_php, created a phpinfo.php. Also, I installed php-cgi,and try to configure virtual hosts, works only first site, on the second site is error:
the requested url /cgi-bin/phpinfo.php was not found onthis server.
That's my configs:
cat /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerAdmin webmaster#site1.local
DocumentRoot /var/www/wwwmaster/site1.local
ServerName site1.local
ServerAlias www.site1.local
ErrorLog logs/site1.local-error_log
CustomLog logs/site1.local-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#site2.local
DocumentRoot /var/www/wwwmaster/site2.local
ServerName site2.local
ServerAlias www.site2.local
ScriptAlias /cgi_bin/ /usr/bin/php-cgi/
Action php-cgi /cgi-bin
AddHandler php-cgi php
<Directory /usr/bin/php-cgi>
Allow from all
</Directory>
<Directory "/var/www/wwwmaster/site2.local/">
<FilesMatch "\.php">
SetHandler php-cgi
</FilesMatch>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
ErrorLog logs/site2.local-error_log
CustomLog logs/site2.local-access_log common
</VirtualHost>
What I've done wrong and how can I fix that?
You only have to uncomment the line that says NameVirtualServer *:80 in your apache config file.
If you want virtual server for more than one port, simply put as many NameVirtualServer *:[port number] in the apache config file as you need.
I'm running a http server on Debian (Apache 2) with one IP address. I have few domains and SVN running on the server as well. At the moment I have configuration that points my domains to the correct folders on my server with VirtualHosts.
I have done all my VirtualHosts configurations only in the file called "/etc/apache2/sites-available/default". Is this the correct way to do it, or should I make a new file for every website I'm running on my server?
At this moment, my VirtuaHosts file (/etc/apache2/sites-available/default) looks like this:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain1.com
ServerAlias domain1.com
DocumentRoot /var/www/domain1
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain2.com
ServerAlias domain2.com
DocumentRoot /var/www/domain2
</VirtualHost>
<VirtualHost *:80>
ServerName svn.myhostname.com
DocumentRoot /var/svn
<Directory /var/svn/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Location />
DAV svn
SVNParentPath /var/svn
AuthType Basic
AuthName "Subversion"
AuthUserFile /etc/subversion/svn-auth
Require valid-user
</Location>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/svn.error.log
CustomLog ${APACHE_LOG_DIR}/svn.access.log combined
</VirtualHost>
There is no 'correct' way. You could also make an extra file for every Vhost. I for example have all my VHosts in /etc/apache2/httpd.conf and included it via Include httpd.conf in /etc/apache2/apache2.conf.
But if you want it to be a bit structured you CAN use the Apache2 built in VHosts System in /etc/apache/sites-availible/ with multiple files for every site (VHost).
If you want you could use nano /etc/apache2/sites-availible/mypage1 and then activate or deactivete it via the a2ensite command. Like a2ensite mypage1.
I am running Apache using mod_proxy_fcgi and PHP-FPM and am trying to get it to work Symfony. This is my first project using Symfony and am just getting a feel for it at the moment..
My vhost definition currently looks like:
<VirtualHost *:80>
ServerName symfony.dev
Documentroot "/vagrant/symfony/web"
DirectoryIndex app.php
ProxyTimeout 600
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:5090/vagrant/symfony/web/$1
<Directory "/vagrant/symfony/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
When I go to http://symfony.dev/app_dev.php/, the page loads, but all the links/paths include the full filesystem page. For example, the link for "Run the demo" is http://symblog.dev/vagrant/symfony/web/app_dev.php/demo/.
Is there a different ProxyPassMatch rule that would work, or a Symfony config that can compensate?
I tried ^/(.*\.php)(/.*)?$ which gets app_dev.php/ to load, but then app_dev.php/demo/ seems to load app_dev.php and not the demo, with broken paths to inline resources.
I had the same problems with ProxyPassMatch, but with and SetHandler everything works fine.
<VirtualHost *:80>
ServerName project.dev
ServerAlias www.project.dev
<FilesMatch \.php$>
SetHandler proxy:fcgi://127.0.0.1:9000
</FilesMatch>
#ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/project/web/$1
## Vhost docroot
DocumentRoot "/var/www/project/web"
## Directories, there should at least be a declaration for /var/www/awesome
<Directory "/var/www/project/web">
AllowOverride All
Order allow,deny
Allow from All
</Directory>
## Load additional static includes
## Logging
ErrorLog "/var/www/project/app/logs/apache2/error.log"
ServerSignature Off
CustomLog "/var/www/project/app/logs/apache2/access.log" combined
## SetEnv/SetEnvIf for environment variables
SetEnv APP_ENV dev
## Custom fragment
</VirtualHost>
I've added VirtualHost
ServerAdmin root#localhost
DocumentRoot /var/www/html/blogovet.ru
ServerName www.blogovet.ru
ServerAlias blogovet.ru
But my script in this domain can see all server files /* not only in his directory /var/www/html/blogovet.ru
How to forbid viewing files except DocumentRoot ?
A script will be able to read all files that the user running the script can read. So you should make sure your web server does not run as root (it needs to be started as root to listen on port 80, but should swich user to e.g. "www" itself), and then make sure that that user can't read any sensible files.
You could also use SElinux for an extra layer of security.
I found this solution for PHP (If disable cgi and ssi, looks good)
<VirtualHost *:80>
ServerAdmin root#localhost
DocumentRoot /var/www/html/site.com
ServerName www.site.com
ServerAlias site.com
ErrorLog /var/www/html/site.com/error-log
# TransferLog /var/www/html/site.com/transfer-log
# CustomLog /var/www/html/site.com/access-log common
<IfModule mod_php5.c>
php_admin_value upload_tmp_dir "/tmp"
php_admin_value include_path ".:/usr/share/pear:/usr/share/php:/var/www/html/site.com"
php_admin_value open_basedir "/var/www/html/site.com"
php_admin_value doc_root "/var/www/html/site.com"
</IfModule>
<Directory "/var/www/html/site.com">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>