You are currently browsing comments. If you would like to return to the full story, you can read the full entry here: “Apache PHP and Mysql on Leopard”.
You are currently browsing comments. If you would like to return to the full story, you can read the full entry here: “Apache PHP and Mysql on Leopard”.
Hello,
I did upgrade to Leopard. I updated the httpd.conf and httpd-vhosts.conf files (in the apache2 directory). When I start the web server and try to access on eof the virtual host I get a message:Forbidden
You don’t have permission to access / on this server.
and int he console I can see the following message:(org.apache.htpd) Unknown key: SHAuthorizationRight
I didn’t find anything on the web this error.
The httpd.conf file has root for owner and wheel for group (sounds good).
Do you have any idea?
Thanks for your help
Regards
Herve
if the server is responding, then the problem is not with the configuration files. Are you accessing a specific file on one of the virtual hosts or accessing a directory (the URL ends with a /)?
If you can access a specific file, but can’t access a directory, then your default file name is not configured properly. It’s the index.html or index.php in apache .conf file.
If you can’t access any file on the server, it’s a simple matter of permissions on the folder containing the files for the site. Check the ownership and the permissions on the site’s folder.
Apache runs under user www and group www, so your site’s folder show be owned by user www and group www or the permission needs to be 0777.
Excellent writeup!
Super easy to upgrade but it would have been great if Leopard included Netinfo
The hosts file is just as easy tho.
Great post! I got apache + php running and working, but this is a new computer and I need to add mysql to the mix. How do I instal it and get it to play nice with PHP?
To install mysql, you need to download it from mysql’s site:
http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg
Select the version that suits your Mac, (powerPC or Intel). It says Mac OS X 10.4, but it will work on leopard.
The .dmg file will contain 2 .pkg files, install both of them and restart your mac.
After it restarts, open the terminal and type the following:
/usr/local/mysql/bin/mysqladmin -u root password ‘somepassword’
where ‘somepassword’ is the password you want for the root user of Mysql.
That’s all there is to it.
Thank you a lot, it has really helped. Now it all works perfectly.
If there is a good reason for your not to use the system provided apache, and you absolutely must use the previous installation you have, then you need to point the startup item for the system to your own installation.
You need to edit the file:
/System/Library/LaunchDaemons/org.apache.httpd.plist
and replace the string:
to point to your own installation of apache.
Be careful, any mistakes and you could render your apache installation and the system one unusable.
Migrating MySQL 5.0.45 to Mac OS X 10.5 Leopard
http://blog.tomatocheese.com/archives/2007/11/1/migrating_mysql_to_mac_os_x_leopard/
Could you explain this part of your write-up?
“For example, for each line that you set up in your hosts file like so: beta-site-1.com 127.0.0.1″ …
Which file is this? Is it the file that was modified using NetInfo Manager in Tiger? How do I find it now? I presume that if I want to add another virtual host, I have to get into this file.
And then should I remove the virtual hosts that I had set up in /private/etc/httpd/httpd.conf and replace them with virtual host definitions in /private/etc/apache2/extra/httpd-vhosts.conf?
I’ve tried following these directions but so far the server’s not being found, so clearly I am doing something wrong. Thanks in advance.
the hosts file is located at:
/etc/hosts
I don’t think it was managed by netinfo. NetInfo had its own thing for domains.
Usually, the default hosts file contains one entry:
127.0.0.1 localhost
For a development setup to work, each virtual host needs a pointer to tell your computer where to find the host.
example:
If you add to your ‘hosts’ file:
127.0.0.1 testdomain.com
and save the file.
Then if you type ‘http://testdomain.com/‘ in safari’s address field, then Safari will try to fetch the page from your own computer. So you configure the vhosts file for apache to respond to that request by doing the virtual host thing from the article.
So in summary, the hosts file tells your browser on which computer to find a domain name (127.0.0.1 is your computer) and the vhosts file tells apache which folder on your computer corresponds to that domain.
Thank you Lazeez. Those instructions are what I had to do before but have forgotten. You remind me though, that I can now use the built-in version. Previously I had my own Apache2 and used it instead of the then older version of Apache that came with Tiger. I assume all I’d need to do is move my pages along with the httpd.conf file, right? Thanks again.
You don’t need to move your pages, you just need to configure Apple’s apache2 to point to your folder properly.
Lazeez,
Thanks for the info, it helped get me back up and going quick.
Hi,
Thanks for the info… Right now apache2 and php5 is up and running… Was quite easy to read/follow…
I’ve got a small issue:
When I check the status using phpinfo()
I can see that mysql is supported, but nothing about PostgreSQL.
- I’ve got PostgreSQL-8.1 running on the same MacBook
- I’ve got uncommented the pgsql related lines in /private/etc/php.ini
- stop/ start apache
Still no good, no pgsql support…
I’ve never used PostgreSQL, and I don’t have it on my systems. So I can’t help with that. Sorry.
Thank you for a very helpful article. Concerning the hosts file, mine looks a bit different:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
I’m not exactly sure where or with what syntax to add my virtual hosts, because everything I’ve tried has resulted in either “Can’t find”– or “Can’t connect to server”. Any ideas? Thanks again.
after the line that starts with fe80 simply add whatever host you want, like so:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 hostnametoadd.com
of course, replace hostnametoadd.com with the host name you want.
I’m following the instruction, however, i am stuck at this step.
2 issues,
#1 – I couldn’t find this line in the httpd.conf
# LoadModule php5_module libexec/apache2/libphp5.so
#2 – i added it, and restart apache,
it give me an error “can’t establish a connection to the server at localhost.”
If you can’t find the line, that means you’re using a config file different from the one that ships with Leopard. Since you are, then I have no clue what that file looks like and options are set in it. The instructions above are for the default apache2 config file that ships in Leopard; not the one in the ‘original’ folder.
I have the same hosts file as BleKo (comment 22), and I understand what you’re saying I should do with that file to set up virtual hosts. But I’m not getting that far: after following the instructions in the article, I still can’t get Apache to work. It doesn’t recognize localhost or anything else. Web Sharing says that my computer’s website is http://new-host.home/ but that’s not accessible either. And where does that name come from? Can I change it to localhost or 127.0.0.1 somehow, and would that help?
What happens when you type http://localhost/ in your browser? If you can’t connect, that means one of two things 1) apache is not running or 2) your hosts file is not configured properly.
My hosts files doesn’t contain the stuff that you guys have. Mine has:
127.0.0.1 localhost
127.0.0.1 testdomain1.com
127.0.0.1 testdomain2.com
127.0.0.1 testdomain3.com
127.0.0.1 testdomain4.com
If apache is misconfigured, then I have no idea how to fix it without seeing the whole httpd.conf file.
I just upgraded to Leopard.
I have the PHP and MySQL activated, and I hope, doing OK. I still have more testing to go on the MySQL install…
However, I have the exact same problem mentioned above. The Apache server is running fine, but my user accounts (localhost/~user) are not resolving. I get “Forbidden” errors. This is despite the fact that they are set to chmod -R 0777, so it isn’t the file/directory permissions.
I have individual user .conf files, like so:
Options All
AllowOverride All
Order allow,deny
Allow from all
Options ExecCGI
SetHandler cgi-script
Any ideas?
On my system, leopard didn’t create user directory files properly.
Those should be located at:
/etc/apache2/users/
Mine had a Guest.conf file only.
If your setup has a .conf file in that folder with your home folder name in it, then I don’t know why it wouldn’t work for you. Mine didn’t work until I created the file.
For apache to serve your home site properly, you need to have a config file for it. The file should be:
/etc/apache2/users/username.conf
The file’s contents should be something like:
<Directory “/Users/username/Sites/”>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
of course, in both instances, the file name and the file contents, replace the ‘username’ bit with your own user name.
Everything works fine until I uncomment the virtual hosts line “#Include /private/etc/apache2/extra/httpd-vhosts.conf”
Once I relaunch web sharing with this uncommented I get a cannot connect to server error.
Also, I have a file “shortname”.conf in /etc/apache2/users/ as posted by Lazeez, but if I do a phpinfo() the document_root is still the default “/Library/WebServer/Documents”.
I’ve even added: Include /private/etc/apache2/users/mark.conf to httpd.conf to make sure it’s getting the file, but it’s still not changing the document root.
Thanks for any help, I’m new to using the built-in server and I’ve got a bunch of different sites so I really need virtual hosting.
As usual, found the solution moments after posting for help: http://alexking.org/blog/2007/11/01/apache-2-only-serves-first-virtual-host
For those people struggling with getting the second virtual host site to work, like I have been, make sure both site declarations are inside the VirtualHost tags:
ServerName beta-site-1.com
DocumentRoot “/Library/WebServer/beta-site-1″
ServerName beta-site-2.com
DocumentRoot “/Library/WebServer/beta-site-2″
I ended up having issues with the second site because I had two VirtualHost tag blocks.
>To install mysql, you need to download it from mysql’s site:
>http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg
>Select the version that suits your Mac, (powerPC or Intel). It says Mac OS X 10.4, but it will work on leopard.
OK, done.
>The .dmg file will contain 2 .pkg files, install both of them and restart your mac.
don’t need the startup item since I will use launchd. I have started mysql manually for now.
>After it restarts, open the terminal and type the following:
>/usr/local/mysql/bin/mysqladmin -u root password ’somepassword’
where ’somepassword’ is the password you want for the root user of Mysql.
Here’s where things fail. I have installed mysql many times in the past so assigning the root password is something I automatically, but on a clean install of Leopard, with the 4.1.22 mysql installer, the above appears to do nothing. when I attempt to log into mysql with (paths set):
mysql -u root -p
it tells me user root access id denied for ‘root’@'localhost’
I’m sitting at the console as well… Any ideas.
Restarting the Mac starts up mysqld with the proper parameters. Did you start it up with the same parameters as the startup item?
> Restarting the Mac starts up mysqld with the proper parameters. Did you start it up with the same parameters as the startup item?
Not sure if that question is to me, but…
Under Leopard the correct way to start any service is now to use launchd. I’ll be using this script:
KeepAlive
Label
com.mysql.mysqld
Program
/usr/local/mysql/bin/mysqld_safe
RunAtLoad
UserName
mysql
WorkingDirectory
/usr/local/mysql
Until I have the root user configured, I’m reluctant to have it autostart…
To start it manually, I just used:
sudo ./bin/mysqld_safe &
I just don’t get it. I can’t find the httpd.conf file in my Leopard anywhere.
> I just don’t get it. I can’t find the httpd.conf file in my Leopard anywhere.
/etc/apache2/httpd.conf
The script that the mysql startup script uses to start and stop the server is located at:
/usr/local/mysql/support-files/mysql.server
Try using that instead of mysqld_safe and see what happens.
> The script that the mysql startup script uses to start and stop the server is located at: /usr/local/mysql/support-files/mysql.server
> Try using that instead of mysqld_safe and see what happens.
I stopped mysql (remember that I’m using launchd to start it per the “norm” now under Leopard) and then started it using the script above. Still won’t let me access the database as root.
At this point I’m once again back to a virtually clean Leopard install and a clean mysql install. I figured totally burning it again couldn’t hurt. On a clean mysql install one should be able to:
mysql -u root
without a password since the root password hasn’t been set, but I still get:
www:support-files dherren$ mysql -u root
ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: NO)
(note that I’ve also set my path variable so I don’t have to include the full path in every command–just in case anyone wonders)
I’ve now got a call in to Apple support and I’m supposed to have a phone appointment with the server support group today at 11am EST to see if they can help me.
I love Leopard, but the growing pains I’m experiencing are more like bruises…
I was bashing my head against the desk wondering why my virtual sites were giving a ‘Forbidden – You don’t have permission to access / on this server’ message after upgrading to Leopard, despite the file/directory permissions on the web directories being unchanged.
This happens if your virtual sites aren’t under /Library/WebServer/Documents.
After actually realising Leopard had changed from using Apache1.3 to Apache2 I (eventually) looked at what differences there were in the httpd.conf files relating to directory access.
(In what follows I’ll use square brackets to delimit apache directives in case angle brackets aren’t escaped when displaying as HTML).
In Apache1.3 Apple’s httpd.conf has this:
[Directory /]
Options FollowSymLinks
AllowOverride None
[/Directory]
[Directory "/Library/WebServer/Documents"]
…
Order allow,deny
Allow from all
[/Directory]
The [Directory /] block has an implicit Order Deny, Allow directive (i.e. the default) so that anything below the root of any site is, by default, accessible. (The [Directory "/Library/WebServer/Documents"] block’s directives are explicitly saying that anything within /Library/WebServer/Documents is accessible. This doesn’t change what is already allowed).
However, in Apache2 Apple’s httpd.conf has this:
[Directory /]
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
[/Directory]
[Directory "/Library/WebServer/Documents"]
…
Order allow,deny
Allow from all
[/Directory]
The [Directory /] block now explicitly makes everything inaccessible below the root of any site by default. Now the [Directory "/Library/WebServer/Documents"] block’s directives are overriding this to grant access to everything under /Library/WebServer/Documents.
That’s fine if your virtual sites are under /Library/WebServer/Documents but if they’re not you get ‘Forbidden – You don’t have permission to access / on this server’.
The solution is simply to add an Allow from all directive for each virtual site’s DocumentRoot, e.g.
[VirtualHost *:80]
ServerName my.virtual.site
DocumentRoot /some/other/path
[/VirtualHost]
Becomes:
[VirtualHost *:80]
ServerName my.virtual.site
DocumentRoot /some/other/path
[/VirtualHost]
[Directory /some/other/path]
Allow from all
[/Directory]
The Allow from all directive overrides the [Directory /] block’s Deny from all directive because it is processed afterwards and the last one processed wins.
I’ve uncommented the php line as instructed above, but when i load a page that uses php syntaxt (e.g. ), it does not parse it, it simple displays the text. any ideas?
check to see if you have the php config file. In Leopard there should be a file:
/private/etc/apache2/other/php5.conf
its contents should be: (replace the square brackets with angled ones)
[IfModule php5_module]
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
[IfModule dir_module]
DirectoryIndex index.html index.php
[/IfModule]
[/IfModule]
if the file is not present, then you need to create it and then make sure that the last line in httpd.conf file is:
Include /private/etc/apache2/other/*.conf
And restart apache.
Hi,
With virtual hosts setup, how can I use the URLs in a MVC framework where the urls look like:
http://dev.local/module/controller/action/...
where i need to use:
http://dev.local/~user/module/controller/action/...
That would replace the module argument with ~user and move other arguments one position down
TIA
If you’re still having 403/forbidden errors, and are using FileVault, this might help:
http://ricardo.strangevistas.net/apache-unable-to-access-you-sites-on-os-x.html
thanx a lot …. i spent 2 hr figuring why my apache wasnt understand the php files until i found that leopard had changed the config files.
I upgraded to Leopard and have just recently needed to do some local testing with php. The server seems to be running fine except the fact that I can’t redirect my pages…
header(“Location: content.php”);
exit;
gives me an output error:
Warning: Cannot modify header information – headers already sent by (output started at /Users/devincolumbus/Sites/widget_corp/create_subject.php:4) in /Users/devincolumbus/Sites/widget_corp/create_subject.php on line 18
Do you know what might be causing this?
Check that location. It’s probably an extra character somewhere. If you have edited the php files mentioned and by any chance converted them to UTF8, make sure that there is no BOM.
What is on line 18 of ‘create_subject.php’?
Thank you for your help. The fact that you are still answering questions here is very, very appreciated.
I can access html files across my network. I can not access php files.
Tail of my error_log doesn’t show any error when this occurs.
http://10.0.1.123/~user/index.html works
http://10.0.1.123/~user/index.php does not
Cannot display the webpage error.
That’s an odd one.
Can you access the index.php file from the machine serving it?
If PHP wasn’t working, you would have received the source code for the ‘index.php’ file. Getting an error message means that there was an error while processing the page and PHP produced garbage.
try the following command in the Terminal (/Applications/Utilities/Terminal.app):
curl -I “http://10.0.1.123/~user/index.php”
and see what the output is.
You can also try:
curl -G “http://10.0.1.123/~user/index.php”
That bypasses any interference from the browser and shows you exactly what the server is producing.
Thanks.
Somehow in trying to hack my way through this my mysql installation degenerated into a steaming pile of worthlessness. I am cleaning up the mess and starting over.
My theory now is the mysql and php installation was working fine, and that the issue was the way wordpress was handling the php calls.
It blows me away that apple hasn’t got their stuff together. It’s all about Apache, mysql and this does not come working by default. Even installing mysql…there’s nothing about adding these two lines of code anywhere in the installs or on apple.com…ludicrous!
[...] na Leopard je skroz rasturio moj Apache + PHP + MySQL setup. U ovom tekstu imate sve korake kako da vratite stvari u normalu. Ja sam imao tu nesreću da sam taj tekst našao [...]
[...] Leopard from your Tiger installation you’ll perhaps have to do things differently. Here are some different instructions that might help [...]
[...] but it required doing some workaround to get it working properly. I found some good help at My Macinations and again at Professional PHP.To make a long story short, because this is mostly a reminder for [...]
[...] I came across a page that explains how to setup Apache, PHP and MySQL on Leopard and in the comments (#40), I found the answer to the [...]
[...] the files from the old install across to the new locations. Then I read another tutorial (this one: http://mymacinations.com/2007/10/28/…ql-on-leopard/) and it referred to lines in the httpd.conf file that needed uncommenting. Well, these lines were [...]