How to install/use php on mac v 10.7.2 - php

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..

Related

Why does phpinfo() in webpage show version 5.6, but php -v from command line shows 7.3?

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?

Change apache2 php path

I am using https://github.com/wilmoore/php-version to switch between php versions on my local machine, installed within ~/php/versions. Currently setting up separate VMs with different versions of php installed is not an option.
When I switch php version through the command line using the linked tool, I see it listed as php 7. This also works when using php -v. I have restarted terminal and the machine and it still says php 7.
I have updated composer.json to require php 7.0.2 and greater. Yet when I use phpinfo() in my laravel application, it always states the default PHP Version 5.5.9-1ubuntu4.14.
Where is laravel pointing to the php distribution in my Ubuntu 14.04.3 machine and where can I change this path?
EDIT: I am using Apache. I can see in the phpinfo() output that it is reading the ini file from /etc/php5/apache2/php.ini. I have looked in this file but cannot see where to point to the php distribution.
first make sure that php7.*.conf and php7.*.load files are exist in /etc/apache2/mods-available directory.
then use sudo a2enmod php7.* to enable the mod
use sudo a2dismod php5.* to disable the mod
after running the two commands restart your apache2 server
using sudo systemctl restart apache2
The Apache loads the php5_module library in /etc/apache2/mods-available/php5.load.
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
If you know the loactions of your alternative libraries you can change them in this file.
After editing you need to restart your apache. sudo service apache2 restart or sudo systemctl restart apache2.service
Had the same issue on ubuntu16.
ls -l /etc/apache2/mods-available/php7* ,
showed 2 versions -
/etc/apache2/mods-available/php7.0.conf
/etc/apache2/mods-available/php7.2.conf
Deleted the /etc/apache2/mods-available/php7.0.conf, restarted apache2, and phpinfo() via apache2 showed php7.2

Two versions of php in El Capitan. How do I get rid of one or upgrade the other?

In terminal,
php -v
gives
PHP 5.3.29 (cli) (built: Sep 28 2015 06:33:13)
(with imagick installed) but, in the browser (using apache)
phpinfo();
gives
PHP Version 5.5.27
(with no imagick installed) How do I resolve this?
I don't want to mess about with php.ini and httpd.conf when I'm not entirely sure what I'm doing!
Solved it. I entered
locate libphp5.so
into terminal to find paths to the php installations. This outputted
/usr/libexec/apache2/libphp5.so
/usr/local/Cellar/php53/5.3.29_4/libexec/apache2/libphp5.so
I then edited the apache configuration file
sudo nano /private/etc/apache2/httpd.conf
and changed
LoadModule php5_module libexec/apache2/libphp5.so
to
LoadModule php5_module /usr/local/Cellar/php53/5.3.29_4/libexec/apache2/libphp5.so
NOTE : This line will be different for your local installation, copy the value outputted from the locate command above
I then restarted apache with:
sudo apachectl graceful
Credit to this solution for the command to find the php installations
This may be a help to you : Upgrade to PHP 5.4 on MAC and remove version 5.3.10
I would suggest that you work in a virtual setup instead.
like Vagrant: https://www.vagrantup.com/
Also take a look at Homestead: http://laravel.com/docs/4.2/homestead
"Laravel Homestead is an official, pre-packaged Vagrant "box" that provides you a wonderful development environment without requiring you to install PHP, HHVM, a web server, and any other server software on your local machine.
"
It will also allow you to keep your configuration if you change machine and/or operating system.

PHP not working in OS X Server

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.

How do you get php working on Mac OS X?

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)

Categories