Introduction
We’ll show you how to install PHP 7.1 with Nginx on Ubuntu 18.04. PHP 7.1 comes with many new features and improvements and as a result of this many developers are using it for their projects. Installing PHP 7.1 with Nginx on an Ubuntu 18.04, is an easy task, just follow the steps bellow and you should have it done in few minutes.
Step 1: Enable PPA
First of all, connect to your Linux VPS via SSH and enable the Ondrej’s PPA:
sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt-get update
Step 2: Install PHP 7.1
Once you enable the PPA you can proceed and install PHP 7.1 using the following command:
sudo apt-get install php7.1
Step 3: Search and install specific PHP 7.1 modules
This will also install the required dependencies too. However, if you want to install specific PHP7.1 module, you can search if it is available using the following command:
sudo apt-cache search php7.1
Step 4: Install most commonly used modules
To install PHP7.1 including some of the most commonly used modules you can use the following command:
sudo apt-get install php7.1 php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm
Step 5: Configure php.ini file
Once the installation is completed you need to edit the php.ini
file. Find the configuration file:
php --ini |grep Loaded Loaded Configuration File: /etc/php/7.1/cli/php.ini
Edit the file using your favorite text editor:
sudo nano /etc/php/7.1/cli/php.ini
Make the following changes:
cgi.fix_pathinfo=0
Then, restart the PHP-FPM service:
sudo systemctl restart php7.1-fpm.service
Step 6: Install Nginx on Ubuntu 16.04
Installing Nginx on Ubuntu is very easy. Run the following command to install it:
sudo apt-get install nginx
Create Nginx virtual server block for your domain name:
sudo nano /etc/nginx/sites-available/phxsolution.com
Paste the following content:
server { listen 80; server_name phxsolution.com www.phxsolution.com; root /var/www/phxsolution.com; index index.php; location / { try_files $uri $uri/ =404; } location ~ \.php$ { fastcgi_pass unix:/run/php/php7.1-fpm.sock; include snippets/fastcgi-php.conf; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ~ /\.ht { deny all; } }
Of course, you should replace phxsolution.com with your actual domain name. Save and close the file. To enable the server block in Nginx you need to create a symbolic link to site-enabled
. Use the following command to create a symbolic link:
sudo ln -s /etc/nginx/sites-available/phxsolution.com /etc/nginx/sites-enabled/phxsolution.com
Check if there are errors with the configuration:
sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
If the syntax is OK and there are no errors you can restart Nginx.
sudo systemctl restart nginx.service
Enable Nginx and PHP-FPM on system boot:
sudo systemctl enable nginx.service sudo systemctl enable php7.1-fpm.service
Recommended Posts
Secure Nginx With Let’s Encrypt On Ubuntu 18.04
September 11, 2020
How To Set Up Nginx Virtual Hosts On Ubuntu 18.04
September 11, 2020
How To Start / Stop / Restart Nginx Web Server On Ubuntu Linux?
September 11, 2020
Fabulous, what a webpage it is! This blog provides useful data to us, keep it up.
Excellent goods from you, man. I’ve understand your stuff previous to
and you are just extremely excellent. I really like
what you’ve acquired here, really like what you’re
saying and the way in which you say it. You make it entertaining and you still care for to keep it wise.
I can not wait to read much more from you.
This is actually a tremendous web site.