A few weeks ago I did a series on setting up a new WordPress site, shortly after I had some problems uploading my caching plugin (wp-rocket). This was the error I got;
413 Request Entity Too Large
nginx/1.10.3 (Ubuntu)
Anyway, I fixed the error, and a few days later I got an email from someone with the same problem, so I thought this time I would document the fix.
Solution
Note: I’m going to raise the limits to 100Mb this might be far to large for you, 20 or 50Mb might be more sensible for most sites.
Firstly you need to make an entry in the nginx.conf file
[box]sudo nano /etc/nginx/nginx.conf[/box]
If you’re unused to working in these config files, you are looking for the http section, just before this sections ends (i.e. before the end curly bracket ‘}’), insert the following text.
[box]client_max_body_size 100M;[/box]
Exit and Save the file (ctrl+x, then ‘y’ {Enter}.
Restart nginx.
[box]sudo service nginx restart[/box]
You will also need to enter the new values in the php.ini file.
[box]sudo nano /etc/php/7.0/fpm/php.ini[/box]
Change the following values, like so;
upload_max_filesize = 100M
post_max_size = 100M
Exit and save the file, then restart PHP.
[box]sudo service php7.0-fpm restart[/box]
Related Articles, References, Credits, or External Links
Now the test if the web server is up and running, get the IP address (ifconfig), and browse to the IP address and you should see the nginx welcome page.
Note: If you get a 403 error, issue a ‘cp index.nginx-debian.html index.html‘ command and try again.
sudo systemctl start php7.0-fpm
systemctl status php7.0-fpm
[/box]
Now to enable nginx to pass information to the FastCGI server (allows php scripts to be executed outside the web server). Your nginx install should be taking its settings from a configuration file ‘/etc/nginx/sites-enabled/default’. To make sure execute an ‘nginx -t’ command. We need to edit that file.
Note: Below you will want to change the values in red to match your server, and the values in blue are optional. You can remove all the contents of the existing file and paste in the following.
# Default server configuration
server {
listen 80 default_server;
listen [::]:80 default_server;
# Set The Root Directory for the Entire Website
root /var/www/html/;
# Adding index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
# Add The Server IP Address or FQDN
server_name 123.123.123.12;
# Auto Remove and re-write .htm from requests (to maintain old back-links)
rewrite ^(/.*)\.htm(\?.*)?$ $1$2 permanent;
# The following does the WordPress Rewrites for the permalinks
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
# Allow the user to Cache Static files for 1 year
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
# pass PHP scripts to FastCGI server
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}
}
[/box]
Now save and exit the file, make sure its ok by running;
[box]nginx -t[/box]
Providing it says ‘successful’ restart nginx.
[box]sudo systemctl reload nginx[/box]
Testing PHP7 Works
Make sure we are up and running on version 7.
[box]php –version[/box]
Now just to be sure we are going to create a test page, put in some PHP and make sure it works.
Create a file;
[box]sudo nano /var/www/html/test.php[/box]
Pete in the following;
[box]<?php phpinfo(); ?>[/box]
Save and exit the file, then browse to http://{ip-address}/test.php it should look something like the image below.
It’s considered bad practice to have that file on the server, so lets delete it with the following command;
[box]sudo rm /var/www/html/test.php[/box]
That’s us with a fully functioning nginx web server thats processing PHP, in part three we will install WordPress, connect it to the database we made easier, and then you will be ready to start posting.
Related Articles, References, Credits, or External Links
I have a particular web page that uses PHP short tags. Post migration from my old hosting company to a dedicated VPS, this stopped working.
As I know little about Linux, and even less about PHP, I asked the question at Experts Exchange about why It was no longer working. I took no time at all, for someone who knew what they were doing to say, “Your code uses ‘Short tags’, but you do not have short tags enabled”
Solution
How To Enable PHP Short Tags From .htaccess
This would be your approach if you were on a hosted web server, and could not access the servers PHP configuration. In the ‘Root’ of your website should be a file called .htaccess you can simply edit this with any text editor (but make sure it does not save with a file extension!).
1. Connect to the server via SSH, (or open a terminal session). The file you need to edit is called php.ini. This server is running CentOS, so you should find that file in the /etc/ folder.
2. By default the line you are looking for is 229 (press CTRL+C to show position). Locate the short_open_tag = Off line.
3. Change the entry to ‘On’, and save the changes (CTRL+X and ‘Y’ to save).
4. Restart the web server.
[box]
service httpd restart[/box]
Related Articles, References, Credits, or External Links
Out of the box, Apache expects your website homepage to be called index, on this site the homepage is called home, here’s how to change it.
Solution
1. Connect to the server via SSH, (or open a terminal session). The file you need to edit is called httpd.conf. This server is running CentOS, so you should find that file in the /etc/httpd/conf folder.
2. I’m going to edit it with nano.
3. Locate the DirectoryIndex section and remove index and any other unwanted filename (i.e. in this example index.var).
4. Add in the one you require and save and exit, (press CTRL+X and Y to save).
–
5. You nee to restart Apache for the change to take effect.
[box] apachectl -k restart[/box]
Related Articles, References, Credits, or External Links