I'm working to deploy Laravel 5.3 project to Ubuntu 16.04 Server.
The tutorial I'm following says that there should be
DocumentRoot /var/www
<Directory /var/www>
in the "/etc/apache2/sites-enabled/000-default" file and I should edit them to be :
DocumentRoot /var/www/project/public
<Directory /var/www/project/public>
I found :
DocumentRoot /var/www
but didn't find :
<Directory /var/www>
I tried to put it and put this inside the directory tag
RewriteEngine On
RewriteBase /var/www/project/public
but it results in errors while restarting apache.
What should I do ??
You need to copy you default-000.conf don't overwrited, and no from sites-enabled but from sites-available
sudo a2enmod rewrite //active mode rewriting
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mysitename.com.conf
sudo nano /etc/apache2/sites-available/mysitename.com.conf
Paste the vhost :
<Directory /var/www/project/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
After this save and do a :
sudo a2ensite mysitename.com.conf
sudo a2dissite 000-default.conf
Add an htaccess to you root folder :
sudo nano /var/www/project/public/.htaccess
sudo chmod 644 /var/www/project/public/.htaccess
sudo chown www-data:www-data -R /var/www //to be sure you have rights
sudo service apache2 reload //to take the new configuration
sudo service apache2 restart //apply ...
Paste you directive rewriting
RewriteEngine On
RewriteBase /var/www/project/public
Related
Moving from Ubuntu 17.10 to Mint 18.3 and migrating virtual host config files fails with
[core:error] [pid 3012] (EAI 2)Name or service not known: AH00547: Could not resolve host name
On my fresh installed Mint i have done this first
1) sudo a2dissite 000-default.conf
This is my standard Config File using for Vhosts
<VirtualHost *.domain.localhost:80>
ServerName domain.localhost
ServerAlias www.domain.localhost api.domain.localhost
ServerAdmin webmaster#localhost
DocumentRoot /home/dev/projects/domain/web/html/
<Directory /home/dev/projects/domain/web/html/>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature Off
</VirtualHost>
BTW: This steps i'm doing for every project
1) sudo chown -R www-data:www-data PATH_TO_DIR
2) sudo chmod 660 -R PATH_TO_DIR
3) sudo chmod -R -x+X PATH_TO_DIR
4) sudo find PATH_TO_DIR -type d -exec chmod g+s {} \;
5) sudo setfacl -R -d -m u::rwX,g::rwX,o::- PATH_TO_DIR
UPDATE:
adding domains to /etc/hosts, reloading server leads again to the default
I have solved it by modifying "000-default.conf" DocumentRoot Path, then modifying "/etc/apache2/apache2.conf" by adding these lines
<Directory /home/mdev/_projects/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Also this had to be changed from
<VirtualHost *.domain.localhost:80>
to
<VirtualHost *:80>
No entries at /etc/hosts neccassary!
Using the following posts:
Ubuntu 14.04 apache2 configuration problems
.htaccess file not working on Ubuntu 14.04 with apache2
Apache doesn't execute script of index.php in root automatically
I've changed my /etc/apache2/apache2.conf file to be the following:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory
And I've created the file /var/www/html/.htaccess to be the following:
DirectoryIndex Index.php index.php Index.html index.html Index.htm index.htm
When I go to my site, the default page is still the (It Works!) index.html file.
How do I configured Apache to give priority to index.php?
Is your DocumentRoot /var/www/ or /var/www/html/ (the latter is where you say you have your .htaccess file)??
If the .htaccess is in /var/www/html/ than I'm gonna guess you need to update your Apache config to be:
<Directory /var/www/html/>
Upgraded to Mavericks and edited httpd.conf to enable php and virtual hosts. That's the only change made. Now when I try to access localhost I get the error: Forbidden - you don't have permission to access xxxxx
Any ideas how to fix this?
The problem results from php not being executed any more, try to call e.g. the index.php directly and you will very likely see the sourcecode of your file.
go to /etc/apache2/httpd.conf and uncomment:
LoadModule php5_module libexec/apache2/libphp5.so
you have to restart your apache afterwards, so execute on command line:
sudo apachectl -k restart
Following steps made it work for me:
Add an error_log path to your misbehaving vhost entries, so you can
track the problem more closely
<VirtualHost *>
...
ErrorLog "/accessible/path/to/error_log"
</VirtualHost>
Restore all your previous apache settings, to be found at /etc/apache2/httpd.conf~previous
Make sure your chmod and chown rights are up to date
Alter documentRoot settings if necessery (adding + did the trick for me)
<Directory "/path/to/webroot">
Options +Indexes +FollowSymLinks +SymLinksIfOwnerMatch +MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Optionally, add following entry to your .htaccess file
Options +Indexes +FollowSymLinks +SymLinksIfOwnerMatch +MultiViews
Extra hint
Incase you are using php, restore your ini file by copying php.ini-5.2-previous to php.ini
$ cd /private/etc/
$ sudo cp php.ini-5.2-previous php.ini
Sources
http://brianflove.com/2013/10/23/os-x-mavericks-and-apache/
http://jason.pureconcepts.net/2012/10/install-apache-php-mysql-mac-os-x/
Options FollowSymLinks or SymLinksIfOwnerMatch is off
My htaccess file works on localhost but doesn't work when i deploy it to EC2 instance.
I'm using Macbook and in finder i cannot see the htaccess file, i thought that perhaps it didn't get copied to EC2 instance but i don't think this is the problem because when i copy the project i can see the htaccess file in my editor.
Is there something enabling mod rewrite in EC2 linux instance? If there is, i didn't do it or it enables mod rewrite as default?
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
I pieced together some info from various posts so I thought I'd put up an answer.
As Paul commented, If you're running Amazon EC2 Linux, you're probably running httpd instead of Apache. The file is therefore in /etc/httpd/conf/httpd.conf
You have to change the file as root user. (from ssh access) Do this: sudo vim /etc/httpd/conf/httpd.conf (How to edit httpd.conf file in AMAZON EC2)
DocumentRoot "/var/www/html" was listed in two places for me. I had to change the subsequent AllowOverride None to AllowOverride All in those two places.
Restart apache. I restarted my whole ec2 instance (i have apache configured to start automatically) although just restarting apache should work. But I see the change is working.
I was trying to make the same changes in a .htaccess file (removing the index.php from urls in a code igniter application). Hope it helps!
By default EC2 doesn't have .htaccess enabled, you must edit your httpd.config to allow for it.
In /etc/apache/sites-available/default change AllowOverRide = None to AllowOverRide = All.
Its a three step process
Configure apache mod_rewrite,run in terminal.
sudo a2enmod rewrite
add the following code to /etc/apache2/sites-available/default
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
3.Restart apache
/etc/init.d/apache2 restart
There are three steps
Configure apache mod_rewrite,run in terminal. sudo a2enmod rewrite
Add this code in this file after closing VirtualHost tag /etc/apache2/sites-available/000-default.conf
DocumentRoot /var/www
Options FollowSymLinks
AllowOverride All
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Restart apache server by command
sudo service apache2 restart
When you using the apache2 server
Go to the following directory.
cd /etc/apache2/sites-available
If you use LS command here you will see the following file.
000-default.conf
That's the file with default apache configuration which are applied to your sites in /var/www/html folder.
Open this file for editing.
sudo nano 000-default.conf
Add following lines after DocumentRoot /var/www/html line.
Options FollowSymLinks AllowOverride All Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all
Save the file and restart the apache.
sudo service apache2 restart
that's it and now your .htaccess file will work
On Linux enviroment
1 - cd /etc/apache2/sites-available
2 - sudo nano 000-default.conf
and paste this code:
<Directory "/var/www/html">
Order allow,deny
Allow from all
Options None
AllowOverride All
</Directory>
This worked on AWS instance.
In my case, I am not running httpd, but only Apache.
I followed this website and it works.
Step 1: Enable mod_rewrite module in Apache
sudo a2enmod rewrite
Then restart the Apache HTTP server with service command with sudo:
sudo service apache2 restart
or using the systemctl command with sudo:
sudo systemctl restart apache2
Now that we have mod_rewrite enabled, we can proceed further to configure it.
Step 2: Enable the usage of the .htaccess file
sudo nano /etc/apache2/apache2.conf
Find the following section in /etc/apache2/apache2.conf. You should see the code like this:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
and change, from AllowOverride None to AllowOverride All
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
I've a Ubuntu server with static IP for testing purpose, I'd like to create a project (for example hello-world) outside the /var/www/ directory, let's say in this location(/home/username/webroot/hello-world/). It should be accessible via browser like this http://xxx.xxx.xxx.xxx/hello-world/ How do I do this?
I would use an Alias:
Alias /hello-world /home/www/foo
<Directory "/home/www/foo">
Options -MultiViews -FollowSymLinks +SymLinksIfOwnerMatch
AllowOverride all
</Directory>
Enable FollowSymlinks in your Apache-config and make a symbolic link on your file system.
ln -s /path/to/your/project /var/www/projectname
And replacing the content is easy, without having to reload the server
rm /var/www/projectname
ln -s /path/to/your/project-v2 /var/www/projectname
you configure a virtual host in the configuration file of your apache: apache2.conf or httpd.conf:
<VirtualHost *:80>
ServerPath /hello-world
DocumentRoot /home/username/webroot/hello-world
</VirtualHost>