Apache Php

/ Comments off
  1. Apache Php-fpm
  2. Apache Php5
(Redirected from Apache HTTP server)

The Apache HTTP Server, or Apache for short, is a very popular web server, developed by the Apache Software Foundation.

This article describes how to set up Apache and how to optionally integrate it with PHP.

Apache is a popular web server application you can install on the Raspberry Pi to allow it to serve web pages. On its own, Apache can serve HTML files over HTTP, and with additional modules can serve dynamic web pages using scripting languages such as PHP. Apache will now execute all HTTP/S requests with PHP. If all you have are html, css, and php files, then this will work fine for you. If you have other languages running, then you'll need to tailor the file matching to your situation. I've tested this with phpMyAdmin and it works fine. Ubuntu 10.04, MySQL 5.1, Apache 2.2, and PHP 5.2/5.3: I just discovered that I am using the wrong version of PHP for a CRM application. Once I figured out how to make a simple phpinfo script to tell me what Apache2 is using, I tried changing the php.ini such that my webserver would use the PHP I want. Well, this is my problem.

  1. Apache 2.4 webserver with modrewrite (+ other important modules) enabled;.htaccess.htpasswd support; - choose between php 5.6, 7.1, 7.2, 7.3 with almost all extensions enabled (if you need anything custom, just ask); - free mysql databases powered by MariaDB 10.4.
  2. How to test the Apache and PHP configuration. How can I be sure that my PHP server is working? And How to know the version and modules enabled?

Installation

Install the apache package.

Configuration

Apache configuration files are located in /etc/httpd/conf. The main configuration file is /etc/httpd/conf/httpd.conf, which includes various other configuration files.The default configuration file should be fine for a simple setup. By default, it will serve the directory /srv/http to anyone who visits your website.

To start Apache, start httpd.service using systemd.

Apache should now be running. Test by visiting http://localhost/ in a web browser. It should display a simple index page.

For optional further configuration, see the following sections.

Advanced options

See the full list of Apache configuration directives and the directive quick reference.

These options in /etc/httpd/conf/httpd.conf might be interesting for you:

For security reasons, as soon as Apache is started by the root user (directly or via startup scripts) it switches to this UID. The default user is http, which is created automatically during installation.
This is the port Apache will listen to. For Internet-access with router, you have to forward the port.
If you want to setup Apache for local development you may want it to be only accessible from your computer. Then change this line to Listen 127.0.0.1:80.
This is the admin's email address which can be found on e.g. error pages.
This is the directory where you should put your web pages.
Change it, if you want to, but do not forget to also change <Directory '/srv/http'> to whatever you changed your DocumentRoot to, or you will likely get a 403 Error (lack of privileges) when you try to access the new document root. Do not forget to change the Require all denied line to Require all granted, otherwise you will get a 403 Error. Remember that the DocumentRoot directory and its parent folders must allow execution permission to others (can be set with chmod o+x /path/to/DocumentRoot), otherwise you will get a 403 Error.
This directive in <Directory> sections causes Apache to completely ignore .htaccess files. Note that this is now the default for Apache 2.4, so you need to explicitly allow overrides if you plan to use .htaccess files. If you intend to use mod_rewrite or other settings in .htaccess files, you can allow which directives declared in that file can override server configuration. For more info refer to the Apache documentation.
Tip: If you have issues with your configuration you can have Apache check the configuration with: apachectl configtest

More settings can be found in /etc/httpd/conf/extra/httpd-default.conf:

To turn off your server's signature:

To hide server information like Apache and PHP versions:

User directories

User directories are available by default through http://localhost/~yourusername/ and show the contents of ~/public_html (this can be changed in /etc/httpd/conf/extra/httpd-userdir.conf).

If you do not want user directories to be available on the web, comment out the following line in /etc/httpd/conf/httpd.conf:

The factual accuracy of this article or section is disputed.

Reason: It is not necessary to set +x for every users, setting it only for the webserver via ACLs suffices (see Access Control Lists#Granting execution permissions for private files to a web server). (Discuss in Talk:Apache HTTP Server#User Directories)

You must make sure that your home directory permissions are set properly so that Apache can get there. Your home directory and ~/public_html must be executable for others ('rest of the world'):

Restart httpd.service to apply any changes. See also Umask#Set the mask value.

TLS

Warning: If you deploy TLS, be sure to follow weakdh.org's guide to prevent vulnerabilities. For more information see Server-side TLS.

Firstly obtain a certificate. If you own a public domain, you can use Transport Layer Security#ACME clients.

In /etc/httpd/conf/httpd.conf, uncomment the following three lines:

If using certbot --apache, the following line needs to be uncommented as well:

After obtaining a key and certificate, make sure the SSLCertificateFile and SSLCertificateKeyFile lines in /etc/httpd/conf/extra/httpd-ssl.conf point to the key and certificate. If a concatenated chain of CA certificates was also generated, add that filename against SSLCertificateChainFile.

Finally, restart httpd.service to apply any changes.

Tip: Mozilla has a useful SSL/TLS article as well as an automated tool to help create a more secure configuration.

Virtual hosts

Note: You will need to add a separate <VirtualHost *:443> section for virtual host SSL support.See #Managing many virtual hosts for an example file.

If you want to have more than one host, uncomment the following line in /etc/httpd/conf/httpd.conf:

In /etc/httpd/conf/extra/httpd-vhosts.conf set your virtual hosts. The default file contains an elaborate example that should help you get started.

To test the virtual hosts on your local machine, add the virtual names to your /etc/hosts file:

Restart httpd.service to apply any changes.

Managing many virtual hosts

If you have a huge amount of virtual hosts, you may want to easily disable and enable them. It is recommended to create one configuration file per virtual host and store them all in one folder, eg: /etc/httpd/conf/vhosts.

First create the folder:

Then place the single configuration files in it:

In the last step, Include the single configurations in your /etc/httpd/conf/httpd.conf:

Shitsuji no princesama seriesbaldcirclebulk. Though, Uta no Prince-Sama Maji Love 1000% and gravitation is in a way different because Uta no prince sama has more characters and forth but for gravitation Shuichi just want to sing for yuki. If you like gravitation, you may end up liking uta no prince sama afterall they both have nice songs:D.

You can enable and disable single virtual hosts by commenting or uncommenting them.

A very basic vhost file will look like this:

Extensions

PHP

First install PHP, then follow one of the next three subsections below. Finally, test the installation as described in the final subsection.

Using libphp

This method is probably the easiest, but is also the least scalable: it is suitable for a light request load. It also requires you to change the mpm module, which may cause problems with other extensions (e.g. it is not compatible with #HTTP/2).

Installphp7-apache for PHP 7 or php-apache for PHP 8, as appropriate.

In /etc/httpd/conf/httpd.conf, comment the line:

and uncomment the line:

Note: The above is required, because libphp.so included with the package does not work with mod_mpm_event, but will only work mod_mpm_prefork instead. (FS#39218)

Otherwise you will get the following error:

As an alternative, you can use mod_proxy_fcgi (see #Using php-fpm and mod_proxy_fcgi below).

To enable PHP, add these lines to /etc/httpd/conf/httpd.conf:

  • Place this at the end of the LoadModule list:
  • Place this at the end of the Include list:

Restart httpd.service using systemd.

Using apache2-mpm-worker and mod_fcgid

This method provides improved performance and memory usage when serving multiple requests.

Installmod_fcgid and php-cgi.

Create the needed directory and symlink it for the PHP wrapper:

Create /etc/httpd/conf/extra/php-fcgid.conf with the following content:

Edit /etc/httpd/conf/httpd.conf:

  • Uncomment the loading of the actions module:
  • Load the FCGID module after the loading of the unixd module (on which it is dependent) - you may wish to place this within the <IfModule unixd_module> block:
  • Ensure that the inclusion of the MPM configuration is uncommented (it is uncommented in the default installed version of this file):
  • Add an inclusion of your new FCGID configuration:

Restarthttpd.service.

Using php-fpm and mod_proxy_fcgi

This method provides 'an alternative PHP FastCGI implementation with some additional features (mostly) useful for heavy-loaded sites' [1].

Note: Unlike the widespread setup with ProxyPass, the proxy configuration with SetHandler respects other Apache directives like DirectoryIndex. This ensures a better compatibility with software designed for libphp, mod_fastcgi and mod_fcgid.If you still want to try ProxyPass, experiment with a line like this:

Installphp-fpm.

Enable proxy modules:

Create /etc/httpd/conf/extra/php-fpm.conf with the following content:

And include it at the bottom of /etc/httpd/conf/httpd.conf:

Note: The pipe between sock and fcgi is not allowed to be surrounded by a space! localhost can be replaced by any string. More here

You can configure PHP-FPM in /etc/php/php-fpm.d/www.conf, but the default setup should work fine.

Start and enable php-fpm.service. Restarthttpd.service.

Test whether PHP works

To test whether PHP was correctly configured, create a file called test.php in your Apache DocumentRoot directory (e.g. /srv/http/ or ~<username>/public_html/) with the following contents:

Then go to http://localhost/test.php or http://localhost/~<username>/test.php as appropriate.

HTTP/2

Note:
  • While Apache supports unencrypted HTTP/2 over TCP (h2c), common browsers do not. Thus for use with the latter, #TLS must be enabled first.
  • If supporting clients do not use HTTP/2 instead of HTTP/1.1 and Mozilla's config generator (which already includes the Protocols line below) was used to setup #TLS, try Includeing httpd-ssl.confafter the latter's output.
  • Ways to test include curl -sI https://your.website or this Chrome extension.

To enable HTTP/2 over TLS support, uncomment the following line in httpd.conf:

And add the following line:

To debug, you can set only the module rather than the entire server to debug or info:

For more information – including extra HTTP/2 feature settings – see the mod_http2 documentation.

Warning: The http2_module is incompatible with the mpm_prefork_module that old configurations widely use to setup PHP. Consider using php-fpm instead.

Troubleshooting

Apache Status and Logs

See the status of the Apache daemon with systemctl.

Apache logs can be found in /var/log/httpd/

Error: PID file /run/httpd/httpd.pid not readable (yet?) after start

Comment out the unique_id_module line in httpd.conf: #LoadModule unique_id_module modules/mod_unique_id.so

/run/httpd not being created at boot

If systemd-tmpfiles --create as the root user complains about 'unsafe path transition', check ownership of your root directory.

Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe.

If when loading php_module the httpd.service fails, and you get an error like this in the journal:

This is because PHP includes support for a module that is not threadsafe, and you are trying to use a threaded MPM. One solution to fix this is to use a non-threaded MPM. Try replacing mpm_event_module with mpm_prefork_module:

and restart httpd.service.

AH00534: httpd: Configuration error: No MPM loaded.

You might encounter this error after a recent upgrade. This is only the result of a recent change in httpd.conf that you might not have reproduced in your local configuration.To fix it, uncomment the following line.

and restart httpd.service.

AH00072: make_sock: could not bind to address

This can be caused by multiple things. Most common issue being that something is already listening on a given port, check via netstat that this is not happening:

If you get any output, stop the given service that's taking up the port or kill the runaway process that is causing the port to be bound, and try again.

Another issue could be that Apache is not starting as root for some reason - try starting it manually and see if you still get the AH0072 error.

Finally, you can also have an error with your config and you are listening twice on the given port. Following is an example of a bad config that will trigger this issue:

AH01071: Got error 'Primary script unknown'

This can be caused by ProtectHome=true in the php-fpm systemd unit file if you are serving files in /home such as in a virtual host environment. You can disable this feature by editing the php-fpm unit file and restarting php-fpm. Alternatively, move your document root.

Php

Changing the max_execution_time in php.ini has no effect

If you changed the max_execution_time in php.ini to a value greater than 30 (seconds), you may still get a 503 Service Unavailable response from Apache after 30 seconds. To solve this, add a ProxyTimeout directive to your http configuration right before the <FilesMatch .php$> block:

and restart httpd.service.

PHP-FPM: errors are not being logged separately per virtual host

If you have multiple virtual hosts, it may be desirable to have each of them output their error logs to separate files (using the ErrorLog Apache directive). If this is not working for you, confirm that PHP-FPM is configured to log errors to syslog:

It's also possible that the pool configuration is overriding it. Ensure the following line is commented out:

See also

Apache Php-fpm

  • Apache on wiki.debian.org
Retrieved from 'https://wiki.archlinux.org/index.php?title=Apache_HTTP_Server&oldid=666981'

Apache NetBeans is much more than a text editor. It highlights source code syntactically and semantically, lets you easily refactor code, with a range of handy and powerful tools.

Apache NetBeans provides editors, wizards, and templates to help you create applications in Java, PHP and many other languages.

Apache NetBeans can be installed on all operating systems that support Java, i.e, Windows, Linux, Mac OSX and BSD. Write Once, Run Anywhere, applies to NetBeans too.

Subscribe to our mailing lists, or follow us in Twitter, Slack, FaceBook or YouTube.

Apache Php5

See how you can participate by submitting pull requests, filing issues, or joining the NetCAT program.

We are currently reviewing the tutorials. See how you can help us review the Java and PHP tutorials.