×
Community Blog How to Install PHP on Ubuntu

How to Install PHP on Ubuntu

In this article, you will get some information on the installation of php for different tools on Ubuntu.

How to Install Craft CMS with a LEMP Stack

There are many PHP based Content Management Systems (CMS) that you can run on an Alibaba Cloud ECS Instance with a LEMP stack. Of these, Craft CMS is probably one of the slickest.

As Craft is built using the Yii high performance PHP framework, and adheres to modern PHP standards, it is also a very scalable and stable platform.

In this tutorial, you will get some information on the installation of Craft CMS on a LEMP Stack on Alibaba Cloud.

The final part of the LEMP stack we need to run Craft CMS is PHP. Although Craft will run on PHP5.3 and upwards, it is not advisable to use old and unsupported versions. PHP7 is much more secure and provides incredibly superior performance.

As Nginx doesn't natively process dynamic content, such as PHP scripts, we will need to install PHP-FPM. This will install all the core PHP packages we need to run with an NGINX server. Let's also install the PHP extension for MySQL at the same time:

# apt-get install php-fpm php-mysql

Craft CMS requires a few other PHP packages that aren't included in PHP-FPM, so we need to install them separately:

# apt-get install php7.0-curl php7.0-mbstring php7.0-mcrypt php-imagick php7.0-xml

How to Install Redis Object Caching on WordPress

Caching allows us to store data in RAM so that any future request for that data can be served faster, without any needing to query the database or process any PHP. In this tutorial, we will install a Redis server as an object cache for DB queries, and configure WordPress to use it.

In this tutorial, you can get some information on the installation of a Redis object cache plugin on WordPress.

Enable cache settings in wp-config.php

Next we need to edit our WordPress 'wp-config.php' file to add a cache key salt with the name of your site, and define 'WP_CACHE' as true to create a persistent cache with the WordPress Redis Object cache plugin we will install later:

Open your 'wp-config.php' file for editing:

sudo nano /var/www/html/wp-config.php
Immediately after the WordPress unique Keys and Salts section, add the following with your site's url:

define( 'WP_CACHE_KEY_SALT', 'an-example-domain.com' );
define( 'WP_CACHE', true );

Installation of LibreNMS on Ubuntu

In this tutorial, we will install and configure LibreNMS on Ubuntu 16.04 with an Alibaba Cloud Elastic Compute Service (ECS) instance.

LibreNMS runs on the web server, written in PHP and uses MariaDB for database. So you will need to install Apache, PHP and MariaDB to your system.

First, install Apache and MariaDB by running the following command:

apt-get install apache2 mariadb-server -y

Once the installation is completed, start Apache and MariaDB service and enable them to start on boot:

systemctl start apache2
systemctl start mysql
systemctl enable apache2
systemctl enable mysql

By default, the latest version of PHP is not available in Ubuntu 16.04 default repository. So you will need to add the repository for that. You can add it by running the following command:

apt-get install software-properties-common -y
add-apt-repository ppa:ondrej/php

Next, update the repository and install PHP along with all the libraries by running the following command:

apt-get install libapache2-mod-php7.1 php7.1-cli php7.1-mysql php7.1-gd php7.1-snmp php-pear php7.1-curl snmp graphviz php7.1-mcrypt php7.1-json fping imagemagick whois mtr-tiny nmap python-mysqldb snmpd php-net-ipv4 php-net-ipv6 rrdtool git -y

Once all the packages are installed, enable required PHP modules with the following command:

phpenmod mcrypt
a2enmod php7.1
a2dismod mpm_event
a2enmod mpm_prefork

Next, you will also set Time Zone in php.ini file:

nano /etc/php/7.1/cli/php.ini

Make the following changes:

date.time = Asia/Kolkata

Related Blog Posts

WordPress: Performance Benchmarking & Installing Redis Object Caching

Caching allows us to store data in RAM so that data can be served faster, without any needing to query the database or process any PHP.

Whilst this is a great start, what will happen if your website suddenly starts to receive lots of concurrent visitors? While the stack we have installed is performant, how can we improve it, to ensure that no matter how popular our site becomes our server won't choke?

The answer to our problem is caching. Caching allows us to store data in RAM so that any future request for that data can be served faster, without any needing to query the database or process any PHP.

Related Market Products

Postgres Pro Standard Database 10 (Ubuntu 16.04)

Postgres Pro Standard Database provides early access to new PostgreSQL features and optimizations.

Related Documentation

Improve ApsaraDB for Memcache performance through PHP persistent connections

Some PHP users experienced that the performance of ApsaraDB for Memcache fails to meet the expected indexes through tests. We followed up on the situation and found that most users go through the Apache web service to connect to ApsaraDB for Memcache through PHP, using short connections. The overhead of every short connection not only includes socket reconnection, but also complicated re-authentication procedures, being much larger than that of a general request. This impacts the website efficiency greatly.

PHP client usage

When you perform the add operation on an existing key (not expired), var_dump(add) prints true (this inversion parameter is incorrect) if the get operation has been performed before add. We recommend to determine whether the add operation was successful or not by verifying if the value of getResultCode is 0. If get is not performed before add, the var_dump(add) inversion parameter is correct.

Related Products

ApsaraDB for Memcache

ApsaraDB for Memcache is a managed memory based caching service, which supports high-speed access to queries and data. ApsaraDB for Memcache improves the response of dynamic websites or applications by relieving the load on the backend database as cache data is stored in-memory.

ApsaraDB RDS for PostgreSQL

Known as "The world’s most advanced open source database", PostgreSQL enables OLTP databases that handle enterprise-level SQL statements, supports NoSQL data types such as JSON, XML and hstore, and supports GIS data processing.

Related Course

Introduction to HybridDB for PostgreSQL

This course starts from the comparison between OLTP and OLAP business types and then have a introduction to Greenplum database, which is quite widely used analytic type database in the world. Then there will be introduction about the features and operations of HybridDB for PostgreSQL, which is a database service based on Greenplum.

0 0 0
Share on

Alibaba Clouder

1,439 posts | 227 followers

You may also like

Comments