Installing PHP, MySql and Apache on windows - php

Its my first time working with Apache,PHP,MySql. I downloaded and installed the latest package of these 3. Now I checked with apache and the index.html works. Now I replaced the index.html with some php script to check if my php works or not. When opened the html page again I see the php code directly. It seems it does not work. following is how my php code looks like.
<html>
<body>
<?php
echo "Hello World";
?>
</body>
</html>
when I open my index.php , I see the above code itself. Can anybody let me know whats wrong and how can i fix it?

Check your apache httpd.conf file for some commented out code that looks like this
LoadModule php5_module libexec/apache2/libphp5.so
and further down the file, this...
<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>

it seems there is some problem in the installation. use WAMP as stefan and dessus or XAMPP. i recomand u to use XAMPP its bundled with APACHE, MYSQL, File Zilla Server, Mercury for mail. Easy to Install and Use . http://www.apachefriends.org/en/xampp.html

Another vote for WampServer. Once you have a working server, it's then easier to poke around with configurations files and then learn Apache/PHP configuration that way.

use wamp! it's easy and fast :)
http://www.wampserver.com/en/
personally, i use an old version from 2007, 1.7.4, it can be found here: http://sourceforge.net/projects/wampserver/files%2FWAMP5/
the good thing about using an old version is that your code will work on old machines, and many servers out there have old versions of php and mysql.
the bad thing about using an old version is that your code might not work on new machines, and some machines out there have new versions of php and mysql.

http://computing-know.blogspot.in/#!/2013/10/how-to-setup-apache-php-mysql.html
Step By Step Process to Setup Apaache,PHP,Mysql,phpMyAdmin and XDebug.
1)How to install Apache
2)Setup PHP for Apache
3)Install & Configure MySQL to use with PHP
4)Setup XDebug for Debugging
5)phpMyAdmin
Note:In this tutorial my Server Folder is located on F:\Server
How to install Apache
1)There are two ways to install apache either install the old version of apache httpd (Compatible with Windows XP) from httpd.apache.org/download.cgi or get the latest apache build zip from www.apachelounge.com/download/ .
2)I will show how to configure apache from the zip version downloaded from apachelounge.com/download/ .
3)Click on Additional + VC9 on the left of the page.
4)Download the 2.4.x zip build with OpenSSL 0.9.8.
5)Create a folder with a name Server on location where .
6)My Location is F:\Server
7)Extract the Apache24 from apache zip to the Server folder.
8)Now Goto config folder in Apache and open httpd.config in any text editor.
9)Find(Ctrl + F) and replace each and every instance of "c:/Apache24" and change it to your apache location in my case its f:/Server/Apaache24.
ServerRoot "c:/Apache24" with ServerRoot "f:/Server/Apache24"
DocumentRoot "c:/Apache24/htdocs" with DocumentRoot "f:/Server/Apache24/htdocs"
with
ScriptAlias /cgi-bin/ "c:/Apache24/cgi-bin/" with ScriptAlias /cgi-bin/ "f:/Server/Apache24/cgi-bin/"
with
8)Now run the Command Prompt (with Administrator Rights) .
9)On Command Prompt go to the location Server/Apache24/bin .
10)Inside the Bin folder type "httpd -k install" to install the Apache service and then press Enter.
11)To start the Apache Server simply type in "httpd -k start" and then press Enter.
12)Restart Your Computer
13)Now Open the Bin folder and double click on the ApacheMonitor.exe and Start Apache
14)Now Goto localhost if you see page "It Works" then Apache is sucessfully installed on you computer.
If you see a page that says "It works!" then the Apache server has been installed successfully.
Setup PHP for Apache
1)Goto windows.php.net/download/ download the php-5.4.x-Win32-VC9-x86.zip.
2)Create a folder named php inside Server folder.
3)Extract all files from php-5.4.x-Win32-VC9-x86.zip to php folder in the Server.
4)Now Goto config folder in Apache and open httpd.config in any text editor.
5)Find(Ctrl + F) the LoadModule scroll down until last LoadModule and Paste the following
LoadModule php5_module "f:/Server/php/php5apache2_4.dll".
6) Find(Ctrl + F) the AddType scroll down until last AddType and Paste the following
AddType application/x-httpd-php .php .
7)Add the PHP location to the end of the httpd.conf file. For example, at the end of the file, add the following: PHPIniDir "Your PHP Location".
localhost/info.php
8)In the php folder rename the php.ini-development to php.ini and open it in Text Editor.
9)Find(Ctrl + F) the display_errors, and make sure the value is set to On.
10) Find(Ctrl + F) the extension_dir = "./" and change it to extension_dir = "F:\Server\php\ext" .
11)Restart Apache Server.
12)Create a file "phpinfo.php" in htdocs folder in Apache with follwoing content:
13)Goto localhost/phpinfo.php
extension_dir = "./"
14)Right Click MyComputer Click Propertes
15)Click Environment Variables
16)Add Your php folder location at the end of the path
17)Restart Your Computer.
Install & Configure MySQL to use with PHP
1)Goto dev.mysql.com/downloads/mysql/ download the zip or installer version.
2)Install MySQL
3)Click Next
4)Select Complete & click Next
5)Click Finsh
6)Click Standard Configuration
7)Click Next
8)Enter the password for mySQL
9)Goto MySQL Command Line and enter the password.
12)Open the php.ini file and find the line: ;extension=php_mysql.dll remove the semi-colon.
and find the line: ;extension=php_mysql.dll
phpMyAdmin
1)Goto config folder in Apache and open httpd.config in any text editor.
2) Find(Ctrl + F) the line DirectoryIndex index.html add index.php.
3)Open php.ini file in the Server Folder and Uncomment the mbstring and mysqli extension.
3)Goto phpmyadmin.net/ Download the latest phpMyAdmin-4.0.8-english.zip.
4)Extract it to phpMyAdmin folder in htdocs.
5)Restart the Apache Server.
6)Goto localhost/phpMyAdmin/
Setup XDebug for Debugging
1)Goto http://xdebug.org/download.php from your browser and download the
php_xdebug-2.x.x-5.4-vc9 Thread Safe 32 bit version.
2)Copy and Paste it to the extension folder in the php.
3)Copy & Paste the following line of code at the end of php.ini file .
[XDebug]
;; Only Zend OR (!) XDebug
zend_extension="Your Location of Xdebug"
xdebug.remote_enable=true
xdebug.remote_host=localhost
xdebug.remote_port=10000
xdebug.remote_handler=dbgp
4)Restart Apache Server.
5)Goto to localhost/phpinfo.php scroll down to see if xDebug is installed

Related

PHP install fails on file does not exist

on cmd: C:\Apache24\bin>httpd -t
Received message:
httpd: Syntax error on line 540 of C:/Apache24/conf/httpd.conf: Cannot load C:/php/php8apache2_4.dll into server: The specified module could not be found.>
And, in fact, C:\php\php8apache2_4.dll does not exist in my C:\php folder.
Do I specify a different php8 ... .dll or must I find and install the php8apache2_4.dll? And if the latter, where do I look?
Background:
Based on https://www.youtube.com/watch?v=oJnCEqeAsUk&t=4s entitled "Install & Set Up Apache Web Server on Windows 10", I installed Apache/2.4.55(Win64) server after download and extract from Apache Lounge into the C:\Apache folder I created.
Based on https://www.sitepoint.com/how-to-install-php-on-windows/#installingphp I created a C:\php folder into which I extracted a downloaded PHP from the x64 Thread Safe ZIP package from https://windows.php.net/download/ . I renamed a copy of C:\php\php.ini-development to C:\php\php.ini. Then enabled extension=curl, extension=gd, extension=mbstring and extension=pdo_mysql. I then added C:\php to the PATH system environment variables.
I then opened C:\Apache24\conf\httpd.conf and added
# PHP8 module
PHPIniDir "C:/php"
LoadModule php_module "C:/php/php8apache2_4.dll"
AddType application/x-httpd-php .php
and changed dir_module to read:
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
Then, from the command line I attempted
cd C:\Apache24\bin
httpd -t
Upon which I received the "could not be found module" message.
I am running MS Windows 10 Home Version 19044 on a Dell Inspiron 15-3567 Dell laptop x-64 based PC

how to configure server to look in to .xphp extention files for php code

In my project I want to store all new/specific code into files with xphp extension but I want server to parse those file as .php.
Can we configure this. If yes how?
I am using Apache server with php 5.6.3, with access to server configurations.
Thanks in Advance.
in apache2 you can add multiple handlers as follows:
within your .conf file which is often located in /etc/apache/sites-available/ in linux/ubuntu , add this line
AddType: application/xhttpd-php .xphp
this will only take effect on the virtual host which you are adding this line to,
if you want your changes take effect on all your hosts, add this line to your /etc/apache2/apache2.conf
if you don't have an access to you server configurations files :
you can add this line to your .htaccess file :
Addhandler application/x-httpd-php .html .php .xphp
don't forget to restart your apache2 after changing the conf files
sudo service apache2 restart

PHP test page is showing blank

I am trying to set up PHP to work with Apache using Apache Module DLL. The following code is added to c:\Apache24\conf\httpd.conf file:
LoadModule php5_module C:/PHP/php5apache2_4.dll
<IfModule php5_module>
DirectoryIndex index.html index.php
AddHandler application/x-httpd-php .php
PHPIniDir "C:/PHP"
</IfModule>
Then I browse http://localhost in a browser and it shows a page saying "It Works!"
Then again I test browse a PHP page info.php which just calls phpinfo() and it shows quite a bit of info about PHP installation.
Now, the case is that I found two default files such as php.ini-production and php.ini-development and I copy any one of them and save it as php.ini in
"C:/PHP",restarts the Apache server and again test browse info.php,then this time the page is blank even without any error message.
What might be the issue and how should I try to solve it?
My software specification is outlined below:
OS: Windows 7
PHP: 5.6.29
Apache: 2.4.23-win32-VC14
Thanks in advance!

create a php file in vagrant and have the host OS browser display the result

In my mac terminal I typed:
vagrant up
vagrant ssh
after which my command prompt is inside vagrant and displays:
vagrant#zero-to-slim:~$
after which I type:
vagrant#zero-to-slim:~$ cd /vagrant
where I have created a php file (called hello.php)
<?php
echo "Hello World from inside vagrant!!";
?>
When I go to firefox and type /var/www I can see the contents of the directory:
(i) a folder named zero-to-slim.dev
(ii) index.html
(iii) hello.php
I want to enter (in my browser) localhost/hello.php and be able to see "Hello World from inside vagrant!!", which is clearly not happening. How do I make that happen? FYI, just typing localhost in firefox displays: "It Works!" I'm not using PuPHET or anything, just LAMP.
Also I think the problem is I have to direct my host OS Apache to look at some shared folder to render .php files. No idea how to do that either (new to LAMP dev)
OSX comes with PHP pre-installed but not configured. You have to do that yourself.
According to Using the bundled PHP on PHP.net:
PHP has come standard with Macs since OS X version 10.0.0. Enabling PHP with the default web server requires uncommenting a few lines in the Apache configuration file httpd.conf whereas the CGI and/or CLI are enabled by default (easily accessible via the Terminal program).
and it goes on to say that you start by uncommenting the lines mentioning php in /private/etc/apache2/httpd.conf, e.g.,
# LoadModule php5_module libexec/httpd/libphp5.so
# AddModule mod_php5.c
and restart Apache.

Getting blank PHP page over Apache

In a newly setup digitalOcean cloud server (CentOS), I have installed php and Apache. The webserver is running fine:
[root#a2m5cent01 httpd]# service httpd status
httpd (pid 11232) is running...
[root#a2m5cent01 httpd]# php --version | head -1
PHP 5.3.3 (cli) (built: Dec 11 2013 03:29:57)
But browser is showing blank pages (white page) if I try to visit any php page.
Here is what I have done so far to troubleshoot:
Created a page with following content: <?php phpinfo(); ?>. It displays a blank page when viewed from browser.
Just to ensure, apache is pointing to the correct directory, placed a static .html page there, and saw it comes out fine in browser, so apache is working and directory is correct.
In /etc/php.ini, changed display_errors directive to On. Still blank page
In Apache config file (/etc/httpd/conf/httpd.conf) found this line Include conf.d/*.conf. Inside conf.d directory, there is a php.conf file containing the line:
LoadModule php5_module modules/libphp5.so. Ensured that this .so file actually exists in this place.
In the same file I have these two lines as well: AddHandler php5-script .php and AddType text/html .php
Executed the php page from CLI, it works fine - so php is working locally.
Then why is it always shows a blank/white page over the browser? What else am I missing?
EDIT
Based on suggestions from #Nathan,
I checked Apache error log file, could not see any error being
reported there.
My /etc/php.ini says, php error_log is located as syslog. So I checked /var/log/messages but could not find any PHP error message
Next I put some normal HTML in the php file containing phpinfo() call. Interestingly I found that even the normal HTML texts are also not coming. It still produces blank page.
Then I checked Apache access log. Surprise! There is no GET request for any of the PHP files I tried to load in the browser. But GET request for all the non-php files are there with 200 return code.
Apache is not even logging any access request for PHP files. Any idea why would that happen?
check out your phpinfo() script.
<?php
phpinfo();
?>
missing the "php" behind the first "?" will give a blank page
I think your php installation with apache is faulty. Thats why you can not see any php page in your webserver. Clean remove all the existing apps, like httpd,php,php-fpm,php-cli etc. and try to clean isntall in this order
yum install httpd -y
yum install php php-common php-cli php-gd php-curl php-fpm -y
then make sure you restart yout httpd server.
service httpd restart
Install mod_fastcgi:
yum install mod_fastcgi
Start the service:
service php-fpm start
Restart Apache:
service httpd restart
5. Configuration of Apache with PHP-FPM
Open the fastcgi.conf file:
nano /etc/httpd/conf.d/fastcgi.conf
Add this to the end of the file:
<IfModule mod_fastcgi.c>
DirectoryIndex index.html index.shtml index.cgi index.php
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
</IfModule>
After that search after "FastCgiWrapper" and make sure it's set to "off" then save the file.
The /usr/lib/cgi-bin/ directory must exist, so we create it:
mkdir /usr/lib/cgi-bin/
If mod_php is installed and enabled, we need to disable it so open the configuration at /etc/httpd/conf.d/php.conf:
nano /etc/httpd/conf.d/php.conf
Comment out the AddHandler and AddType lines so it looks like here:
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
#
# Cause the PHP interpreter to handle files with a .php extension.
#
#AddHandler php5-script .php
#AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps
Save the file and restart Apache:
service httpd restart
Are you navigating to the php file directly? Or are you just going to the directory root?
If the later, Apache might not be recognizing .php as the directory index.
To test, try create a .htaccess file in your web root containing the following line:
DirectoryIndex index.php
I have the same issue...
The problem is in the iptables. (It seems like it)
Try with:
service iptables stop
## check if it stop...
service iptables status
Then try to reload the page again.
If you had other solution please share.
[edit]
Restarting the iptables service is working for me.
Try:
service iptables restart
First of all you should check the permissions of your file.
If you don't grant read-permission to public, Apache produces a blank page without showing any errors.
It's been sometime, but I wanted to come back to this question to update that the issue was with the directory permission setup.
The FPM user I was using didn't have necessary permission to execute the index.php file in the web root.
To avoid these issues in the future, I have created an automated bash script that will automatically create and configure webservers in DigitalOcean boxes. Please take a look here https://github.com/akash-mitra/fairy
This script will automatically,
Installs Nginx
Create virtual server block for nginx
Installs PHP, PHP APC, PHP Curl etc.
Supports PHP Fast Process Manager (php-fpm)
Installs Memcached
Installs Database (MariaDB / MySQL)
Optionally Installs PHP Composer and Laravel
Configures and Strengthens SSH
Activates Firewall
Optionally enables SWAP space in DO server and fixes a locale issue
Since everything looks at its default state, have you checked this part just for confirmation
cat /etc/php.ini | grep log_errors
If log_errors is disabled then enable it and check this below log after restarting httpd.
/var/log/httpd/error_log
--
Also check this part from php configuration.
cat /etc/php.ini | grep error_reporting
This value should be enabled by default so that display_errors will work.
error_reporting = E_ALL
Sorry to repost an old thread...this is important.
I also was having these problems where no html response was outputting
After double-checking php.ini or my apache conf files and was still receiving no output, I later found out that I was suppressing the error of an include / require of a class, with #, which was nested within a constructor function. There was a syntax error in the included file, which stopped all output altogether when errors were thrown.
So, check your handlers first.
If you are storing all your output into vars first and you are including various scripts first that fail you'll have to see those errors. If you suppress file handler errors, you'll get a blank screen if you have a syntax error in the file.
Search your files for all instances of # in your php code. Then turn #include "/path_to/script.php"; to include "/path_to/script.php"; or anything #$foo into $foo as such var might reference a dependency that is causing your script to end with nothing showing in the httpd error log or in the http response.

Categories