Phpstorm Apache



  1. Phpstorm Xampp Apache
  2. Phpstorm Apache Debug

Plugin for Intellij IDEA to provide a set of small Apache Camel related capabilities to the code editor. Create a local server configuration. In the local server configuration, you do your development, then copy the sources to the server. A local server is a server that is running in a local or a mounted folder and whose document root is NOT the parent of the project root. For common setups see: Apache HTTP Server, nginx, lighttpd and Hiawatha. To run PHP scripts as plain CGI. JetBrains PhpStorm — Commercial, cross-platform IDE. It will tell you how to setup the service for Apache. If you want or need ApacheMonitor you can create shortcuts however you like. Before installing ANYTHING else, ensure Apache will start. Open a command prompt and navigate to the BIN folder of Apache: 1. At the prompt enter httpd 2. One for CLI (e.g. Used when you execute script in CLI environment - in PhpStorm it would be 'PHP Script', 'PHPUnit' (and alike) types of Run/Debug Configuration (where PHP Interpreter gets involved directly) one used by PHP when run by Apache (Run/Debug Configurations where code is debugged over the browser/HTTP request).

Early Access ProgramFeaturesTutorials

Docker is an open platform for building, shipping and running distributed applications. It gives programmers, development teams and operations engineers the common toolbox they need to take advantage of the distributed and networked nature of modern applications.

With the new Docker integration plugin for PhpStorm, you can add Docker support to existing projects, view logs, manage Docker containers, and debug PHP web applications from right inside PhpStorm.

In this blog post we overview some of the most important features and configurations; for more details please refer to the full tutorial on Docker Support in PhpStorm.

Prerequisites

First of all, you’ll need to install Docker and related tools so that you can take advantage of the Docker integration in PhpStorm. Please refer to the Docker documentation to get more information about the installation process for various platforms or the cloud.

You will also need to install the Docker integration plugin in PhpStorm (in Settings /Preferences | Plugins, click the Install JetBrains plugin…).

PhpStorm & Docker Integration Configuration

To start using Docker, the default Docker machine should be launched using the Docker Quickstart Terminal (Windows / Mac OS X, for Linux you need to use a standard terminal executing asudo docker run hello-world command). At the next steps we’ll need some of the parameters of this machine environment, so we’ll need to run docker-machine env default console command to get all the necessary parameters (Windows / Mac OS X, for Linux you’ll need to use a standard IP address 172.17.42.1), such as DOCKER_HOST and DOCKER_CERT_PATH:

As soon as we have Docker running (and all the parameters fetched for future use), we can start configuring PhpStorm to work with Docker.

Create a Docker configuration with the + button in Settings / Preferences | Build, Execution, Deployment | Clouds:

We’ll need to provide the configuration name (Docker), API URL (https://192.168.99.100:2376, taken from the previous step), and Certificates folder (/Users/mikhailvink/.docker/machine/machines/default).

Please note that you will need to provide a socket path in the API URL field on Linux machines (unix:///var/run/docker.sock by default).

Next we need to create a new Docker Deployment Run/Debug Configuration in the Run | Edit configurations… menu.

Provide all the necessary parameters on the Deployment and Container tabs:

At this point we are interested in exposing port 80 of the container to be available from our local machine, so we should configure a port binding for that:

There are many ways to create/configure Docker containers and VM images; please refer to the Docker documentation on their official website.

For the purposes of this tutorial we’re making some configuration in the Dockerfile and Apache configuration file, so do have a look at them. You can download the entire project used in this demo or separate config files (apache-config.conf, Dockerfile) which then need to be placed in the project root folder.

Running the Docker from PhpStorm

As all the tools are installed and the integration is configured, the recently created Start Docker Run/Debug Configuration can be launched. The Application Servers tool window will be opened updating you on the provisioning status and current state of all your Docker containers:

As soon as our Docker_Xdebug container’s status turns green, we can check how it works in the browser. You should be able to open it with a URL similar to http://192.168.99.100:8080/ (http://host:port, 192.168.99.100 is the IP address of the default Docker machine).

Managing Docker containers and other Docker-related actions in PhpStorm

From the Application Servers tool window, it’s easy to inspect containers and view the running processes. You can also search through logs, start and stop containers, and perform basic container management like creating and deleting containers.

Debugging PHP web application running in the Docker container

The main challenge in getting Xdebug (or Zend Debugger) working with PhpStorm and Docker integration is the correct configuration of the Docker container.

In our case we’re using a Dockerfile (we’ve already shown this config earlier and provided links to download it) to configure the container, including Xdebug-specific parameters, such as:

RUN echo 'zend_extension=/usr/lib/php5/20131226/xdebug.so'>> /etc/php5/apache2/php.ini
RUN echo 'xdebug.remote_enable=1'>> /etc/php5/apache2/php.ini
#Please provide your host (local machine IP) instead of 192.168.2.117
RUN echo 'xdebug.remote_host=192.168.2.117'>> /etc/php5/apache2/php.ini

Please note that xdebug.remote_host value should be replaced with your local machine IP address which is visible from the Docker container (where PhpStorm is running, in our case 192.168.2.117).

Don’t forget to re-run Start Docker Run/Debug Configuration so that all the changes are applied.

As soon as all the configs are in place, the debugging process can be triggered by following this tutorial starting with step 2 (start Listening for PHP Debug Connections, set a breakpoint in the source code, and start a debugging session in the browser, reload the current page, debug) to get the debugger up and running in a few moments:

Please have a look at the full tutorial on Docker Support in PhpStorm for more information.

Please share your feedback on Docker support in PhpStorm in the forum, comments to this blog post, or our issue tracker. Thanks!

Develop with pleasure!
JetBrains PhpStorm Team

One of the biggest topics here at Apache Lounge is running PHP on Apache.
It is a topic that is constant and for some reason often confused.
Confused namely by varying ways to accomplish the same thing.
The following has been tested numerous times, and seems (at least so far) to be easy to follow.
IF YOU PREVIOUSLY INSTALLED APACHE USING A MSI FILE THEN (otherwise skip down to CONTINUE section):
I have not tested Apache Software Foundation (ASF) MSI installation applications lately,
but the last time I tested the MSI FAILED to remove to some things that can cause problems later on during
the Un-Install process. BEFORE you UN-INSTALL the MSI file, open a command prompt run as administrator and navigate to
the BIN folder of Apache. Now, uninstall the service:
Code:

httpd -k uninstall

Now that the service is removed, uninstall Apache and then ALL PHP entries
CONTINUE:
Install the Microsoft VC++ Redistributable
For 2.4.x VC15/VC16 , download Win 32 bit (x86) or Win 64 bit (x64) 2.4 from http://www.apachelounge.com/download/
Apache Setup
Download httpd-2.4.x-winYY-VCxx.zip from http://www.apachelounge.com/download/Phpstorm Apache
Note: you can substitue drive letters to what will work best for you or your situation. I advise however, that you DO NOT place PHP in the Apache root though.
Unzip this ZIP file in a new folder called something like C:Apache24. Then, read the file named Read Me First !!.txt. It will tell you how to setup the service for Apache.
If you want or need ApacheMonitor you can create shortcuts however you like. Before installing ANYTHING else, ensure Apache will start.
Open a command prompt and navigate to the BIN folder of Apache:

    1. At the prompt enter httpd
    2. If there's nothing seriously wrong, Apache will start: the cursor will drop down one line and blink (you should be able to use your browser and navigate to http://localhost and see 'It Work!'.
    3. With focus on the Command Prompt window - Hold down CTRL hit the C key then release both - within a couple of seconds the prompt will be released (Apach will Stop).

After you validate that Apache starts, stop it before proceding.
PHP Setup
Note: you can substitue drive letters and folder names to what will work best for you or your situation. I advise however, that you DO NOT place PHP in the Apache root though.
If you are still with me, now download PHP 7.x from http://windows.php.net/download/ you want this file: php-7.x.xx-Win32-VC11/14/15-x86/64.zip (where x relates to the latest stable version number) Phpstorm/php-71-apache-xdebug
Yes there is a way to install PHP as module, but it has been proved best to install PHP over mod_fcgid (fastcgi, best practice)
Please download the VC11/14 x86/x64 Non Thread Safe OR VC14/VC15/VC16 x86/x64 Thread Safe.
Extract the contents of this file and move the contents to where you intend to use PHP such as C:php7.
Navigate to the PHP folder and edit the php.ini-production. FIND the extension_dir directive and change so that it properly locates the EXT folder. Enter a full path.
extension_dir = 'C:php7ext'
If you want to use the mysql extension you have to enable it un commenting it (removing ';') in that line of php.ini. A good start is ot enbale mysql and mysqli
Code:

extension=php_mysqli
extension=mbstring
extension=pdo_mysql

it is recommended to enable op cache. ( directly after all the other extensions)
Code:

zend_extension=php_opcache.dll

Below search for [opcache]
Code:

opcache.enable=On
opcache.cli_enable=On

If you need xdebug (optional, only for development!) make you set a full path and load it AFTER opcache. It needs to be the last one.
xdebug is not recommended for production use.
use the https://xdebug.org/wizard to download the correct version of xdebug for your PHP version.
example
Code:

zend_extension = C:php7extphp_xdebug-2.9.0-7.4-vc15-x86_64.dll
[xdebug]
xdebug.enable = 1
xdebug.remote_enable = 1
xdebug.idekey = 'PHPSTORM'
xdebug.profiler_enable = 0

hide PHP from apache response headers
Code:

expose_php = Off

Fix the path info in the scripts
Code:

cgi.fix_pathinfo=1

Set your timezone. Find your zone at http://php.net/date.timezone

Phpstorm Xampp Apache

Code:

date.timezone = 'Europe/Berlin'

Save the file as php.ini.
Ensure you can run PHP from the Windows Command Line (
Code:
php -m
should work and produce a list of modules loaded).
Finally, this should be the last step, edit the Apache CONF file (httpd.conf) with
make sure you load mod fcgid. ( mod_fcgid is an additional download)
Code:

LoadModule fcgid_module modules/mod_fcgid.so
<IfModule fcgid_module>
FcgidMaxProcesses 300
FcgidMaxProcessesPerClass 300
FcgidOutputBufferSize 65536
FcgidConnectTimeout 10
FcgidProcessLifeTime 0
FcgidMaxRequestsPerProcess 0
FcgidMinProcessesPerClass 0
FcgidFixPathinfo 0
FcgidProcessLifeTime 0
FcgidZombieScanInterval 20
FcgidMaxRequestLen 536870912
FcgidIOTimeout 120
FcgidTimeScore 3
FcgidPassHeader Authorization
FcgidInitialEnv PHPRC 'C:php7'
FcgidInitialEnv PATH 'C:php7;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;'
FcgidInitialEnv SystemRoot 'C:Windows'
FcgidInitialEnv SystemDrive 'C:'
FcgidInitialEnv TEMP 'C:WINDOWSTEMP'
FcgidInitialEnv TMP 'C:WINDOWSTEMP'
FcgidInitialEnv windir 'C:WINDOWS'
<Files ~ '.php$'>
Options Indexes FollowSymLinks ExecCGI
AddHandler fcgid-script .php
FcgidWrapper 'C:/php7/php-cgi.exe' .php
</Files>
</IfModule>

Save the httpd.conf file. Start Apache.
set in your php.ini
Code:

cgi.fix_pathinfo = 1

For Windows 2000,XP,2003,Vista to ensure that the PATH addition is set, PLEASE reboot your PC!!! No Need for Windows 8, 8.1 and 10.
Now test apaches config file and see if everything loads. Open the command line again, and enter
Code:

httpd -S

If you have an issue like
Quote:

mod_fcgid: HTTP request length 131400 (so far) exceeds MaxRequestLen (131072)

You need to adjust FcgidMaxRequestLen bytes
The default value 131072 (bytes) which is 128 kB to inscrease this for example to 15MB (15728640 (bytes)).
e.g.
Code:

FcgidMaxRequestLen 15728640

For running mod_php and fcgid combined and or multiple php versions see https://www.apachelounge.com/viewtopic.php?t=3430
Configuration, see http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
Save the httpd.conf file. Start Apache.
***Since some have asked where to place this in the httpd.conf - Here's what I do:
***
*** LoadModule directive goes at the end of the long list of LoadModule directives
*** I add a blank line after the LoadModule directive then add the AddHandler directive
*** I place the PHPIniDir directive right after the AddHandler directive
***

END PHP Setup
If you receive no errors, and you want to run Apache as a Service then open a command prompt run as administrator and navigate to the BIN folder of Apache. Now, install the service:
Code:
httpd -k install

Phpstorm Apache Debug

That command will add Apache2 to the Services MSC.
If do not want Apache starting automatically at start-up/reboot: Phpstorm/php-73-apache-xdebug-27
    1. START | RUN
    2. Type in services.msc, hit Enter or click OK
    3. Locate Apache2 service and double-click (or right-click for Properties)
    4. Find the caption Startup type: (in the middle of the dialog box), use the pull-down and select Manual
    5. Click OK

If you have troubles with your PHP script take a look at Basic PHP Troubleshooting
MySQL Setup

    1. Download from mysql.com community downloadpage --> Windows downloads -- Without installer (unzip in C:) --> » No thanks, just take me to the downloads!
    2.Unzip the mysql-noinstall-5.x.xx-win32.zip to e.g. C: rename it to mysql
    3. Uninstall any previous MySQL Windows service
    Code:

    mysqld.exe --remove

    4. Copy one of the MySQL*.ini files (usually my-large.ini) to MySQLmy.ini
    5. Edit my.ini and change any parameters for your site.
    6. You can install mysqld.exe as a Windows service with
    (see also : http://dev.mysql.com/doc/refman/5.6/en/windows-start-service.html )

Code:

mysqld.exe --install

After you install the service be sure to:
Secure the initial MySQL accounts MySQL access controls. Be aware that default both root and the anonymous account are set up with no password, so anyone can connect to the MySQL server as root.
Optional:

    7. Download phpmyadmin which is a good interface over your browser to mysql.
    Only you can access the htdocs folder from the server or ftp
    8a. unzip it to C:Apache2htdocs and rename it to phpmyadmin
    9a. install phpmyadmin with the installer script in http://yourdomain.tld/phpmyadmin/scripts/setup.php
    10a. Delete the scripts folder in phpmyadmin. Create a .htaccess with
    Code:

    <RequireAll>
    Require ip 192.168 127.0.0.1
    </RequireAll>

    so no one can access that, but from your network and the server itself.
Phpstorm/php-71-apache-xdebug-26
Other users can access htdocs folder via ftp.

    8b. unzip it to C:Apache24 and rename it to phpmyadmin
    edit the httpd.conf add:
    Code:

    Alias /mydbdmanager/ 'C:/Apache24/phpmyadmin/'
    <Directory 'C:/Apache24/phpmyadmin'>
    Options Indexes MultiViews
    AllowOverride All
    <RequireAll>
    Require ip 192.168 127.0.0.1
    </RequireAll>
    </Directory>

    9b. install phpmyadmin with the installer script in http://yourdomain.tld/mydbdmanager/setup/index.php
    10b. Delete the setup folder in phpmyadmin.
    11. Now you should have access over http://http://yourdomain.tld/phpmyadmin/ or http://yourdomain.tld/mydbdmanager/

On Windows 10 there is sometimes an error that port 80 is blocked, it might be W3SVC service. Set it to 'manual' starting.
Code:
french name is: 'Service de publication World Wide Web'
english name is: 'World Wide Web Publishing Services'
german name is: 'WWW-Publishingdienst'
Polish name is: 'Usluga publikowania w sieci WWW'
Russian name is 'Служба веб-публикаций'

other Programs that may causes apache not running
Troubleshooting
Sometimes apache doesn'tr start at all. Try adding the following block at the end of httpd.conf
Code:

EnableMMAP Off
EnableSendfile Off
AcceptFilter http none
AcceptFilter https none

Performance
Disable mod_status at all or at least ExtendedStatus Off
Load only modules that you really need
Something is blocking the Apache port(s)?
run cmd.exe as Administrator and run
Code:

netstat -ano | findstr /R 0.0:80 && netstat -ano | findstr /R 0.0:443

SSL Config
Code:

<IfModule mod_headers.c>
# you can enable this, but make sure that you understand it
# Header always set Strict-Transport-Security 'max-age=15553000;'
</IfModule>
TraceEnable Off
SSLUseStapling On
SSLSessionCache shmcb:C:/Windows/Temp/ssl_gcache_data(512000)
SSLStaplingCache shmcb:C:/Windows/Temp/ssl_stapling_data(512000)
SSLOptions +StrictRequire +StdEnvVars -ExportCertData
SSLProtocol -all +TLSv1.2 +TLSv1.3
SSLCompression Off
SSLHonorCipherOrder On
SSLCipherSuite SSL ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384
SSLCipherSuite TLSv1.3 TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384
SSLOpenSSLConfCmd ECDHParameters secp521r1
SSLOpenSSLConfCmd Curves sect571r1:sect571k1:secp521r1:sect409k1:sect409r1:secp384r1:sect283k1:sect283r1:secp256k1:prime256v1
SSLOpenSSLConfCmd SignatureAlgorithms rsa_pss_rsae_sha512:rsa_pss_rsae_sha256:ECDSA+SHA512:ECDSA+SHA256:RSA+SHA512:RSA+SHA256
SSLOpenSSLConfCmd ClientSignatureAlgorithms rsa_pss_rsae_sha512:rsa_pss_rsae_sha256:ECDSA+SHA512:ECDSA+SHA256:RSA+SHA512:RSA+SHA256

Virutal hosts
Note: if you add your first virutal host, the Domain from the httpd.conf will 'disappear'.
Code:

<VirtualHost *:80>
ServerName test.local
DirectoryIndex index.php
<IfModule fcgid_module>
FcgidInitialEnv PHPRC 'C:/php7'
FcgidInitialEnv PATH 'C:php7;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;'
FcgidInitialEnv SystemRoot 'C:Windows'
FcgidInitialEnv SystemDrive 'C:'
FcgidInitialEnv TEMP 'C:WINDOWSTEMP'
FcgidInitialEnv TMP 'C:WINDOWSTEMP'
FcgidInitialEnv windir 'C:WINDOWS'
FcgidPassHeader Authorization
<Files ~ '.php$'>
Options Indexes FollowSymLinks ExecCGI
AddHandler fcgid-script .php
FcgidWrapper 'C:/php7/php-cgi.exe' .php
</Files>
</IfModule>
CustomLog 'C:nul' common
DocumentRoot 'C:/public'
<Directory 'C:/public'>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA]
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
DirectoryIndex index.php
<IfModule fcgid_module>
FcgidInitialEnv PHPRC 'C:/php7'
FcgidInitialEnv PATH 'C:php7;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;'
FcgidInitialEnv SystemRoot 'C:Windows'
FcgidInitialEnv SystemDrive 'C:'
FcgidInitialEnv TEMP 'C:WINDOWSTEMP'
FcgidInitialEnv TMP 'C:WINDOWSTEMP'
FcgidInitialEnv windir 'C:WINDOWS'
FcgidPassHeader Authorization
<Files ~ '.php$'>
Options Indexes FollowSymLinks ExecCGI
AddHandler fcgid-script .php
FcgidWrapper 'C:/php7/php-cgi.exe' .php
</Files>
</IfModule>
CustomLog 'C:nul' common
DocumentRoot 'C:/public'
<Directory 'C:/public'>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA]
</Directory>
SSLEngine on
SSLCertificateFile conf/certs/internal/fullchain.pem
SSLCertificateKeyFile conf/certs/internal/privkey.pem
<Files ~'.(cgi|shtml|phtml|php|htm|html?)$>
SSLOptions +StdEnvVars
</Files>
</VirtualHost>
<VirtualHost *:443>
ServerName other.example.com
DirectoryIndex index.php
<IfModule fcgid_module>
FcgidInitialEnv PHPRC 'C:/php7'
FcgidInitialEnv PATH 'C:php7;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;'
FcgidInitialEnv SystemRoot 'C:Windows'
FcgidInitialEnv SystemDrive 'C:'
FcgidInitialEnv TEMP 'C:WINDOWSTEMP'
FcgidInitialEnv TMP 'C:WINDOWSTEMP'
FcgidInitialEnv windir 'C:WINDOWS'
FcgidPassHeader Authorization
<Files ~ '.php$'>
Options Indexes FollowSymLinks ExecCGI
AddHandler fcgid-script .php
FcgidWrapper 'C:/php7/php-cgi.exe' .php
</Files>
</IfModule>
CustomLog 'C:nul' common
DocumentRoot 'C:/other'
<Directory 'C:/other'>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA]
</Directory>
SSLEngine on
SSLCertificateFile conf/certs/internal/fullchain.pem
SSLCertificateKeyFile conf/certs/internal/privkey.pem
<Files ~'.(cgi|shtml|phtml|php|htm|html?)$>
SSLOptions +StdEnvVars
</Files>
</VirtualHost>

Vhosts several files.
it might coming handy to use one file for each domain. You can do that by a include trick in the httpd.conf
Apache will include any .conf file in the APACHEROOTFOLDER/conf/vhosts
Code:

# Virtual hosts
Include conf/vhosts/*.conf

Enjoy,
James Blond
Admin note:
If you still have issues or find something confusing, please post in one of the other forums.

Last edited by James Blond on Fri 16 Oct '20 11:08; edited 43 times in total