Apache can't find localhost/~user directory - php

Hi every one I'm setting up apache following a tutorial on OS X Yosemite.
I can get to the "It works" page from default WebServer directory but when setting up my own user directory apache doesn't find it anymore. I created the Sites directory in my User folder.
Then I created the username.conf in /etc/apache2/users I also have a Guest.conf there that's not mentioned in my tutorial but I don't know if it is the problem and I'd rather ask than delete it without knowing.
my username.conf file :
<Directory "/Users/mathiashintjens/Sites/">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
I used sudo chmod 644 mathiashintjens.conf to changes privileges then sudo apachectl restart
Then I created an index.html file in my ~/Sites directory and yet I still can't open it in my browser using http://localhost/~mathiashintjens/
I have installed MAMP in the past so maybe here lies the problem?
If anyone could help me it would be really cool.
Thanks in advance!

Related

Apache server Forbidden php

I just got a VPS and it's running CentOS 6.8 with WHM 58.0. I really don't want the WHM, I only want to add one site to the server. So I just installed an FTP server and uploaded the files to the Apache root dir at /usr/local/apache/htdocs and gave all files chmod 777.
All works good, but when I go to PHP or ajax to PHP I get "403 Forbidden". I suppose the problem is in the http.config but I really have no idea. Here is my http.conf file and I don't have any .htaccess files.
Among other things, you want to make sure that the Linux user that is running Apache has permission to read and execute the PHP files where they are on the server.
This is a good guide for transferring PHP files and setting the permissions using PHP: https://www.digitalocean.com/community/tutorials/how-to-use-sftp-to-securely-transfer-files-with-a-remote-server
There's also a guide here to setting up the server and checking that PHP is set up correctly here, but I assume you have done this already: https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04
I just replace this
<Directory "/usr/local/apache/htdocs">
Options Includes Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
With this
<Directory "/usr/local/apache/htdocs">
Options Indexes
Order allow,deny
Allow from all </Directory>

server ip keeps redirecting to defaultwebpage.cgi

I haven't registered any domain for my server.
I might be wrong, but according to my understanding,
the default ip for the server is public.
my server ip is http://166.62.101.242/.
but whenever i ping on that domain, it keeps redirecting to the /usr/local/cpanel/cgi-sys/defaultwebpage.cgi
folder.
I have changed my /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
however it still keeps redirecting to the cpanel page.
what changes do i need to make, so i can access the /var/www folder without registering for a domain?
This redirection is because cPanel uses Block Hosting. You will have to point a domain to the IP Address and tell cPanel to register that domain in your system. I would highly suggest you to get a domain instead of modifying anything with cPanel because if something goes wrong, you may not be able to manage your site. You can get a free domain from freenom.com. If you need further assistance for setting it up, please hit me up and I'll guide you step by step.
It seems there is error in processing .php file in apache.
I have got same problem.
change the ownership of the file.
e.g. if the file name ins info.php
sudo chown nobody:nobody info.php
sudo chmod 644 info.php
Let me know if this help
Also make sure to add .php in
sudo vim /etc/httpd/apache/conf
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml .php
It is looks that you have VPS with a WHM/cPanel.
There are multiple possibilities to set that.
The most easy way is to add an account and set a new domain...
Or can hack the Apache global configuration WHM -> ApacheConfiguration -> Global Configuration and set a new virtual server in premain. The server should have same external and internal IPs
The other way is to hack the main.conf template and change the httpd configuration.
After, you should run:
/services/rebuildhttpdconf
to rebuild the httpd.conf
Please note that your changes in default httpd.conf will be overwrite everytime the cPanel/WHM will restart, so your solution with modification of default /etc/httpd/conf/httpd.conf it is not OK!
Try with the IP instead...
VirtualHost 166.62.101.242:80
...and clean your browser cache! (or you can try this first).
I had the same behavior and I was going to hit my head to the wall because of that :(. The reason why you are getting this is because the content of /etc/httpd/htdocs/index.html IS
<html><head><META HTTP-EQUIV="refresh" CONTENT="0;URL=/cgi-sys/defaultwebpage.cgi"></head><body></b‌​ody></html>
It takes 2 days for me to figure this out. If you managed to land your request on your server but the name you are requesting -the IP in our case- is not exist in the apache virtual hosts, the apache is going to response with this file. ;-)

Symfony 403 Error

I just installed Symfony on my Mac running Yosemite but keep getting 403 errors. This isn't just affecting the directory into which I installed symfony, but also sites in other directories that were previously working fine! So far I have tried:
Following the "Setting up permissions" instructions on the Symfony installation page... http://symfony.com/doc/current/book/installation.html ("Using ACL on a system that supports chmod +a" and "change the umask so that the cache and log directories will be group-writable or world-writable") so I guess the problem isn't to do with the log and cache files.
Updating apache config with...
Require all granted
Allow from All
Checking user permissions:
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
Lots of killing and restarting apache
Still getting..
Forbidden
You don't have permission to access /projectx/ on this server.
Anyone seen this problem before?
Many thanks
Thanks so much for your suggestions, I figured it out. The problem was that I was putting my app in the apache doc root (symfony uses a different web server by default). I needed to create a virtual host (and tell apache to use the httpd-vhosts.conf in the first place)
This article had the answer...http://dab.io/posts/using-apache-for-developing-with-symfony.html
Thanks again!

How to block access folder that not has index file

I using xampp for my project. Now i have a problem
Example i have a project like
myproject\
|-subfolder\
| |---example.php
|-index.php
Now, if i process subfolder in my address like
localhost/myproject/subfolder
i will get a list of files in subfolder (b/c subfolder haven't index file).
Have anyway to block access that (not used index file? ). That should show any message instead of list files in the folder
thanks
You should configure your apache httpd.conf file, change something like:
Options FollowSymLinks Indexes
To:
Options FollowSymLinks
And restart your apach service.
You will have to create a specific file to show the message:
For instance
localhost/myproject/subfolder/message.html
This will then show the message and not all the files.
This is the Index feature of Apache and is designed to help with easy file navigation. Obviously this is undesirable on some servers. To turn it off you need to edit Apache's config file which is usually found in /etc/apache2/apache2.conf on Ubuntu or /etc/httpd/conf/httpd.conf on CentOS / RedHat but could be somewhere else, you did not specify operating system in question. Anyway, find it and edit it.
Search for Indexes in this file and change the value to -Indexes.
Then restart Apache with the following command:
sudo service apache2 restart
(on Ubuntu)
sudo service httpd restart
(on CentOS or RedHat)
Directory listing should now be switched off for all your folders.

How to activate mod_rewrite?

I know that this question have been asked several times. But I can't get it to work.
I installed Apache2 in my Ubuntu server I can also confirm that mod_rewrite is installed using phpinfo();. I have also put a file called .htaccess in my root folder(/var/www/.htaccess). In my .htaccess file I paste the following code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^.*$ test.php
So everything is redirected to test.php
But it still doesn't work. So I checked my httpd.conf file under /etc/apache2. It is completely empty, with no lines of code (This seems a little odd to me)?! However checking in Stackoverflow answers there should be at least the following code in httpd.conf:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Satisfy all
</Directory>
So I paste that code in httpd.conf. And restarted Apache with sudo /etc/init.d/apache restart. And it still does not work?
I have also tested to open the file /sites-enabled/000-default and /sites-available/default, where all virtual host settings lies and change under the directory /var/www and / to AllowOverride All. The mod_rewrite still doesn't work. Can anyone please help me. This problem has been baking my nuts for a while.
Also, my apache2.conf file doesn't work. I tried to write som nonsense. And it is still gives me the normal result instead of http 500 error
if you run this command,
sudo a2enmod rewrite
ubuntu will output whethere it is activated or already running.
All suggestions from Niels Bom are the smartest ones (I think). But I would add this as the first suggestion: try to launch and stop apache via the Ubuntu command: then when it's supposed to be stopped, make sure it's stopped ie verify your local page doesn't show anymore.
read what's in the folder /etc/apache2/. There should be apache2.conf conf.d envvars httpd.conf mods-available mods-enabled ports.conf sites-available sites-enabled
then if everything is ok, take a look at mods-enabled where you will find if the mods are enabled if so, then you can go on, otherwise take a look at the other answers about enabling modrewrite
take a look at sites-enabled: it's where you can find the sites that are... (guess what?) enabled. There should be the default website.
if so, open this file, and try to put apache nonsense in it, restart the server and see if it's happy or not. If it's not happy that's good. If it's happy then you're working on the wrong file
last: try to check what are the authorisations for htaccess files for this default vhost. Here's the way they work: if Apache doesn't find any directive in the vhost file, it will apply the global configuration. So I'd suggest to add the configuration in your vhost file, between the <virtualhost> - </virtualhost> tags (of course).
Please tell me what's going on and I'd be glad to update my question accordingly.
Because this thread ranks very high on google, here another solution:
WHAT'S CAUSING THE PROBLEM ?
It's caused because the standard definition in apache simply blocks all .htaccess stuff. Seriouslsy. This seems to be the initial state in Ubuntu 12.04 LTS.
SOLUTION
In /etc/apache2/sites-available/default (that's a file, not a folder) there's a code block like
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride XXXXXXXXXXXXXXXXXXX
Order allow,deny
allow from all
</Directory>
Here you should change
AllowOverride None
to
AllowOverride All
IMPORTANT
You have to do these changes with sudo rights, anotherwise Ubuntu will not save the file. After a RESTART your .htaccess stuff should work. To test .htaccess simply put some nonsense text into it and surf to localhost or 127.0.0.1 -> If you see "internal server error": voila! Remove the nonsense and you are ready to go.
Okay, let's check assumptions:
Put nonsense in your Apache config files (and restart Apache to let them take effect), does Apache "complain" on restart? Then it tries to load those files. Try this for every Apache config file you can find. You now have a complete list of Apache config files that are loaded.
put nonsense in your htaccess, reload the page, do you get a 500 error? If not, the htaccess is not getting loaded.
Put the most basic mod_rewrite statement in your htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^.*$ test.html
This should rewrite every request to test.html.
Try this and give us the results.
Please check /etc/apache2/apache2.conf
In your question, you have mentioned,
Also, my apache2.conf file doesn't work. I tried to write som nonsense. And it is still gives me the normal result instead of http 500 error
So, before posting more stuff to try-out with .conf files,
run strace -o somefilename.txt sudo /etc/init.d/apache restart
strace - trace system calls and signals : strace(1) - Linux man page.
The -o somefilename.txt part puts the output of strace into somefilename.txt. Open the text file and search for httpd.conf. You should be able to see code similar to:
stat("/etc/httpd/conf/httpd.conf", {st_mode=S_IFREG|0644, st_size=35894, ...})=0
open("/etc/httpd/conf/httpd.conf", O_RDONLY|O_CLOEXEC) = 3
The path to httpd.conf will be replaced by the path to your default httpd.conf
If you find one, then open that httpd.conf and make changes there. Else, a httpd.conf is not getting loaded.
If later is the case, try:
sudo /etc/init.d/apache -f /path/to/httpd.conf start
Also, check for NameVirtualHost *:80 and make sure it is not commented.

Categories