I am following this netbean guide https://netbeans.org/kb/docs/php/configure-php-environment-ubuntu.html#createDocumentRootLocation
But I am stuck at creating the virtual host. I try to do as in the tutorial but there is no <Directory> tags in the "000-default.conf" file. I kept going and ignored that.
I did as in the tutorial and put it in my /home/user/public_html. but now when I run it the php code is not interpreted
If I a2ensite the default I can access virtual host set at /var/www/html and that php is interpreted
There are no errors the php is just not being interpreted, what am I doing wrong here.
Im using:
Ubuntu 18.10 LTS
PHP 7.2.10-0ubuntu1 (cli)
Apache/2.4.34
Edit:
My "TestPhp.conf" file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/jelly/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Edit 2 and answer:
Turned out to be some lines in my "php7.2.conf" file that had to be commented out as the out-commented lines in that file explains. as running PHP scripts in user directories is disabled by default.
what is your test script like? if you start with <? try <?php instead.
Also check php.ini for expose_php = false (may hide php form the headers)
If the error persists, include your config and test script, along with any errors in http.log
You need to find a config file which enables php
I only have a Ubuntu, and the files in my installation may vary compared to yours:
Enable PHP engine [php.load]
This is the part that loads the PHP interpreter, and allows you to use php scripts
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
Enable .php file directed to php [php5.conf]
This is the part tells apache to send *.php (and in this case some other extensions like *.phtml) to the php interpreter
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
SetHandler application/x-httpd-php-source
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in specific virtual host or directory
Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
Require all denied
</FilesMatch>
EDIT I noticed that you were on UBUNTU as well
use sudo a2enmod and select php in the list
EDIT 2
Note that if you are following a general Guide and not a UBUNTU specific one, you may encounter several issues since the UBUNTU apache config is spread out in several files, as opposed to one big file, which is what you may encounter in other distros
Related
I'm setting up a windows server 2019 with apache 2.4 and PHP 5.6.
I was able to load the phpinfo in the browser with localhost.
I am trying to get the sites to open up in an htdocs folder on another drive (D:) using an alias that, according to our networking team is quoting, "DNS is set up correctly pointing to newprod.company.name.com", with "newprod" being the acutal alias.
In my httpd.conf file, I have the following settings:
Define SRVROOT "c:/Apache24"
ServerRoot "${SRVROOT}"
Listen 80
The above is pointing at the C: drive where Apache24 is located.
LoadModule rewrite_module modules/mod_rewrite.so
I have the above module uncommented. There are several other modules that have been uncommented, but the one above seems to be one of the main modules that, according to various Apache setup tutorials, is the main module.
ServerAdmin my.company#company.com
ServerName newprod.company.name.com:80
ServerName Localhost:80
According to various tutorials, the above seems to be accurate. I have compared my previous httpd.conf files, and they work using very similar configurations, including Localhost:80.
DocumentRoot "D:/htdocs"
<Directory "D:/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
The main part to focus on above the D:/htdocs. This is where I figured the sites should be opening from, as well as opening using the alias.
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
The above is typical for an Apache setup, per various tutorials.
<VirtualHost newprod.company.name.com:80>
ServerName newprod.company.name.com
Redirect / http://newprod.company.name.com/
</VirtualHost>
I use the above on another server (with a different alias) without any issues.
PHPIniDir "C:/PHP5.6"
AddHandler application/x-httpd-php .php
LoadModule php5_module "C:/PHP5.6/php5apache2_4.dll"
Then finally, the above is to ensure Apache will read PHP.
I have two other servers that are loading the sites with their own aliases with no problem. I literally went line for line trying to ensure everything matches. The only things that don't match is the PHP configurations at the bottom of the file. My other two servers are using PHP 7.4, while the problem server is using PHP 5.6.
Why aren't my sites loading using the alias I provided?
If you're using
ServerName newprod.company.name.com:80
ServerName Localhost:80
in main httpd.conf (or main apache config file), get rid of
ServerName Localhost:80
The vhost configuration
<VirtualHost newprod.company.name.com:80>
ServerName newprod.company.name.com
Redirect / http://newprod.company.name.com/
</VirtualHost>
is probably going to create a redirect loop: if that's all the configuration inside the virtualhost, get rid of it: it's useless.
Is port 80 on your apache server reachable from another pc? Are you able to telnet from a pc in the same lan on po 80 of apache server? Have you checked if the firewall is dropping the first syn packet?
As we have upgrade OS from centos 6.9 to Centos 7 on server. We have installed "Apache/2.4.6" and "PHP 5.6.36 (fpm-fcgi)" on this server. But we are facing problem to execute "PHP Code" in ".html" files. PHP code working fine in ".php file" but not in ".html files". I have ready many blogs but no where mentioned exact solution.
Can you please guide us how we can execute PHP code in .html files.
Note : We are using Apache 2.4, PHP-FPM and MPM_worker on centos 7.
After change below in files "/etc/php-fpm.d/www.conf" and "/etc/httpd/conf.d/php.conf" :
"security.limit_extensions = .php .php3 .php4 .php5 .htm" // in www.conf
and
SetHandler "proxy:fcgi://127.0.0.1:9000" // in php.conf
PHP code working in htm files but due to to these changes every html files renders as php. We want only php code render as php not html code render by php.
Your help would be appreciated.
This is how I configure Apache / PHP-FPM for a virtual host. It's not a public server so I'm only using HTTPS. This is from /etc/httpd/conf.d/ssl.conf:
<VirtualHost _default_:443>
DocumentRoot "/home/myvhost/public_html"
ServerName myvirtualhost.com:443
<Directory "/home/myvhost/public_html">
allow from all
Options FollowSymLinks SymLinksIfOwnerMatch
Require all granted
php_admin_value open_basedir /home/myvhost/public_html
</Directory>
SuexecUserGroup myvhost myvhost
ProxyPassMatch ^(/.*\.php)$ fcgi://127.0.0.1:9000/home/myvhost/public_html/$1
<FilesMatch \.php$>
# SetHandler application/x-httpd-php
SetHandler "proxy:fcgi://127.0.0.1:9000"
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</FilesMatch>
</VirtualHost>
And this is from /etc/php-fpm.d/myvhost.conf (copied from the default PHP-FPM configuration file):
[myvirtualhost.com]
user = myvhost
group = apache
listen = 127.0.0.1:9000
security.limit_extensions = .php
So basically you could just copy the "ProxyPassMatch" line and change php to html and do the same thing with "FilesMatch". You can also modify the regex but I'm not really good at that.
I have installed a collection of PHP versions from Remi Repositories, which may be ignored, for the question itself, but kept for the sake of understanding the processed I tried.
They work fine from command line, but I'd like to use them with Apache 2 (httpd on Fedora 24), running multiple virtual hosts as in:
php54.test
php55.test
php56.test
php70.test
php71.test
I have created the VirtualHost conf files and each one is working fine.
I want to run each corresponding php version (accordingly to the suggestive ServerName), but I can't find how to load PHP from each Virtual Host.
I couldn't find the corresponding Remi libphpX.so for loading them as modules:
<VirtualHost *:80>
ServerName php54.test
DocumentRoot /var/www/php54
#SOMETHING LIKE THIS...
LoadModule php??_module modules/libphp??.so
</VirtualHost>
I have, and this is not news, a shared hosting that allows me to change PHP version from .htaccess and I can do something like this:
AddHandler application/x-httpd-php54 .php
AddHandler application/x-httpd-php55 .php
AddHandler application/x-httpd-php56 .php
AddHandler application/x-httpd-php7 .php
AddHandler application/x-httpd-php71 .php
I may look like a dummy now, but how can I do the same .htaccess switching for having multiple PHP versions available?
I probably am not knowing what and how to search on Google to find the best matched answer.
You cannot use multiple versions of mod_php.
Better solution is to use php-fpm (the Fastcgi Process Manager), using in each vhost a SetHandler to fcgi server:
SetHandler "proxy:fcgi://127.0.0.1:9070"
Or (using unix domain socket)
SetHandler "proxy:unix:/var/opt/remi/php70/run/php-fpm/www.sock|fcgi://localhost"
This is described in this article : My PHP workstation.
Alright, I have spent hours searching through very similar questions but I still don't seem to have found the answer:
I have set up a virtual host with the following in my httpd-vhosts.conf
Listen 80
<VirtualHost *:80>
ServerName test.dev
ServerAlias test.dev
DocumentRoot "/Users/OrangeSoda/OneDrive/Projects/Test/Website"
ErrorLog "/private/var/log/apache2/test.dev-error_log"
CustomLog "/private/var/log/apache2/test.dev-access_log" common
<Directory "/Users/OrangeSoda/OneDrive/Projects/Test/Website">
Options all
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
In my http.conf I have Include /private/etc/apache2/extra/httpd-vhosts.conf as well as LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so uncommented.
When I go to test.dev/index.php which just has <?php echo "PHP TEST"; ?>, I see the contents of the file output as a string.
It seems as though PHP is not enabled and is therefore not being recognized.
If i go to localhost, I do see the "It Works!" page, so I know php is working, just for some reason not on my virtual host.
Someone suggested to put php_admin_flag engine on but that just makes the whole page crash.
Does anybody understand why php is not enabled here?
Have you checked if port 80 is opened? It might help more if you include detailed log.
You're on the right track but you need to actually load php onto the virtual host. On the <Directory> entry, add these lines :
<IfModule sapi_apache2.c>
php_admin_flag engine on
</IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
</IfModule>
I got the solution from here.
It looks like mod-php may not be installed. What OS are you on?
On Ubuntu/debian:
sudo apt-get install php5
on redhat:
sudo yum install php
The solution was that while php was enabled, for some reason the default setting in httpd.conf was not to read .php files as .php.
Although I am not really sure why that would not be the default setting, I added the following to my httpd.conf and now it works just fine:
AddType application/x-httpd-php .php
I have tried reinstalling PHP. PHP is working, and Apache2 is running. I don't know why it's not opening in a browser and displaying normally.
Just so you know - my httpd.conf is empty - and instead I have everything in apache2.conf. This is because I'm using Ubuntu.
Can you help me? I know it's something simple, but I can't seem to find the answer.
Have you virtual host on this project?
Are you open php file with http://localhost/file.php or directly like file://...../file.php ?
In your apache conf:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Don't forget to restart apache afterwards. Let me know how it goes.
In my case there was a modification of the /etc/apache2/mods-enabled/php5.conf by module userdir
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_value engine Off
</Directory>
</IfModule>
</IfModule>
The solution is inside the config file, just comment the lines from <IfModule mod_userdir> to </IfModule>.
Try
sudo a2enmod php5
in terminal.
Assuming you are using php 5 :)
If you are using php5 the complete solution would be
sudo apt-get install libapache2-mod-php5
Then
sudo a2enmod php5
I recently had this problem, but only when accessing my site's root (e.g. http://example.com) - it worked as expected when accessing index.php explicitly (e.g. http://example.com/index.php).
The issue was that before creating index.php, I had an index.html file in the web root, but then I renamed it to index.html.bak to 'move it out of the way'. Unfortunately, that doesn't move it out of the way. For whatever reason, Apache will serve that file up with a MIME type of application/x-trash.
(As the /etc/mime.types file contains a line reading "application/x-trash ~ % bak old sik")
Maybe that will help someone else who is scratching their head as I was.
Also, when moving a site and you encounter this, make sure your .htaccess file doesn't specify a different method handler for php. We ran into this moving a wordpress site for a client.
Had same problem - and it was in the .htaccess file I had accidentally downloaded from the live server. Once you've deleted the .htaccess file, you will need to clear your cache to be able to load the .php file in your browser via http://