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)
Related
Have read previous answers and understand that I must have two versions installed, but cannot locate where the 5.6 could be. I changed /etc/bin/php to point to the version 7.3 I installed using brew. I updated the /etc/apache2/httpd.conf to use php#7.3. I restarted the server to be sure it would start apache reading from the httpd.conf. Yet, when I run phpinfo from the webpage, It starts with 5.6 and does not include the http.conf info about the server administrator, yet it says it's using http.conf. For some reason sudo apachectl restart will not work saying that the port is already in use. I removed the /usr/local/php5 link ( renamed it to php5.bak ), so that it would not be used.
What other things should I look at?
When you use php -v command you use php-cli which can be diffrent version.
Also if you have multiple versions installed you may want disable apache module for old one.
sudo a2dismod php5 // disable php5.6
sudo a2enmod php7.3 // enable php7.3
There can be many different things that are causing it but I'm betting on MacOS Apache that's installed with the system. Try killing it from the startup:
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
I have found a "partial" answer. I am running Mac OS X 10.12.6 on a mac-mini as a web server. The location of the configuration file for apache is:
/Library/Server/web/config/apache2/httpd_server_app.conf
Thus all of the /etc/apache2/httpd.conf and other suggestions, while they work fine on many unix and even OS X ( non-server ) where one has used brew to install, they don't work here. I made some changes in the above file and verified that AFTER going to the Server app, selecting WebSites in the services menu, and clicking toggling the ON/OFF button to off, then back to on, the server is restarted. All of the attempts using different apache2ctl restart, etc. do not work.
I am still somewhat puzzled that I don't see the server administrator that I enter showing up in the phpinfo.php display, but some other changes did.
My next quest, and suggestions are welcome, is how to change the http_server_app.conf file so that instead of php5, it will use my php7 that is available from the command line. The attempt to change:
LoadModule php5_module libexec/apache2/libphp5.so
#LoadModule php7_module libexec/apache2/libphp7.so
did not work as libphp7.so could not be located. I'm now looking for it. At one point in the conference file, I find:
<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>
Will I need to have one like this for php7_module, once I find it and use it above?
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.
I have a server running OS X 10.8.2. I wanted to install PhpMyAdmin, so I have installed MySQL and PHP (through MacPorts) too. Then I put the PhpMyAdmin folder in the root of my webserver, but when I surf to http://SERVERADDRESS/PhpMyAdmin on any web browser on any device I get the source code of the index.php file instead of the page loaded (see screenshot). Can you help me please?
First, open terminal. In it, write:
sudo nano /etc/apache2/httpd.conf
Find the row with
#LoadModule php5_module libexec/apache2/libphp5.so
and remove the comment from the beginning of the line (remove the #). Hit Ctrl+O and then Control+X to save and quit.
Then restart apache:
sudo apachectl restart
Then try and reload phpmyadmin.
I installed phpMyAdmin on my computer. I used Apache as my http server. However, every time I go to http://localhost/phpMyAdmin/, this screen appears:
How do I make it so that this login screen appears instead:
You may be better off to install an integrated suite, such as:
XAMPP - Linux/Windows/Apple
* store web pages in htdocs
WAMP - Windows
MAMP - Apple
Then, just going to the address localhost will give you a menu, with all components (apache, phpmyadmin, tomcat, etc etc)
They are all free, so why not?
Add this
DirectoryIndex index.php
to /etc/phpmyadmin/apache.conf (or wherever your apache.conf or httpd.conf or whatever is).
If you happen to be running on Windows, look for the Apache webserver directory.
XAMPP Users: If you have installed it as a service, changes to configuration files seem to take effect only when you restart the service through the Services panel and not via the XAMPP control panel.
Use http://localhost/phpMyAdmin/index.php
or
Check your host config, check the DirectoryIndex param.
I found that when I entered root in the username and left the password blank I got in
You need to edit your apache2 config file to include PHPmyadmin.
Do this:
gedit /etc/apache2/apache2.conf
OR nano /etc/apache2/apache2.conf
Add this to the end of your config file:
Include /etc/phpmyadmin/apache.conf
Save then restart Apache:
/etc/init.d/apache2 restart
i'm your average college student interested in using PHP. Could anyone give me a 101 on how to install/enable it on a mac version 10.7.2 using simple, plain language? I will appreciate any and all help!!
Cheers
No Need to Install PHP or Apache, They already ship with Mac 10.7
These are the basic steps you need to take for PHP and Apache to work together:
Enable PHP in you httpd.conf file located - /etc/apache2/httpd.conf
Setup your php.ini - sudo cp /etc/php.ini.default /etc/php.ini
Enable the Apache web server located in the Sharing > Web Sharing
Enable PHP in Apache
Find this setting in your httpd.conf file
#LoadModule php5_module libexec/apache2/libphp5.so
And, uncomment it like
LoadModule php5_module libexec/apache2/libphp5.so
This guide explains setting up MySQL and VirtualHost on Mac. I have been using this setup for over six months. Also, worked on the 10.7 early releases just fine.
http://superfancy.net/coding/php-mysql-apache-in-mac-osx-leopard/
Shell Commands to Start and Stop Apache on Mac
Start Apache
sudo apachectl start
Restart Apache
sudo apachectl restart
(edited to remove typo in restart command)
PHP5 should be already installed, it's just disabled. Open the Apache config file with a text editor it's at
/private/etc/apache2/httpd.conf
Now find the line which reads: "#LoadModule php5_module libexec/apache2/libphp5.so" and delete the comment (hash) from the beginning of the line and save the file (you'll need admin permissions to do this)
Now restart Apache - from the Terminal app type: sudo apachectl graceful
It will ask for your admin password
PHP should now be working..