Image for post
Image for post

Nginx, Apache2 Configuration for CodeIgniter!

Meher Ullah Khan Raj
Sep 7 · 3 min read

We can see many resources for initial setups such as Nginx, PHP, MySQL, and PHPMyAdmin installation on Ubuntu. But when we want to set up a PHP project such as CodeIgniter then we facing problems with Nginx & Apache configuration.

To solve that problem I write this article also I added this link in my Configuring Nginx, PHP, MySQL, PHPMyAdmin on Ubuntu 20.04 (A to Z) — with Project Deploy article.

Before starting this configuration you have to make sure you have complete the initial setup from the link I attached in the top section.

Most of the time we face problems to setup Nginx sites-available (/etc/nginx/sites-available/default) configuration, In this section, I will be showing the ultimate solution for your CodeIgniter project.

Follow the steps.

Nginx Configuration (sites-available):

Add the following lines of code to the server block. Replace all code of server block using the following lines.

After this, you have to restart the Nginx service by running the following command.

service nginx restart

Now you are complete the configuration for Nginx, Now you can use your CodeIgniter Application using your IP address.


let’s follow the next section for Apache configuration.

Apache Configuration:

In the server block of the Nginx server, we rewrite the mode to use our CodeIgniter project using our IP Address, Now you can’t find your PHPMyAdmin using the URL.


Because we create a symlink in the initial setup with /var/www/html. Now we have to change the symlink for our CodeIgniter project with that directory (/var/www/html/ci) by running the following command.

ln -s /usr/share/phpmyadmin /var/www/html/ci

Now you can access your PHPMyAdmin by this URL.


Bonus Section:

Yes, It’s a bonus section for your apache configuration, sometimes for a big project, we have a large database, and we facing problems to import that database in our PHPMyAdmin.

Now I will show how you Import such a database in your server step by step.

PHP / Nginx: set max file upload and post size:

Firstly, you need to locate your php.ini file. In this example, our php.ini file is located in /etc/php/7.4/fpm/php.ini

sudo nano /etc/php/7.4/fpm/php.ini

In nano, press CTRL + W and search for upload_max_filesize and change the value to 80M (for 80 megabytes).

upload_max_filesize = 80M

Again search for post_max_size and change the value to 80M (for 80 megabytes).

post_max_size = 80M

Save file and exit. (Press CTRL+X, press Yand then press ENTER and Restart PHP FPM by running the command.

service php7.4-fpm restart

Now you can see in PHPMyAdmin the size updated, But In this case, you may need to update the Nginx Configuration file also.

Nginx Configuration to solve Nginx error: 413 Request Entity Too Large, follow the following step.

Nginx error: 413 Request Entity Too Large:

In case you may try to upload large files and are seeing this error, it means the client_max_body_size value is too low.

Open the Nginx configuration file by running this command.

sudo nano /etc/nginx/nginx.conf

If you have not found here It may also be located in usr/local/nginx/conf/nginx.conf or /usr/local/et/nginx/nginx.conf

If you still can’t find it, try locate

locate nginx.conf

To save file and exit nano. (Press CTRL+X, press Yand then press ENTER and check that the Nginx config file is valid after saving.

sudo nginx -t

If valid, reload the Nginx service.

sudo service nginx reload

Now you are all set, you can Import a Large database in your server :).

Happy Coding 😍

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store