Install VPS debian PHP Apache postgresql
apt-get -y install apache2
Buka file /etc/apt/sources.list
deb http://deb.debian.org/debian stretch main
deb-src http://deb.debian.org/debian stretch mainapt-get update
apt-get -y install php7.0 libapache2-mod-php7.0
sudo apt-get install php7.0-zip
sudo apt-get install php7.0-xml
Enabling Necessary Apache Modules
Apache has many modules bundled with it that are available but not enabled in a fresh installation. First, we’ll need to enable the ones we’ll use in this tutorial.
The modules we need are mod_proxy
itself and several of its add-on modules, which extend its functionality to support different network protocols. Specifically, we will use:
mod_proxy
, the main proxy module Apache module for redirecting connections; it allows Apache to act as a gateway to the underlying application servers.mod_proxy_http
, which adds support for proxying HTTP connections.mod_proxy_balancer
andmod_lbmethod_byrequests
, which add load balancing features for multiple backend servers.
To enable these four modules, execute the following commands in succession.
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
To put these changes into effect, restart Apache.
sudo systemctl restart apache2
How to Install PHP 7.2 on Ubuntu 18.04
PHP 7.2 is included by default in Ubuntu’s repositories since version 18.04. So the instructions are pretty similar to PHP 7 for 16.04.
Update Ubuntu
Again, before doing anything, you should update your server:
apt-get update && apt-get upgrade
Install PHP 7.2
Next, to install PHP 7.2 on Ubuntu 18.04, just run the following command:
apt-get install php
This command will install PHP 7.2, as well as some other dependencies.
To verify if PHP is installed, run the following command:
php -v
You should get a response similar to this:
PHP 7.2.3-1ubuntu1 (cli) (built: Mar 14 2018 22:03:58) ( NTS )
And that’s it. PHP 7.2 is installed on your Ubuntu 18.04 server.
Install PHP 7.2 modules
These are the most common PHP 7.2 modules often used by php applications. You may need more or less, so check the requirements of the software you’re planning to use:
apt-get install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php
To check all the PHP modules available in Ubuntu, run:
apt-cache search --names-only ^php
How to change the PHP version you’re using
If you have multiple PHP versions installed on your Ubuntu server, you can change what version is the default one.
To set PHP 7.0 as the default, run:
update-alternatives --set php /usr/bin/php7.0
To set PHP 7.2 as the default, run:
update-alternatives --set php /usr/bin/php7.2
If you’re following our LAMP tutorials and you’re using Apache, you can configure Apache to use PHP 7.2 with the following command:
a2enmod php7.2
And then restart Apache for the changes to take effect:
systemctl restart apache2
How to upgrade to PHP 7.2 on Ubuntu
If you’re already using an older version of PHP with some of your applications, you can upgrade by:
- Backup everything.
- Install the newest PHP and required modules.
- Change the default version you’re using.
- (Optionally) Remove the older PHP
- (Required) Configure your software to use the new PHP version. You’ll most likely need to configure Nginx/Apache, and many other services/applications. If you’re not sure what you need to do, contact professionals and let them do it for you.
Speed up PHP by using an opcode cache
You can improve the performance of your PHP by using a caching method. We’ll use APCu, but there are other alternatives available.
If you have the ‘php-pear’ module installed (we included it in our instructions above), you can install APCu with the following command:
pecl install apcu
There are also other ways you can install APCu, including using a package.
To start using APCu, you should run the following command for PHP 7.2:
echo "extension=apcu.so" | tee -a /etc/php/7.2/mods-available/cache.ini
And the following command for PHP 7.0:
echo "extension=apcu.so" | tee -a /etc/php/7.0/mods-available/cache.ini
If you’re following our LAMP tutorials and you’re using Apache, create a symlink for the file you’ve just created.
For PHP 7.2:
ln -s /etc/php/7.2/mods-available/cache.ini /etc/php/7.2/apache2/conf.d/30-cache.ini
For PHP 7.0:
ln -s /etc/php/7.0/mods-available/cache.ini /etc/php/7.0/apache2/conf.d/30-cache.ini
And finally, reload Apache for the changes to take effect:
systemctl restart apache2
To further configure APCu and how it works, you can add some additional lines to the cache.ini file you previously created. The best configuration depends on what kind of server you’re using, what applications you are using etc. Either google it and find a configuration that works for you, or contact professionals and let them do it for you.
That’s it for our basic setup. Of course, there are much more options and configurations you can do, but we’ll leave them for another tutorial.