2016-07-19 11:12:28 +02:00
Adding a Virtual Host
---------------------
2016-07-19 13:05:02 +02:00
In order to access the PHP Censor web interface, you need to set up a virtual host in your web server.
2016-07-17 16:20:35 +02:00
Below are a few examples of how to do this for various different web servers.
2016-07-19 11:12:28 +02:00
Nginx Example
=============
2016-07-17 16:20:35 +02:00
```
server {
... standard virtual host ...
location / {
2016-07-21 19:20:59 +02:00
try_files $uri @php -censor;
2016-07-17 16:20:35 +02:00
}
2016-07-21 19:20:59 +02:00
location @php -censor {
2016-07-17 16:20:35 +02:00
# Pass to FastCGI:
fastcgi_pass unix:/path/to/phpfpm.sock;
fastcgi_index index.php;
fastcgi_buffers 256 4k;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME index.php;
}
}
```
2016-07-19 11:12:28 +02:00
Apache Example
==============
2016-07-17 16:20:35 +02:00
2016-07-19 13:05:02 +02:00
For Apache, you can use a standard virtual host, as long as your server supports PHP. All you need to do is add the following to a `.htaccess` file in your PHP Censor `/public` directory.
2016-07-17 16:20:35 +02:00
```
< IfModule mod_rewrite . c >
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
< / IfModule >
```
- Edit virtual host in apache2.
```
< VirtualHost * :80 >
ServerAdmin user@domain.com
2016-07-21 19:20:59 +02:00
DocumentRoot /var/www/php-censor.local/public
ServerName php-censor.local
2016-07-17 16:20:35 +02:00
2016-07-21 19:20:59 +02:00
< Directory / var / www / php-censor . local / public / >
2016-07-17 16:20:35 +02:00
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
< / Directory >
2016-07-21 19:20:59 +02:00
ErrorLog ${APACHE_LOG_DIR}/php-censor-error_log
CustomLog ${APACHE_LOG_DIR}/php-censor-access_log combined
2016-07-17 16:20:35 +02:00
< / VirtualHost >
```
2016-07-19 11:12:28 +02:00
- Add in /etc/hosts
2016-07-17 16:20:35 +02:00
```
2016-07-21 19:20:59 +02:00
127.0.0.1 php-censor.local
2016-07-17 16:20:35 +02:00
```
2016-07-19 11:12:28 +02:00
Built-in PHP Server Example
===========================
2016-07-17 16:20:35 +02:00
You can use the built-in PHP server `php -S localhost:8080` by adding `public/routing.php` .
```php
< ?php
if (file_exists(__DIR__ . '/' . $_SERVER['REQUEST_URI'])) {
return false; // serve the requested resource as-is.
} else {
include_once 'index.php';
}
```