There is a new version of this tutorial available for Ubuntu 16.04 (Xenial Xerus).

How to install TYPO3 7 on Nginx (LEMP) on Ubuntu 15.10

This tutorial shows how to install and run a TYPO3 (version 7 LTS) web site on a Ubuntu 15.10 system that has a Nginx web server installed instead of Apache. This kind of setup is often called LEMP = Linux + Nginx (pronounced "engine x") + MySQL + PHP). Nginx is a fast and efficient HTTP server that uses less resources than Apache and delivers pages a lot faster, especially static files.

 

1 Preliminary Note

I want to install TYPO3 in a vhost called www.example.com here with the document root /var/www/www.example.com/web.

You should have a working LEMP stack. If you don't have a LEMP installation yet, use this tutorial: Ubuntu LEMP Server

Because we have to run all the steps from this tutorial with root privileges, we can either prepend all commands in this tutorial with the string sudo, or we become root right now by typing

sudo su

I will use the nano editor to edit config files on the shell, nano can be installed with this command:

apt-get install nano 

2 Installing APCu

APCu is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It's similar to other PHP opcode cachers, such as eAccelerator and XCache. It is strongly recommended to have one of these installed to speed up your PHP page.

APCu can be installed as follows:

apt-get install php-apcu

If you use PHP-FPM as your FastCGI daemon, restart it as follows:

service php5-fpm restart

 

3 Installing TYPO3

The document root of my www.example.com web site is /var/www/www.example.com/web - if it doesn't exist, create it as follows:

mkdir -p /var/www/www.example.com/web

Next we download TYPO3 7 as a .tar.gz file from http://typo3.org/download/ and place it in our document root:

cd /var/www/www.example.com
wget get.typo3.org/7.6 -O typo3_src-7.6.0.tar.gz
tar xvfz typo3_src-7.6.0.tar.gz
rm typo3_src-7.6.x.tar.gz
cd web
ln -s ../typo3_src-7.6.0 typo3_src
ln -s typo3_src/index.php index.php
ln -s typo3_src/typo3 typo3

It is recommended to make the document root and the TYPO3 files in it writable by the Nginx daemon which is running as user www-data and group www-data:

chown -R www-data:www-data /var/www/www.example.com

If you haven't already created a MySQL database for TYPO3 (including a MySQL TYPO3 user), you can do that as follows (I name the database typo3 in this example, and the user is called typo3_admin, and his password is typo3_admin_password):

mysql --defaults-file=/etc/mysql/debian.cnf
CREATE DATABASE typo3;
GRANT ALL PRIVILEGES ON typo3.* TO 'typo3_admin'@'localhost' IDENTIFIED BY 'typo3_admin_password';
GRANT ALL PRIVILEGES ON typo3.* TO 'typo3_admin'@'localhost.localdomain' IDENTIFIED BY 'typo3_admin_password';
FLUSH PRIVILEGES;
quit

Next we create a Nginx vhost configuration for our www.example.com vhost in the /etc/nginx/sites-available/ directory as follows:

nano /etc/nginx/sites-available/www.example.com.vhost
server {
       listen 80;
       server_name www.example.com example.com;
       root /var/www/www.example.com/web;

       if ($http_host != "www.example.com") {
                 rewrite ^ http://www.example.com$request_uri permanent;
       }

       index index.php index.html;

       location = /favicon.ico {
                log_not_found off;
                access_log off;
       }

       location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
       }

       # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
       location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
       }

        location ~ \.php$ {
                        try_files $uri =404;
                        include /etc/nginx/fastcgi_params;
                        fastcgi_pass unix:/var/run/php5-fpm.sock;
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        fastcgi_intercept_errors on;
                        fastcgi_buffer_size 128k;
                        fastcgi_buffers 256 16k;
                        fastcgi_busy_buffers_size 256k;
                        fastcgi_temp_file_write_size 256k;
                        fastcgi_read_timeout 1200;
        }
		
        client_max_body_size 100M;

        location ~ /\.(js|css)$ {
                expires 604800s;
        }

        if (!-e $request_filename){
                rewrite ^/(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ /$1.$3 last;
        }

        location ~* ^/fileadmin/(.*/)?_recycler_/ {
                deny all;
        }
        location ~* ^/fileadmin/templates/.*(\.txt|\.ts)$ {
                deny all;
        }
        location ~* ^/typo3conf/ext/[^/]+/Resources/Private/ {
                deny all;
        }
        location ~* ^/(typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) {
        }

        location / {
                        if ($query_string ~ ".+") {
                                return 405;
                        }
                        if ($http_cookie ~ 'nc_staticfilecache|be_typo_user|fe_typo_user' ) {
                                return 405;
                        } # pass POST requests to PHP
                        if ($request_method !~ ^(GET|HEAD)$ ) {
                                return 405;
                        }
                        if ($http_pragma = 'no-cache') {
                                return 405;
                        }
                        if ($http_cache_control = 'no-cache') {
                                return 405;
                        }
                        error_page 405 = @nocache;

                        try_files /typo3temp/tx_ncstaticfilecache/$host${request_uri}index.html @nocache;
        }

        location @nocache {
                        try_files $uri $uri/ /index.php$is_args$args;
        }

}

This configuration already contains everything that is needed for clean URLs (because of the try_files $uri $uri/ /index.php$is_args$args; line in the @nocache location).

Next make sure you have the following line in /etc/nginx/mime.types:

nano /etc/nginx/mime.types
[...]
        text/x-component                        htc;
[...]

To enable the vhost, we create a symlink to it from the /etc/nginx/sites-enabled/ directory:

cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/www.example.com.vhost www.example.com.vhost

Reload Nginx for the changes to take effect:

service nginx reload

Create the FIRST_INSTALL file in the website root to enable the TYPO3 installer.

touch /var/www/www.example.com/web/FIRST_INSTALL

And change the owner to www-data so that the TYPO3 installation script can remove the file when the installation is finished.

chown www-data:www-data /var/www/www.example.com/web/FIRST_INSTALL

We have to adjust a few php.ini values to match the requirements for TYPO3. Open the php.ini file:

nano /etc/php5/fpm/php.ini

And adjust the following config options so that they have these values:

[....]
always_populate_raw_post_data=-1
[....]
max_execution_time=240
[....]
post_max_size = 20M
[....]
upload_max_filesize = 20M
[....]
max_input_vars=1500
[....]
memory_limit = 256M
[....]

Then save the file and restart PHP-FPM to load the new configuration:

service php5-fpm restart

Now we can launch the web-based TYPO3 installer by going to http://www.example.com/:

TYPO3 Installation - Check for prerequisites.

Click on the "System looks good. Continue" button to start the installation process. In case that this page shows a message that not all prerequisites are fulfilled, then adjust your config first to match the requirements before you proceed with the installation:

Next fill in the database details (user: typo3_admin; password: typo3_admin_password from when we created the typo3 database) and click on Continue:

TYPO3 Installation - Database Details.

On the next page choose Use an existing empty database and pick typo3 from the drop-down menu. Then click on Continue:

TYPO3 Installation - Select Database.

Next provide a username and password for the TYPO3 admin user and enter a name for your TYPO3 website. Click on Continue afterwards:

TYPO3 Installation - Set admin user.

The installation is now finished. If you want to start with a demo website instead of a completely empty system, select the Yes, download the list of distributions option (this will not install demo data immediately, but just make a demo website available in the backend from where you can choose to install it). I'll choose here to not download any demo sites. Then click on Open the backend:

TYPO3 Installation - Finish the installation.

The admin area can be found under http://www.example.com/typo3/. Log in with the username admin and the password you defined during installation:

TYPO3 Login.

And login with the TYPO§ administrator user that you created above.

The TYPO3 7 Administrator Backend.

And start to build your TYPO3 website. The frontend will show an error like "Service Unavailable (503) No pages are found on the rootlevel!" until you added a root page in the backend. I recommend to take a look at the excellent TYPO3 documentation on how to create your first website in TYPO3 if you are not familiar with this CMS yet.

4 Virtual machine image download of this tutorial

This tutorial is available as ready to use virtual machine image in ovf/ova format for Howtoforge Subscribers. The VM format is compatible with VMWare and Virtualbox. The virtual machine image uses the following login details:

SSH / Shell Login

Username: administrator
Password: howtoforge

This user has sudo rights.

MySQL / MariaDB Login

Username: root
Password: howtoforge

The IP of the VM is 192.168.1.100, it can be changed in the file /etc/network/interfaces. 

TYPO3 Login

Username: admin
Password: howtoforge

Please change all the above passwords to secure the virtual machine.

 

Share this page:

0 Comment(s)