Personal Project

Showing posts with label LAMP. Show all posts
Showing posts with label LAMP. Show all posts

Monday, August 15, 2016

Apache Problem due to (24)Too many open files - Solution

After running web services on Apache for few years, my web suddenly could not be accessed because of given an error "HTTP WARNING: HTTP/1.1 403 Forbidden".

When checking the Apache Error log, I found an error message as shown below.

(24)Too many open files: /var/www/html/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable


The solution to this problem is to increase the maximum number of open files and user processes by the following settings.


vim /etc/security/limits.conf 
root soft nofile 32768 
root hard nofile 32768 
root soft nproc 4096  
root hard nproc 4096



Monday, March 7, 2016

How to install LAMP on Ubuntu ?

1. Install Apache



2. Install MySQL



3. Install PHP


Restart Server



Check PHP

You can check your PHP by executing any PHP file in folder /var/www/html












Sunday, February 7, 2016

Install Apache, PHP, and Memcached on CentOS

Install Apache 

# yum install update 

Setup Apache


# vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html">
   AllowOverride all
#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all

</Directory>

Install PHP


# yum install php

# yum install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
curl-d

Check PHP

# vim /var/www/html/info.php
<?php
phpinfo();
?>

// Test Link
http://Server`s IP/info.php

Install Memcached

#yum install memcached

Start Memcached


# chkconfig --level 235 memcached on
# /etc/init.d/memcaached start
# /etc/init.d/memcached sratus

Install Memcached Perl Library

Install perl library for Memcached.
# yum install perl-Cache-Memcached

Install Memcached Python Library

Install python library for Memcached.
# yum install python-memcached

Restart Apache

Restart the Apache service to reflect changes.
# /etc/init.d/httpd restart
OR
# service httpd restart

Check Memcache


# vim /var/www/html/memtest.php

<?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";
$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;
$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";
$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";
var_dump($get_result);
?>

// Test Link
http://Server`s IP/memtest.php


Restrat Apache

# /etc/init.d/httpd restart


Thursday, February 4, 2016

How to optimize Apache, setup Memcached and PHP on Ubuntu ?

Install and setup Apache

// Install Apache2  
sudo apt-get install apache2

// Edit Config
vim /etc/apache2/apache2.conf

<IfModule mpm_prefork_module>
StartServers       10
MinSpareServers    10
MaxSpareServers   10
ServerLimit      256
MaxClients       256
MaxRequestsPerChild 10000
</IfModule>


// check module

apachectl -V | grep -i mpm


// disable event

a2dismod mpm_prefork


// Enable Prefork

a2enmod mpm_prefork

// Restart Apache

service apache restart


Install Memcahced

// Install memcached

sudo apt-get update
sudo apt-get install php5 php5-memcache
sudo apt-get install memcached
sudo apt-get install php-pear
sudo apt-get install build-essential
sudo pecl install memcache

// restart memcached

sudo service memcached restart 

You should add "extension=memcache.so" to php.ini  and restart Apache 
 

// Check Memcache
ps aux | grep memcache 

Install PHP

sudo apt-get install php5 php5-mysql
sudo apt-get install --purge mysql-client mysql-common 

// Remove MYSQL
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean

Solutions to common problems

Problem1:  
The mcrypt extension is missing. Please check your PHP configuration.

Solution:
sudo apt-get install php5-mcrypt
sudo apt-get install mcrypt

Problem2:  
Need CURL PHP extension to connect facebook

Solution:
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

Problem3:
Echo PHP Not Support at HTML

Solution:
vim /etc/php5/apache2/php.ini
short_open_tag = On  
service apache2 stop

service apache2 start

   
chown -R www-data /var/www/html/
chmod -R u+w /var/www/html/