#1
|
|||
A Fast Reliable and Proven Setup Apache PHP MySQL
​A Fast, Reliable and Proven Setup :: Apache PHP MySQL from [ICODE]Apachelounge[/ICODE]
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.:mrgreen: 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 ​CONTINUE: Install the Microsoft VC++ Redistributable For 2.4.x VC16/VS17 , 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/ 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:
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 8.x from http://windows.php.net/download/ you want this file: php-8.x.xx-Win32-VC11/14/15-x86/64.zip (where x relates to the latest stable version number) 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:\php8. Navigate to the PHP folder find php.ini-production, rename it to php.ini and edit it. FIND the extension_dir directive and change so that it properly locates the EXT folder. Enter a full path. extension_dir = "C:\php82\ext" 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 Code:
zend_extension=php_opcache.dll Code:
opcache.enable=On opcache.cli_enable=On 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:\php82\ext\php_xdebug-3.2.0-8.2-vs16-x86_64.dll [xdebug] xdebug.enable = 1 xdebug.remote_enable = 1 xdebug.idekey = "PHPSTORM" xdebug.profiler_enable = 0 example Code:
[xdebug] zend_extension="C:/php8.0.6/zend_ext/php_xdebug-3.0.4-8.0-vs16-x86_64.dll" ;xdebug.mode allowed are : off develop coverage debug gcstats profile trace xdebug.mode = debug xdebug.max_nesting_level = 1000 xdebug.discover_client_host = true xdebug.profiler_output_name = "cachegrind.out.%t.%p" xdebug.output_dir ="C:/wamp64/tmp" xdebug.show_local_vars=0 Download the DLL from http://pecl.php.net/package/redis Put that dll into the ext folder. e.g. C:\php81\ext in your php.ini load the redis extension. This must be done before loading opcache! Code:
extension=redis Code:
session.save_handler = redis session.save_path = "tcp://127.0.0.1:6379" 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 Code:
date.timezone = "Europe/Berlin" Ensure you can run PHP from the Windows Command Line ( Code:
php -m 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:\\php82" FcgidInitialEnv PATH "C:\\php82;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;" FcgidInitialEnv SystemRoot "C:\\Windows" FcgidInitialEnv SystemDrive "C:" FcgidInitialEnv TEMP "C:\\WINDOWS\\TEMP" FcgidInitialEnv TMP "C:\\WINDOWS\\TEMP" FcgidInitialEnv windir "C:\\WINDOWS" <Files ~ "\.php$"> Options Indexes FollowSymLinks ExecCGI AddHandler fcgid-script .php FcgidWrapper "C:/php82/php-cgi.exe" .php </Files> </IfModule> Now test apaches config file and see if everything loads. Open the command line again, and enter Code:
httpd -S Quote:
The default value 131018 (bytes) which is 128 kB to inscrease this for example to 15MB (15188640 (bytes)). e.g. Code:
FcgidMaxRequestLen 15188640 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 If do not want Apache starting automatically at start-up/reboot:
If you have troubles with your PHP script take a look at Basic PHP Troubleshooting MariaDB (MySQL) Setup
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:
Other users can access htdocs folder via ftp.
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 "áûÃÆöñð òõñ-ÿÃÆñûøúðÆøù" 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 Code:
<If "%{SERVER_PORT} == '443'"> <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> </If> 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-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-GCM-SHA384 SSLCipherSuite TLSv1.3 TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384 SSLOpenSSLConfCmd ECDHParameters secp521r1 SSLOpenSSLConfCmd Curves secp521r1:secp384r1 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:/php82" FcgidInitialEnv PATH "C:\\php82;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;" FcgidInitialEnv SystemRoot "C:\\Windows" FcgidInitialEnv SystemDrive "C:" FcgidInitialEnv TEMP "C:\\WINDOWS\\TEMP" FcgidInitialEnv TMP "C:\\WINDOWS\\TEMP" FcgidInitialEnv windir "C:\\WINDOWS" FcgidPassHeader Authorization <Files ~ "\.php$"> Options Indexes FollowSymLinks ExecCGI AddHandler fcgid-script .php FcgidWrapper "C:/php82/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:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;" FcgidInitialEnv SystemRoot "C:\\Windows" FcgidInitialEnv SystemDrive "C:" FcgidInitialEnv TEMP "C:\\WINDOWS\\TEMP" FcgidInitialEnv TMP "C:\\WINDOWS\\TEMP" 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:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;" FcgidInitialEnv SystemRoot "C:\\Windows" FcgidInitialEnv SystemDrive "C:" FcgidInitialEnv TEMP "C:\\WINDOWS\\TEMP" FcgidInitialEnv TMP "C:\\WINDOWS\\TEMP" 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> 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 |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Verizon’s found a way to make your FaceTime calls more reliable | phillynews215 | Digital Scoop | 0 | 12-12-2024 02:39 PM |
Make Firefox FAST! And I mean Fast | YourFriendWayneD | Recycle Bin | 4 | 06-28-2007 04:05 PM |
Installing Apache, PHP, MySQL, Perl on Windows | elboriyorker | Recycle Bin | 1 | 09-27-2006 11:39 AM |
Learning PHP and MySQL | elboriyorker | Recycle Bin | 0 | 07-02-2006 07:39 PM |
How to set up a server with Apache , PHP , MySQL , Perl , phpMyAdmin | elboriyorker | Recycle Bin | 0 | 06-28-2006 08:49 PM |