Nginx, Apache Configuration for CodeIgniter!

Meher Ullah Khan Raj
3 min readSep 7, 2020

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 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 set up 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.

http://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.

http://your_ip_address/phpmyadmin

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.

http://your_ip_address/phpmyadmin

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 it 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 to your server :).

Happy Coding 😍

--

--

Meher Ullah Khan Raj

Expertise in Full-Stack Development | Delivering Scalable Solutions