2015/04/09

How to redirect non-www URL to www in Apache



If both www and non www domain of your website (http://example.com and http://www.example.com) serve the same website, and you want people going to http://example.com to automatically be redirected to http://www.example.com, there's a few way that you can do so with Apache




.htaccess




First of all, make sure mod_rewrite is installed and enabled for your Apache installation. Once it is, add a file named .htaccess in your website's root directory and add the following lines;
RewriteEngine On
RewriteCond %{HTTP_HOST} ^!example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]


Virtualhost




You can also change your website's Virtualhost setting for the redirect.
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com/
</VirtualHost>

You'll need to restart Apache for this method to work


How to disable directory listing in Apache



If no DirectoryIndex (normally configured as index.html, index.htm, index.php, welcome.html) present in a directory, and if mod_autoindex is enabled (which by default is normally enabled), Apache would list the directory contents, as the following;



While useful for some cases, you would want to disable this feature (perhaps for security reason). There are few ways to do this.




Disable mod_autoindex




The easiest way is probably to disable the autoindex module entirely. This would affect all the sites hosted on the server, which could be both good and bad.

The module is called autoindex, and can be disabled by the a2dismod command, as in the following example.
sudo a2dismod autoindex


Directory's Options directive




The option could be applied per-directory, via the Directory's Option directive as the following.
<Directory /var/www/mysite>
Options -Indexes
</Directory>

Notice that it's -Indexes and not +Indexes

This could be set in your Apache's configuration file.


.htaccess




The above method would also work by adding a .htaccess file with the following content that you want directory listing to be disabled.
Options -Indexes

Changes should take effect when apache is restarted.


How to configure Apache reverse proxy



Apache's reverse proxy is an act of an Apache webserver providing content from other webserver transparently. This is useful in many instances such as caching and mirroring, but it's mostly used to serve websites that are hosted behind NAT or a firewall. A reverse proxy server routes connection addressed to the internal server, and the client sees the reverse proxy server itself as the origin server.


For example, Apache can be configured to serve URL's such as http://www.example.com/webapp to actually get the content from http://192.168.0.10/myapp, which is hosted from an internal network. This happens transparently and the user initially requesting http://www.example.com/webapp need not to be aware of what happens in the background.




Enable proxy modules




Apache require 2 modules enabled for this reverse proxy to work. These modules are proxy and proxy_http. To enable them, run the following command at the terminal.
sudo a2enmod proxy_http

That will enable both proxy and proxy_http, as proxy module is actually a dependency to the proxy_http module. This is confirmed by the output of the above command.
Considering dependency proxy for proxy_http:
Enabling module proxy.
Enabling module proxy_http.

Once the module is enabled, you can start configuring the reverse proxy settings.


Configure reverse proxy




From the previous example, we would like our public facing webserver at http://www.example.com to host our internal site of http://192.168.0.10/myapp to be available as http://www.example.com/webapp

You'll need to add the following lines to your Apache's configuration file.
For Ubuntu, the file could be /etc/apache2/sites-enabled/000-default

ProxyRequests Off

ProxyPass /webapp http://192.168.0.10/myapp
ProxyPassReverse /webapp http://192.168.0.10/myapp


Restart Apache




For the changes to take effect, the Apache webserver need to be re-started. Run the following command at the terminal to do that.
sudo /etc/init.d/apache2 restart


How to change Apache user and group


Apache web server normally runs as the user nobody, www-data or apache. These users usually has limited permission on the system, and doesn't normally has shell login. This is good for security reason, but if for whatever reason you are required to run Apache as different user and group, you have the option to do that.


What you'll need to do is to change the User and Group directive in Apache configuration file. In Ubuntu the main configuration file is /etc/apache2/httpd.conf.


The following configuration will run Apache as the user nobody, and group nobody.



User nobody
Group nobody

You can change that to other user and group available in the system.



This could be a big security risk, especially to those changing the user to root

You will need to restart Apache first for the changes to take effect.



sudo /etc/init.d/apache2 restart

The check if the your changes work, run ps as the following;



ps aux | grep apache

Which should give you output imilar to the following;



root      1188  0.0  0.1 162184  6664 ?        Ss   Mar29   0:02 /usr/sbin/apache2 -k start
nobody 1197 0.0 0.1 162184 5668 ? S Mar29 0:00 /usr/sbin/apache2 -k start
nobody 1198 0.0 0.1 162184 5916 ? S Mar29 0:00 /usr/sbin/apache2 -k start
nobody 1200 0.0 0.1 162184 5684 ? S Mar29 0:00 /usr/sbin/apache2 -k start
nobody 1201 0.0 0.1 162184 5684 ? S Mar29 0:00 /usr/sbin/apache2 -k start
nobody 1202 0.0 0.1 162184 5684 ? S Mar29 0:00 /usr/sbin/apache2 -k start

Notice that Apache runs as the user nobody.



unable to execute dex gc overhead limit exceeded gc overhead limit exceeded


Eclipse will throw GC overhead limit exceeded error when it runs out of memory, normally while performing memory-consuming operations such as building workspace on big projects.


The error would look something like this;




An internal error occurred during: "Building workspace".
GC overhead limit exceeded

To fix this problem, you'll need to allocate more memory to your Eclipse instance. To do this, locate the eclipse.ini file in your Eclipse's installation directory. The content would be something similar to the following;



-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20140116-2212
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.6
-XX:MaxPermSize=256m
-Xms40m
-Xmx512m

To increase the memory allocation for your Eclipse instance, edit the number in the following lines accordingly.



-Xms512m
-Xmx1024m

These options are passed to Java when launching Eclipse. Xms specifies the initial memory allocation pool, and Xmx specifies maximum memory allocation pool for Java Virtual Machine (JVM). The number is the amount of memory, in Megabytes.


You can also increase the value of MaxPermSize, as the following;



-XX:MaxPermSize=1024m

MaxPermSize or Permanent Generation defines the memory allocated to keep compiled class files.


Restart Eclipse for the changes to take effect.



2015/04/06

افتراضي التحول من MySQL الى MariaDB فى اصدارات cPanel الجديدة

السلام عليكم ورحمة الله وبركاته

بعد صدور النسخة النهائية من cPanel 11.48 وبعد سرد مابها من اختلافات وتطويرات
كان من اهمها دعم الشركة MariaDB بدلا من MySQL لقواعد البيانات وهو تحول مهم ومفيد لسيرفراتنا جدا فى الاداء .. وانصح الجميع وبشدة الاستغناء عن MySQL .

شرح اليوم عن استبدال MySQL ب MariaDB من خلال اوامر متعلقة بسكربت cPanel نفسه
قد قمت من قبل بشرح الاستبدال بالفعل فى الاصدارات الماضية وهذه الطريقة مختلفة بعض الشىء

اول شىء وأهم شىء دائما .. ناخد باك اب لاى ملف ومسار ما سنعدل عليه

رمز PHP:

cp -Rf /var/lib/mysql /var/lib/mysql-old
mv /etc/my.cnf /etc/my.cnf-old


نقوم بحذف الباكجات الخاصة ب MySQL

رمز PHP:

/scripts/update_local_rpm_versions --edit target_settings.MySQL55 uninstalled
/scripts/update_local_rpm_versions --edit target_settings.MySQL56 uninstalled



رمز PHP:

/scripts/check_cpanel_rpms --fix --targets=MySQL55,MySQL56


سنضيف الريبو الخاص ب MariaDB من اجل تحميل السيرفر وملحقاته
نفتح الملف بالامر التالى

رمز PHP:

vi /etc/yum.repos.d/MariaDB.repo


ونضع بداخله

رمز PHP:

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5.41/centos6-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1


نفتح ملف

رمز PHP:

vi /etc/yum.conf


نبحث عن السطر الموجود به

رمز PHP:

exclude=


ونقوم بحذف كل من php* و mysql*

الان نقوم بتسطيب السيرفر وملحقاته
ننفذ كل سطر على حده

رمز PHP:

yum install MariaDB-server MariaDB-client MariaDB-devel php-mysql
/etc/init.d/mysql start
mysql_upgrade
/etc/init.d/mysql restart


ثم نقوم بعمل بيلد للاباتشى للاطمئنان بأن كل شىء يعمل بشكل سليم وموديولات PHP تم تحميلها بنجاح .

رمز PHP:

/scripts/easyapache --build


تحياتى للجميع .

2015/04/02

شرح نقل جميع مواقع سيرفر معين الى سيرفر اخر

السلام عليكم ,,

شرح مبسط سريع ,, لاصحاب الاستضافات ,,
لكيفية عمل باكـ اب لجميع مواقع السيرفر ,, ومن ثم نقل ملفات الباك اب الى سيرفر جديد بسهولة

تابع ,,

طبق ,,

وقف الاباتشي عالسيرفر حتى توخد باك ابات حديثة وما تكون رايح منها مشاركات اثناء النقل ,,



رمز Code:

/etc/init.d/httpd restart


طبق التالي لاخذ باك اب لجميع مواقع السيرفر :



رمز Code:

for i in `ls /var/cpanel/users`;do /scripts/pkgacct $i; Done


الان باك ابات جميع مواقع السيرفر موجودة بالمسار : /home بالسيرفر القديم ,,
لنقلها للجديد ,,

افتح السيرفر الجديد ,, وطبق :



رمز Code:

cd /home; scp -r -P PORT *.tar.gz root@LOCALHOST:/home


PORT = بورت الـشل للسيرفر الجديد
LOCALHOST = اي بي السيرفر الجديد .
طبعا باقي الامر واضح ,,

راح يظهر لك تاكيد عند الدخول لاول مرة اكتب yes ومن ثم تابع واكتب باسورد الروت ,, وانتظر لحين تحميل كافة الباك ابات ,, ومبروك عليك النقل ,,

لو اردت استرجاع الباك ابات كاملة على السيرفر الجديد فقط طبق :



رمز Code:

for i in `ls /home/*.tar.gz`;do /scripts/restorepkg --force $i;done


دمتم بود ,,