I'm having issues related to loading php using Apache. I use a iMac running Sierra 10.12.6. Server version: Apache/2.4.25 (Unix). PHP 5.6.30 (cli) (built: Feb 7 2017 (16:18:37). Loaded module: php7_module (shared). I have been making all changes using Terminal. So far I can access my localhost, getting the "It Works!" page. I can access my user directory, for html documents only.
When I load the php5 module localhost will not connect at all. Server localhost not found. When I comment the php5 load module out again and restart apache I can gain access html documents in both localhost and localhost/~. When php5 is not loaded it downloads the document instead of opening it. It will go to the downloads folder or open in a text editor like Dreamweaver automatically. I downloaded MAMP and can access the phpinfo page and localhost on port 8888 so I think that is Ok, although I'm having issues connecting MySQL. That's a separate issue. Right now I just want to access php in my localhost/~.
My user directory info is (using actual username)
<Directory "Users/username/Sites/">
Options Indexes MultiViews
AllowOverride All
Require all granted
</Directory>
I followed tutorials making the recommended changes to the httpd.conf and other files and creating the index.html and php info documents in ~/Sites.
LoadModule userdir_mod
AddHandler php5-script php
display_errors = On
Include /private/etc/apache2/extra/httpd-userdir.conf
Include /private/etc/apache2/other/*.conf
I also changed the ServerName to localhost:80.
I also changed permissions on my WebServer/Documents folder to read & write for system, wheel and everyone.
I also made the following changes after reading through message boards on this site making changes to the Directory index.
I made other changes to the bash file (following the tutorial) and eventually reloaded the original httpd but I still can't access php. How do i access php5 in my user directory? Thanks.
Either some modules are missing, or a misconfiguration in your httpd.conf file. The correct AddType for php is:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
And make sure your module is loaded. Depending on the PHP version you are using, this is something like:
LoadModule php5_module modules/mod_php56.so
Restart your Apache and clear your browser cache before testing your php pages. Or try to upgrade to PHP 7. Unlink the old PHP and add the new:
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew unlink php56
brew install php71
I had the same issue and it turned out to be a permissions error. Try creating a new folder and copy across all the files.
Related
I had xampp and Atom running fine together on my old 2015 MacbookPro.
I installed both on my new 2021 M1 MAX Macbook Pro and then found that PHP is not pre installed in OS12.
Initially I was able view/run .php files from the Xampp http directory with localhost (Atom had no PHP), but I installed php 8.1 using Home Brew Atom is working but Xampp localhost is not running PHP.
I saw that there was a script from Homebrew in Terminal :
LoadModule php8_module /opt/homebrew/opt/php#8.1/lib/httpd/modules/libphp.so
<FilesMatch .php$>
SetHandler application/x-httpd-php
I have tried adding this to httpd.conf files in both the ....XAMPP/xamppfile/etc directory and
....XAMPP/xamppfiles/etc/original directory
there are also httpd.conf files in
....XAMPP/xamppfiles/apache2/conf directory
....acquia-drupal/apache/conf/original directory
....acquia-drupal/apache/conf/directory
Please let me know which of these that I should post the code from Home Brew into and if there is a correct place in the httpd.conf file to place it. Also if there are other issues to check.
Thanks
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?
I am setting up a test server before upgrading an elderly version of mediawiki on a production server. I am trying to duplicate what will be on the production server - apache2.4 and php5.3.
When I try to access any php file, the server displays it as text rather than running it.
This is all running on Ubuntu 12.04 LTS. The apache package available is version 2.2, so I can't simply apt-get.
I have built apache 2.4 from source, and it correctly serves an index.html from my designated DocumentRoot.
In httpd.conf, I have added:
DocumentRoot = /var/www
AddType application/x-httpd-php .php
<filesMatch>"\.php$:"
SetHandler application/x-httpd-php .php
</filesMatch>
I have installed php5.3, and it is working - I can run phpinfo.php from a command line.
In /etc/php5/apache2/php.ini I have (error displays are for testing only):
engine = On
display_errors = On
display_startup_errors = On
doc_root = /var/www
I am not able to find a reference to a mod_php of any sort either in the httpd.conf or in the directory in which httpd is installed (/usr/local/apache2).
Some of the references on the web mention "modules-available" and "modules-enabled" but these appear to be a convenience added by Debian, and are not part of the apache source build.
What am I missing? I'm sure it's something simple.
After searching and using packages from several repositories for both apache and php, and trying to build either or both from source, I determined that there did not seem to be a libphp5.so that was compatible with apache 2.4. In any case, I didn't find it.
I reconfigured everything to use php as cgi rather than as a module, and got things working that way, which was enough for my intended purpose.
You need to load php module in httpd.conf:
On my Linux Slackware I have this in /etc/httpd/mod_php.conf
LoadModule php5_module lib/httpd/modules/libphp5.so
# Tell Apache to feed all *.php files through PHP. If you'd like to
# parse PHP embedded in files with different extensions, comment out
# these lines and see the example below.
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
And in /etc/httpd/httpd.conf:
# php
Include /etc/httpd/mod_php.conf
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 just installed PHP on my computer (Ubuntu). If I create a test.php file with simple code and then run "php test.php", it works fine (I get what I expect).
However, when I open this file (test.php) with my browser (Mozilla) it asks me how to open this file. Not a problem. I click "open with" and then I select "/usr/bin/php" and... nothing happens. Browser does not display anything.
Can anybody help me with that? Why does my browser cannot display a local php-file using a local php server?
You need to install a web server (apache, lighttpd, ngnix etc.) on your machine, then make sure the server is setup to process php files through the php interpreter. After you have done all that, copy the php files to your server web root directory and access them through the browser.
XAMPP is probably the easiest way to get a development environment up and running.
Here is forum article on getting it running on Ubuntu.
Do you have a web server installed also?
This will install a full LAMP stack on Ubuntu.
sudo tasksel install lamp-server
But keep in mind this will launch Apache and MySQL daemons in the background.
To disable when you are not developing:
sudo /etc/init.d/apache stop; sudo /etc/init.d/mysql stop
When you are:
sudo /etc/init.d/apache start; sudo /etc/init.d/mysql start
You can make a macro in your favorite IDE to do this automatically.
Removing it is as easy as:
sudo tasksel remove lamp-server
Vertex
PHP through a browser will only work if you have php running as a webserver module (cgi, fcgi)
If you are on a regular linux distro you can probably apt-get emerge or zypper apache2 and the mod_php module from a repository. If you want to build from source, here is an small howto:
apache2php
If you're on *nix, try
locate httpd.conf
to find the apache configuration file. It should be somewhere like /etc/apache2/httpd.conf.
In the httpd.conf file, you need to do two things. First load the PHP module eg.
LoadModule php5_module libexec/apache2/libphp5.so
Then you also need a PHP file handler eg.
# PHP file handlers.
<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>
To test it's running OK, start apache with the .conf file as a parameter and load up a .php file that contains:
<?php
phpinfo();
?>
If PHP is running ok under apache, you should see a purple/white/black page listing all the settings currently in use.
See http://php.net/manual/en/configuration.changes.php for details of the myriad settings you can use.
Make sure you restart apache each and every time you change the .conf file!!!!