Sadržaj
sudo apt-get install libmemcached-dev libmemcached11
memcache sudo apt-get -y install gcc make autoconf libc-dev pkg-config sudo apt-get -y install zlib1g-dev sudo apt-get -y install libmemcached-dev sudo pecl7.X-sp install memcached When you are shown the prompt
libmemcached directory [no] : type or paste the following text exactly as shown and press Enter.
no --disable-memcached-sasl That is, the entire line you'll see on your screen will be as follows once you press Enter.
libmemcached directory [no] : no --disable-memcached-sasl Once installed, create a configuration file for the extension and restart PHP by running the following commands as root
sudo bash -c "echo extension=memcached.so > /etc/php7.X-sp/conf.d/memcached.ini" sudo service php7.X-fpm-sp restart Installing Memcached on PHP 5.4, 5.5, and 5.6 To install this extension, SSH in to your server as root and run the following commands:
sudo apt-get -y install gcc make autoconf libc-dev pkg-config sudo apt-get -y install zlib1g-dev sudo apt-get -y install libmemcached-dev sudo pecl5.X-sp install memcached-2.2.0 When you are shown the prompt
libmemcached directory [no] : type or paste the following text exactly as shown and press Enter.
no --disable-memcached-sasl That is, the entire line you'll see on your screen will be as follows once you press Enter.
libmemcached directory [no] : no --disable-memcached-sasl Once installed, create a configuration file for the extension and restart PHP by running the following commands as root
sudo bash -c "echo extension=memcached.so > /etc/php5.X-sp/conf.d/memcached.ini" sudo service php5.X-fpm-sp restart Verifying the Installation You can verify the memcached extension is installed correctly by running this command:
phpX.Y-sp -i | grep -i "memcached support" You should see output like the following:
memcached support => enabled Uninstalling the Memcached Extension To uninstall this extension, as root run the commands:
sudo rm /etc/phpX.Y-sp/conf.d/memcached.ini sudo peclX.Y-sp uninstall memcached Next, restart PHP-FPM with the command:
sudo service phpX.Y-fpm-sp restart Memcache Two different extensions are available that provide access to Memcached from within your PHP scripts. One is named memcache and the other is named memcached. This extension (the one named memcache with no d on the end) is no longer maintained. For instructions on the memcached extension (with a d on the end), see the section above. To install this extension, SSH in to your server as root and run the following command:
sudo apt-get install gcc make autoconf libc-dev pkg-config sudo apt-get install zlib1g-dev sudo pecl5.X-sp install memcache Once installed, create a configuration file for the extension and restart PHP.
sudo bash -c "echo extension=memcache.so > /etc/php5.X-sp/conf.d/memcache.ini" sudo service php5.X-fpm-sp restart
sudo apt-get install -y php libapache2-mod-php Next, install php-memcached extension. This module provides clients(e.g. PHP code) with access to the Memcached server.
$ sudo apt-get install -y php-memcached Restart Apache for the changes to be effected.
$ sudo systemctl restart apache2 With PHP and Memcached extension installed, you can move on to installing the Memcached server
Step 3: Installing and Configuring Memcached Server Since Memcached package is available on the default Ubuntu software repository, you will use apt to install it. You will also install libmemcached-tools . This is a set of lightweight library and tools used by the Memcached server.
To install Memcached, run the command below:
$ sudo apt-get install -y memcached libmemcached-tools Once installed, you can edit Memcached settings by modifying the /etc/memcached.conf file using nano text editor
$ sudo nano /etc/memcached.conf Let's go over some of the configuration settings used by Memcached
-d : This option allows Memcached to run as a daemon
logfile: Memcached logs errors and its activities in this file.
-m : The value after -m specifies the maximum memory that can be held by the Memcached server although Memcached will not hold the total memory when initially started, The default value is 64 MB. You can change the cache size depending on the available RAM on your Alibaba Cloud ECS instance.
-p : Memcached will listen on the port specified with this option. The default value is 11211.
-u : This option specifies the user under which Memcached will run under. The default value is memcache
-i : This specifies the IP address that Memcached server will listen on. The default value on Ubuntu 18.04 server is localhost set with the IP address 127.0.0.1
-c : This option can be used to limit the number of simultaneous connections to the Memcached server. The default value is 1024.
If you make any changes to the file, you should restart Memcached server using the command below:
$ sudo systemctl restart memcached Then, restart Apache web server
$ sudo systemctl restart apache2 Memcached server should now be working as expected. In the next step, you will write a simple PHP script to check if PHP can indeed support the Memcached server.
Step 4: Checking Memcached Support Once you have installed and configured Memcached, the next step is to verify if your Apache web server and PHP can recognize it.
To do this, create an info.php file in the root of your website.
$ sudo nano /var/www/html/info.php Then, paste the content below in the file