How to install PHP (7, 7.2 or 7.3) on Ubuntu Reset the MySQL 5.7 root password in Ubuntu 16.04 LTS Install Laravel 5.7, PHP 7.3 and NGINX on Ubuntu Basic PHP 7 and Nginx Configuration on Ubuntu 16.04 Linux
Step 1: Install NGINX as Web Server
sudo apt-get update && apt-get upgrade
sudo apt install nginx
sudo service nginx status
Step 2: Configuration the Firewall with UFW
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx HTTP'
Now enable ufw for Firewall.
sudo ufw enable
sudo ufw status
Step 3: Install PHP 7.3 FPM and Related Modules
sudo apt-get install software-properties-common
sudo apt-get update
Once the PPA repository has been added and updated, now we are going to install PHP 7.3
#install PHP 7.3
sudo apt-get install php7.3-fpm php7.3-cli php7.3-mysql php7.3-gd php7.3-imagick php7.3-recode php7.3-tidy php7.3-xmlrpc php7.3-common php7.3-curl php7.3-mbstring php7.3-xml php7.3-bcmath php7.3-bz2 php7.3-intl php7.3-json php7.3-readline php7.3-zip
#apt-get install php-pear php7.3-curl php7.3-dev php7.3-gd php7.3-mbstring php7.3-zip php7.3-mysql php7.3-xml
To set PHP 7.3 as the default, run:
update-alternatives --set php /usr/bin/php7.3
To verified PHP 7.3 was installed correctly on the web server, you may check the PHP version
sudo php -v
or
sudo php -me
To install PHP FastCGI Process Manager(fpm)
sudo apt-get install php7.3-fpm
or
sudo apt-get install php7.2-fpm
or
sudo apt-get install php7.1-fpm
The default location of the PHP socket that Nginx List the contents for the directory /var/run/php/
ls /var/run/php/
You will see the output like below, note this below we are going to use for the next server block configuration
php7.3-fpm.pid php7.3-fpm.sock
Step 4: Configure PHP file (Optional)
sudo vi /etc/php/7.3/fpm/php.ini
error_reporting = E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_ERROR | E_CORE_ERROR
max_input_time = 30
error_log = /var/log/php/error.log
file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Los_Angeles
Step 5:Configuration Server Blocks
sudo vi /etc/nginx/sites-available/default
server {
listen 80;
listen [::]:80;
root /var/www/html/lab-axfon/public;
index index.php index.html index.htm;
server_name lab.axfon.com;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
sudo service nginx restart
Step 5: install MySQL
sudo apt-get install mysql-server mysql-client
Step 6: install phpMyAdmin
sudo apt-get install phpmyadmin
sudo ln -s /usr/share/phpmyadmin/ /var/www/phpmyadmin