Created
April 26, 2025 03:47
-
-
Save siagung/3dcac4eff8b67fd38cddb1b2cba42e4a to your computer and use it in GitHub Desktop.
Apache VirtualHost Configuration for CodeIgniter 3 with PHP-FPM and SSL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| optimized VirtualHost configuration for your CodeIgniter 3 application with PHP-FPM and SSL on AlmaLinux 9: | |
| <VirtualHost *:80> | |
| ServerName xxx.co.id | |
| ServerAlias www.xxx.co.id | |
| DocumentRoot /var/www/html/xxx.co.id | |
| # Redirect all HTTP to HTTPS | |
| RewriteEngine On | |
| RewriteCond %{HTTPS} off | |
| RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
| </VirtualHost> | |
| <VirtualHost *:443> | |
| ServerName xxx.co.id | |
| ServerAlias www.xxx.co.id | |
| DocumentRoot /var/www/html/xxx.co.id | |
| # SSL Configuration | |
| SSLEngine on | |
| Include /etc/letsencrypt/options-ssl-apache.conf | |
| SSLCertificateFile /etc/letsencrypt/live/xxx.co.id/fullchain.pem | |
| SSLCertificateKeyFile /etc/letsencrypt/live/xxx.co.id/privkey.pem | |
| # PHP-FPM Configuration | |
| <FilesMatch \.php$> | |
| SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost" | |
| </FilesMatch> | |
| # Directory Settings | |
| <Directory /var/www/html/xxx.co.id> | |
| Options -Indexes +FollowSymLinks | |
| AllowOverride All | |
| Require all granted | |
| # CodeIgniter URL Rewrite | |
| RewriteEngine On | |
| RewriteBase / | |
| # Allow access to existing files/directories | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteCond %{REQUEST_FILENAME} !-d | |
| # Rewrite all other requests to index.php | |
| RewriteRule ^(.*)$ index.php?/$1 [L,QSA] | |
| </Directory> | |
| # Security Headers | |
| Header always set X-Content-Type-Options "nosniff" | |
| Header always set X-Frame-Options "SAMEORIGIN" | |
| Header always set X-XSS-Protection "1; mode=block" | |
| Header always set Referrer-Policy "strict-origin-when-cross-origin" | |
| # Error Logging | |
| ErrorLog /var/log/httpd/xxx_error.log | |
| CustomLog /var/log/httpd/xxx_access.log combined | |
| # PHP Settings (optional) | |
| <IfModule mod_env.c> | |
| SetEnv CI_ENV production | |
| </IfModule> | |
| </VirtualHost> | |
| ----------------------------------------------------- | |
| Verify PHP-FPM is running: | |
| sudo systemctl status php-fpm | |
| Set correct permissions: | |
| sudo chown -R apache:apache /var/www/html/xxx.co.id | |
| sudo find /var/www/html/xxx.co.id -type d -exec chmod 755 {} \; | |
| sudo find /var/www/html/xxx.co.id -type f -exec chmod 644 {} \; | |
| Create .htaccess file in your document root: | |
| sudo nano /var/www/html/xxx.co.id/.htaccess | |
| <IfModule mod_rewrite.c> | |
| RewriteEngine On | |
| RewriteBase / | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteCond %{REQUEST_FILENAME} !-d | |
| RewriteRule ^(.*)$ index.php?/$1 [L,QSA] | |
| </IfModule> | |
| restart : | |
| sudo systemctl restart php-fpm httpd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment