When I updated to my OS 10.9, my apache virtual host setup broke. I first discovered that the include line for the extra/httpd-vhost.conf file had been commented out, like so:
# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf
So I uncommented. Now, the virutal hosts seemed to be operating, but the php code is just being pulled up as a text file. It's not running the code. Seems as though, perhaps, the php link is no longer working? Does that make sense? Any ideas?
Have a look in the /private/etc/apache2/extra directory. Mac OS X renames your old config files and adds fresh vanilla ones. I had the same problem when I upgraded to Mavericks.
Turns out the problem was simply that the LoadModule line for php5 in httpd.conf had also been commented out:
LoadModule php5_module libexec/apache2/libphp5.so
I uncommented and everything seems to be working now.
Related
I want to install dompdf, and so I need PHP, and consequently Apache (for instance) installed. I've managed to install Apache 2.0.64 on my Windows 7 64 bit. It was apparently working fine, until I've installed PHP 5.4.9 and configured httpd.conf, so Apache could "see" the PHP installation. I've been using this link for guidance on that -> http://www.webdevelopersnotes.com/how-do-i/install-PHP-windows-7.php After that, when I try to start Apache2 the "The requested operation has failed!" error pop-up appears. If I comment the lines that I've inserted into httpd.conf, Apache works again. The lines are:
AddType application/x-httpd-php .php
(...)
LoadModule php5_module "c:/Program Files (x86)/php_5.4.9/php5.dll"
(...)
PHPIniDir "C:/Program Files (x86)/php_5.4.9"
I've spent a lot of hours and searched but couldn't find a similar problem to mine nor a solution of my own. Does anybody has a hint on this?
Thank you very much,
João
I'm having trouble with Apache/PHP on Windows 8. I have previously been using them on XP (along with MySQL) with no problems. I never used Windows 7.
Apache installs without issues. Everything works OK, including all my virtual servers.
PHP installs OK, the installation puts entries into httpd.conf without giving errors.
However, when I try to load Apache after installing PHP, Apache won't load.
I'm confused by the error that Apache returns when the PHP entries are included in httpd.conf:
Syntax error on line 1029 of C:/Program Files/Apache Group/Apache2/conf/httpd.conf:
Cannot load C:/Program Files/PHP/php5apache2_2.dll into server: The specified module could not be found.
The lines are:
#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
PHPIniDir "C:\Program Files\PHP\"
LoadModule php5_module "C:\Program Files\PHP\php5apache2_2.dll"
#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
(line 1029 is the LoadModule line).
That location for the dll is definitely correct. The syntax of the line is as inserted by PHP. I have compared the syntax to previous versions of httpd.conf that I have and it appears correct. I think the syntax error is a red herring.
I have tried:
Switching backslashes to slashes in the dll location.
Adding PHP to the path.
Installing Apache and PHP in both sequences.
Checking the permissions to the PHP folder and the individual files
to ensure that SYSTEM has read/execute.
Comment out the PHP lines and Apache loads fine. If I comment out the LoadModule line and and just leave the PHPIniDir line, it still fails. Apache seems to be behaving as though it can't see the PHP directory, but I can't work out why.
There is nothing on the Windows event log. Latest versions of PHP and Apache. I'm at a bit of a loss what to try next. Any suggestions please?
Download and follow instructions from this link:
http://www.apachelounge.com/download/
The latest download (2.4) works on Windows 8 and Server 2012.
I downloaded and tested with the following on Windows 8:
Each zip has a readme.txt or install.txt with instructions.
Apache 2.4
http://www.apachelounge.com/download/win32/binaries/httpd-2.4.3-win32.zip
PHP 5.4.8
http://windows.php.net/downloads/releases/php-5.4.8-Win32-VC9-x86.zip
PHP 5.4.8 handler for Apache
http://www.apachelounge.com/download/win32/modules-2.4/php5apache2_4.dll-php-5.4-win32.zip
My httpd.conf lines that were added/modified were:
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module "C:/Apache24/php-5.4.8/php5apache2_4.dll"
LoadFile "C:/Apache24/php-5.4.8/php5ts.dll"
PHPIniDir "C:/Apache24/php-5.4.8"
<IfModule php5_module>
<Location />
AddType text/html .php
AddHandler application/x-httpd-php .php
#AddHandler application/x-httpd-php-source .phps
</Location>
</IfModule>
Its mentioned in the Readme.txt file packed with the dll's at ApacheLounge, but not anywhere else on the download page or in the filename (as all other versions):
"Runs with PHP 5.4 Thread Safe (TS), and only with Apache 2.4 Win32 VC9 or VC10"
The dlls are only for the TS version, so if you've downloaded the other one, you are basically screwed. TS php binaries fixed it for me.
GL.
Presuming this is your development, not deployment environment, why don't you just download xampp from apache friends? It should come preconfigured, and you will deploy in other setup anyway.
I ran into the similar issue when reinstalling Apache and PHP on Win 8 (I am more Linux user though). And similar to the original post, no matter what I tried to do in httpd.conf and php.ini Apache simply either did not start or did not see the PHP. After spending unreasonable amount of time, I decided to download the PHP 5.3 (5.3.27)-VC9 x86 Thread Safe (2013-Jul-10 21:56:58) Installer [45.86MB] instead of the non-tread safe version which I have been using before. There is a difference in the .msi installers. The one for the thread-safe version actually contains the required files and if you follow the installer prompts it will actually asks you if the php installation should be "linked" to Apache server. Then you just provide the hhtpd.conf directory and all works fine. Thats my 2c on this :)
I think the problem is in the blank "Program Files".
I'm trying to configure apache 2.2 for php 5.2 (or preferably 5.3, but php.net seems to say not to) on Windows Server 2008.
C:\Apache2.2\
C:\php\v5.2\
Apache is running fine before I add this to httpd.conf
LoadModule php5_module "C:/php/v5.2/php5apache2_2.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php/v5.2/"
Then apache spits out this error when I try to restart it from cmd:
httpd.exe: Syntax error on line 129 of httpd.conf: Cannot load C:/php/v5.2/php5apache2_2.dll into server: The specified module could not be found.
It's definitely there!
I googled the error and found a lot of people complaining of it, but they're all for mistakes like referencing php5apache2.dll instead of php5apache2_2.dll.
EDIT: btw, when I use the installer, and it modifies httpd.conf for me, I still get the cannot find error during start up. wtf…
turns out the LoadModule […] has to go at the very end of httpd.conf. dunno why, but i moved it, and apache stopped complaining.
I have recently updated to Lion and enabled Web Sharing in the System Preferences but I am unable to get php working.
I added an info file to the web root directory and it outputs the file as text.
info.php
with the content
<?php phpinfo(); ?>
(Edit: This method appears to work fine for 10.9 (Mavericks), 10.10 (Yosemite) and 10.11 (El Capitan), so I figured I'd mention that for any new influx of slightly frustrated OS X updaters :D )
Edit your /etc/apache2/httpd.conf and make sure the line:
LoadModule php5_module libexec/apache2/libphp5.so
...exists. I think it's commented out by default in the standard OS X config, but from what I remember, you just need to uncomment it, then re-start Apache:
sudo apachectl restart
And you should be good to go.
UPDATE: Please note that this was written for OS X pre-(High) Sierra. If you run OSX 10.12 or newer, please follow this more than excellent guide by Andy Miller: macOS 10.15 Catalina Apache Setup: Multiple PHP Versions
I too like to use things that are basically already there. I don't see why anyone would use MAMP or AMPPS (or any other packed 3rd party out-of-box webserver app) when Mac OS X comes with apache and PHP by default.
Took me a couple of tries to get it working, so here is basically what did it for me and hopefully it'll help you guys save a little time.
Like Matt Gibson said, start terminal and type: (sudo requires your root password)
sudo nano /etc/apache2/httpd.conf
Then uncomment this line by removing the '#' in front of it (ctrl+v can be used as page-down)
LoadModule php5_module libexec/apache2/libphp5.so
To make sure you can include files etc in PHP, scroll to "User _www" (in my case) and change that to: (where "yourusername" is the user you login with)
User yourusername
You can leave the group as-is, "Group _www" by default on a fresh OS X Mountain Lion install.
On default apache only looks for index.html, so search for "DirectoryIndex index.html" and change that to: (adding index.html at the end is optional of course)
DirectoryIndex index.php index.html index.htm
Exit and save by pressing ctrl+x (and confirm with "y")
Then restart apache:
sudo apachectl restart
My phpinfo(); returned with a PHP Version 5.3.15
==================
Since I find it useful to have my local sites in my user dir, I created a directory /Users/yourusername/Sites (which isn't there on default anymore in Mountain Lion).
Again, edit httpd.conf via "sudo nano /etc/apache2/httpd.conf" and ...
Scroll down to "DocumentRoot" and change it to: (where "yourusername" is the username you login with)
DocumentRoot "/Users/yourusername/Sites/"
Scroll to where it says "# This should be changed to whatever you set DocumentRoot to." and change the next line to: (where "yourusername" is the username you login with)
<Directory "/Users/yourusername/Sites/">
Then exit and save by pressing ctrl+x (and confirm with "y")
Restart apache.
I have one word for you. MAMP.
Try it phpbrew
It's ease build, install tool for PHP, any version.
For the latest version of mac os i.e Mojave 10.14, follow the steps below to activate PHP server:
Open terminal. Press command+spacebar, type terminal and press enter.
Enter command $ sudo nano /etc/apache2/httpd.conf to edit httpd.conf file in nano, which is an inbuilt file editor in macOS.
Enter the password.
Now search loadmodule by pressing control+w.
Find file named #LoadModule php7_module libexec/apache2/libphp7.so
Uncomment the file by removing the # symbol present at the very beginning of the module.
Now exit the editor by pressing control+x, press y to save the changes and press enter to confirm changes to the httpd.conf file.
Now restart the apache server by entering the command
$ sudo apachectl restart
PHP server should be running now running.
Now you can check the working of your server by opening the PHP file from your default server directory or you can also change the directory as well.
After upgrading the MAC OSX to 10.14.5 My Apache config file was new and all my previous settings were replaced with default settings.
I was not able to open any PHP files in my browser. I followed the above steps and it resolved the issue.
Note - In OSX 10.14.5 there is Php7.1.23
Steps I followed -
Edit the httpd.conf file located under /etc/apache2/httpd.conf
This below given live was commented. I uncommented it by removing the # sign and saved
the httpd.conf file and restarted the apache service.
LoadModule php7_module libexec/apache2/libphp7.so
sudo apachectl restart
Thank you for the solution, appreciated your help friends.
Regards,
Vicky Jadhav (India - pune)
This is the guide I followed to make PHP work on Snow Leopard:
http://maestric.com/doc/mac/apache_php_mysql_snow_leopard
Apache2 is working.
http://localhost.lan works just fine. Virtualhost works too.
Mysql is working.
PHP5 is not even with
LoadModule php5_module libexec/apache2/libphp5.so
I think your apache2 install has a problem.
You need to re-install apache2 then try
LoadModule php5_module libexec/apache2/libphp5.so
again.
To clarify Neoryder's post, edit /etc/apache2/httpd.conf, find the line:
#LoadModule php5_module libexec/apache2/libphp5.so
and remove the hash sign from the beginning to enable PHP in your web server. You have to go to your Sharing preference pane and uncheck and recheck Web sharing for the change to take effect.
I'll mention one more thing that caught me out moving from Linux to OS X...
Most people want to serve PHP files from their own Sites folders. There's lots of advice out there about configuring Apache using .htaccess files, and some of it won't work under OS X because Apache is locked down a bit by default.
For example, if you want to have PHP files ending with .html or .htm, most people will tell you to create an .htaccess file and put in it the line:
AddType application/x-httpd-php .html .htm
If you're a developer and this is annoying you, you may want to edit the file /etc/apache2/users/<myusername>.conf and change the line:
AllowOverride None
to:
AllowOverride All
This will allow your local .htaccess files to override various global defaults that they couldn't before.
This is obviously a late answer...but I had the exact same problem and I used Homebrew to install a later version of php:
http://notfornoone.com/2010/07/install-php53-homebrew-snow-leopard/
brew install php --with-apache --with-mysql
I then went into my httpd.conf file:
cd /etc/apache2
sudo nano httpd.conf
And changed the line:
#LoadModule php5_module libexec/apache2/libphp5.so --> the old version
# Below is the link to the new homebrew version
LoadModule php5_module /usr/local/Cellar/php/5.3.7/libexec/apache2/libphp5.so
(It depends where you install Homebrew, but the default is /usr/local)