In our previous guides, we installed Percona MySQL 5.7 on Ubuntu 18.04, then installed Apache2 with Let’s Encrypt and enabled HSTS, HTTP/2. Now, We Will Install PHP 7.2 on Ubuntu 18.04 LTS Running Apache2, Percona MySQL. That will create a typical LAMP server setup, enough to run PHP-MySQL web applications like WordPress. This tutorial can be used for cloud server, VPS, dedicated server. Dedicate server’s optimization only will differ.
Updates :
This article is for configuring APC.
---
This guide is an update to this article for installing PHP 7.4.
Steps to Install PHP 7.2 on Ubuntu 18.04 LTS
We will use Ondřej Surý’s PPA :
1 2 3 4 5 | sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php # hit enter key apt update apt upgrade |
After that part is complete, simply run :
1 | sudo apt-get install php |
By default, latest PHP will be installed. After installation is complete, run :
1 | php -v |
Which will return this kind of output :
1 2 3 4 | PHP 7.2.5-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: May 5 2018 05:00:15) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.5-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies |
Now, we have to install some of the PHP modules to run most of the PHP-MySQL applications, or WordPress with different plugins :
1 | apt install libapache2-mod-php7.2 php7.2-cgi php7.2-cli php7.2-common php7.2-curl php7.2-dev php7.2-gd php7.2-gmp php7.2-json php7.2-mysql php7.2-opcache php7.2-pgsql php7.2-pspell php7.2-readline php7.2-recode php7.2-sqlite3 php7.2-tidy php7.2-xml php7.2-xmlrpc libphp7.2-embed php-symfony-polyfill-php72 php7.2-bcmath php7.2-bz2 php7.2-mbstring php7.2-xsl php7.2-zip |
It will take some time. You can search modules for PHP 7.2 by running :
1 | sudo apt-cache search php* | grep 7.2 |
We actually installed most of them. Now go to your public HTML directory and create a PHP info page, like :
1 2 | cd /var/www/html nano info.php |
Copy paste this in that file :
1 | <!--?php // Show all information, defaults to INFO_ALL phpinfo(); ?--> |
Save the file. Open browser and point to that info.php
, file on browser, which will show you an informative page :
Do not forget to delete that php.info
file :
1 2 3 4 | cd /var/www/html rm info.php ## one line command # sudo bash -c "echo -e '<!--?php\nphpinfo();\n?-->' > /var/www/html/info.php" |
Update Ubuntu search database by running :
1 | sudo updatedb |
Then search PHP settings file :
1 | locate php.ini |
There are lot of PHP ini files, which will be used by your web application? We can run :
1 | php -i | grep ini |
You’ll get output like this :
1 2 3 4 5 | Configuration File (php.ini) Path => /etc/php/7.2/cli Loaded Configuration File => /etc/php/7.2/cli/php.ini Scan this dir for additional .ini files => /etc/php/7.2/cli/conf.d Additional .ini files parsed => /etc/php/7.2/cli/conf.d/10-mysqlnd.ini, ... |
Actually, /etc/php/7.2/cli/php.ini
is for CLI. See that php.ini
file on browser, there it is written :
Loaded Configuration File /etc/php/7.2/apache2/php.ini
So, essentially we have to tweak, optimize both files. Now install APCu :
1 | pecl install apcu |
We are creating the settings file of APCu (alternatively, you can open /etc/php/7.2/mods-available/cache.ini
and add extension=apcu.so
) :
1 | echo "extension=apcu.so" | tee -a /etc/php/7.2/mods-available/cache.ini |
And make a symlink :
1 | ln -s /etc/php/7.2/mods-available/cache.ini /etc/php/7.2/apache2/conf.d/30-cache.ini |
Now restart Apache :
1 | systemctl restart apache2 |
APCu makes codes faster by caching. Alternate method of installing APCu (example is for PHP 7.4) :
1 | sudo apt-get install php7.4-apcu |
You can read further settings :
1 | http://php.net/manual/en/apcu.configuration.php |
This is basic setup. You can search our website for PHP’s caching optimization with keywords like en Opcache, Opcache etc. But this much is basic need. Some settings of PHP ini also need minimum change to increase upload limit via PHP-MySQL applications.
Tagged With ubuntu php , https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1821 tWPQ2h8aWgJPqEz72jH4ahU4vl67eQayr1oL971qu5De9IxIrc1UfzicT8nEiBJR 5751e4149273b0333ed3386d38ba066284c0da48&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme , https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1836 cfx9PGRP6pjiLYmGOTSWZQcdyhB0C5ICbY8U7WFHJBgeJ6fdmLuAIMmLkqT73T5D 50617ded7e5c02d8bfa5c3250c2077757e3eee30&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme , https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1837 xUvf6DFOvxceTWJinKOjOhTQEx5S96YKF3QGyLAn7CkzgWukB1VBATJGmszGVGsq 4acd4ec050642716350b283190bbbcade72fbd1f&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme , install php 7 2 ubuntu 18 , paperuri:(43b2945e81ac1d056ed66e4a2c7c506d) , Ubuntu 18 LTS APCu , Ubuntu下源码安装MySQL , unbuntu 18 04 extensions PHP 7 2