Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

Tuesday, October 17, 2017

How to Install SuiteCRM on CentOS 7



SuiteCRM is a fork of the popular customer relationship management software SugarCRM. It is a free and open source alternative to SugarCRM. It is written in PHP and uses MySQL / MariaDB to store its data.
Requirements
SuiteCRM does not have a minimum hardware requirement, the requirements increases as the users of the application increases. For optimal performance, you should use a server with 1GB RAM. To follow this tutorial, you will need a server with minimal CentOS 7 installed. All the required dependencies will be installed throughout the tutorial. You will also need root access or sudo access on your server. If you are logged in as non root user, run sudo -i to switch to root user.
Installing SuiteCRM
Before installing any package it is recommended that you update the packages and repository using the following command.
yum -y update 
To install SuiteCRM, you will need to install a web server, PHP and database server. In this tutorial, we will be installing the Apache web server with PHP 7.0 and MariaDB as a database server.
To install Apache web server run the following command.
yum -y install httpd 
To start the Apache web server and enable it to start at boot time, run the following command.
systemctl start httpd systemctl enable httpd 
Although SuiteCRM can be installed on earlier versions of PHP, we will be installing it on the latest version of PHP which is PHP 7.0. The default YUM repository contains PHP version 5.4 only, hence we will need to use the Webtatic repository to install a version of PHP greater than 5.5. Run the following commands for installing EPEL repository as EPEL repository is required before we install Webtatic repository.
yum -y install epel-release yum -y update yum clean all
Now install Webtatic repository using the following commands.
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm yum -y update
To install PHP 7.0 and all the required PHP modules, run the following command.
yum -y install php70w php70w-mysql php70w-xml php70w-json php70w-gd php70w-mbstring php70w-zip php70w-imap php70w-pcre php70w-zlib php70w-curl
Once PHP is installed, you will need to configure few thing in php.ini configuration.
Open /etc/php.ini using your favorite editor.
nano /etc/php.ini
If you do not have nano installed, you can install it using
yum -y install nano.
Scroll down to find the following lines.
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 128M
Although 128MB for PHP is enough for SuiteCRM, but you may increase it to higher amounts for faster processing of the application.
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 2M
Change the max upload to at least 20 MB. It should look like as shown below.
upload_max_filesize = 20M
Once done, restart Apache web server using the following command.
systemctl restart httpd
Now install MariaDB database server using the following command.
yum -y install mariadb mariadb-server
Start MariaDB and enable it to start at boot time using the following commands.
systemctl start mariadb systemctl enable mariadb
Now run the following command to secure your MariaDB installation.
mysql_secure_installation
It will run a small script which asks you to provide the root password for MariaDB. As we have just installed MariaDB, the root password is not set, just press enter to proceed further. It will ask you if you want to set a root password for your MariaDB installation, choose y and set a strong password for the installation. It will further ask you for removing test databases and anonymous users. Most of the questions are self-explanatory and you should answer yes to all the questions.
Now you will need to create a database with database user to store SuiteCRM data. To create a database we will need to login to MySQL command line first. Run the following command for same.
mysql -u root –p
This will prompt you for the root password, provide the root password of MySQL which you have set earlier. Now run the following query to create a new database for your SuiteCRM installation.
CREATE DATABASE suitecrmdata;
The above query will create a database named suitecrmdata. For the database, you can use any name you prefer in the place of suitecrmdata.
Make sure that you use semicolon at the end of each query as the query always ends with a semicolon. Once the database is created you can create a new user and grant all the permissions to the user for the database. Using root user is not recommended for the databases. To create a new database user, run the following query.
CREATE USER 'suitecrmuser'@'localhost' IDENTIFIED BY 'StrongPassword';
The above query will create a user with username suitecrmuser. You can use any preferred username instead of suitecrmuser. Replace StrongPassword with a strong password. Now provide the appropriate privileges to your database user over the database you have created. Run the following command:;
GRANT ALL PRIVILEGES ON suitecrmdata.* TO 'suitecrmuser'@'localhost';
Now run the following command to immediately apply the changes on the database privileges.
FLUSH PRIVILEGES;
Exit MySQL prompt by executing exit command.
Once done, you can download the SuiteCRM using the following command.
cd /opt wget https://suitecrm.com/files/152/SuiteCRM%207.7/105/SuiteCRM-7.7.8.zip
At the time of writing the tutorial, the latest version of SuiteCRM is 7.7.8. You can always check for the latest version on SuiteCRM download page.
Extract the files using the following command.
unzip SuiteCRM-7.7.8.zip
If you do not have unzip installed, you can run yum -y install unzip.
The above command will extract the files in SuiteCRM-7.7.8 directory. Move all the files to the web root directory of Apache web server using the following command.
mv SuiteCRM-7.7.8/* /var/www/html cd /var/www/html
Provide the ownership of the files to the Apache web server user by running the following command.
chown -R apache:apache /var/www/html
Adjust SELinux permissions using the following commands.
chcon -R -t httpd_sys_content_rw_t /var/www/html setsebool httpd_can_network_connect_db=on setsebool httpd_can_network_connect=on setsebool httpd_can_sendmail=on setsebool httpd_unified=on
Now you can go to your favorite browser and browse the following link.
http://serverIPaddress Or http://yourdomain.comYou will see following interface.
Accept the license agreement and Choose a language for installation. Click Next to go further. Installer will now check for the system requirements. If you have followed this tutorial, you should see that all the requirements are met.
Click Next to proceed further. In next interface, you will be required to provide the database credentials and Admin user credentials.
Provide the database name which we have created earlier, provide the hostname
localhost and the username and password of the database user.
In administration user, provide the admin username password. Choose a URL for your SuiteCRM instance and your email address.
In More Options, you can choose to import the demo data provided by the installer. It can help you evaluate the product. For a production installation, you may not want to import anything. Choose accordingly.
In Scenario Selection, you can choose that which modules should be activated in the application. You can also modify this setting in administration settings once it's installed.
In SMTP Server Specification, you can specify the SMTP server by which SuiteCRM will send emails. You can use the settings for email providers like Gmail, Yahoo Mail or you can also choose to provide SMTP server for other application as well. Provide the hostname for your SMTP server and choose a port on which SMTP is running on the mail server. Select SMTP authentication checkbox and provide your email address and password for your mail account. Select if you want to use SMTP over SSL or TLS. Select Allow users to use this account for outgoing email: if you want your users to use the email to send the emails from their account.
In Branding option you can provide the name of your organization and its logo. Name of your organization will appear on the title bar and the logo will appear in the place of SuiteCRM logo.
In System Locale settings you can choose the data and time format for your application. Choose a time zone for your application and also provide which currency you wish to use with your CRM application. These settings will be considered as the default settings, but users can modify this according to their need.
In Site Security option you can specify a custom directory for your Sessions and Logs. Click Next to proceed further. It will now generate the configuration file and will place it on the system. It will also write the data on the database.
Once the installation finishes, you will be automatically taken to the login screen.
Log in using the administrator credentials provided during installation and you will see SuiteCRM dashboard as shown below.
SuiteCRM installation is now finished.
To automatically run SuiteCRM scheduler, you will need to add a cron job in your system. Run the following command to open your crontab file.
crontab –e
Add the following line at in the file.
    *    *    *    *    *     cd /var/www/html; php -f cron.php > /dev/null 2>&1
Save and exit from editor.
Conclusion
In this tutorial, we have learned to install SuiteCRM application on CentOS 7 server. You can now deploy the application to increase the productivity of your organization.


Wednesday, October 16, 2013

13 Apache Web Server Security and Hardening Tips

Apache Security Tips

We all are very familiar with Apache web server, it is a very popular web server to host your web files or your website on the web. Here are some links which can help you to configure Apache web server on your Linux box.

Here in this tutorial, I’ll cover some main tips to secure your web server. Before you apply these changes in your web server, you should have some basics of the Apache server.

  1. Document root Directory: /var/www/html or /var/www
  2. Main Configuration file: /etc/httpd/conf/httpd.conf (RHEL/CentOS/Fedora) and /etc/apache/apache2.conf (Debian/Ubuntu).
  3. Default HTTP Port: 80 TCP
  4. Default HTTPS Port: 443 TCP
  5. Test your Configuration file settings and syntax: httpd -t
  6. Access Log files of Web Server: /var/log/httpd/access_log
  7. Error Log files of Web Server: /var/log/httpd/error_log
1. How to hide Apache Version and OS Identity from Errors

When you install Apache with source or any other package installers like yum, it displays the version of your Apache web server installed on your server with the Operating system name of your server in Errors. It also shows the information about Apache modules installed in your server.

Show Apache Version

Show Apache Version

In above picture, you can see that Apache is showing its version with the OS installed in your server. This can be a major security threat to your web server as well as your Linux box too. To prevent Apache to not to display these information to the world, we need to make some changes in Apache main configuration file.

Open configuration file with vim editor and search for “ServerSignature“, its by default On. We need to Off these server signature and the second line “ServerTokens Prod” tells Apache to return only Apache as product in the server response header on the every page request, It suppress the OS, major and minor version info.

# vim /etc/httpd/conf/httpd.conf (RHEL/CentOS/Fedora)
# vim /etc/apache/apache2.conf (Debian/Ubuntu)




ServerSignature Off
ServerTokens Prod




# service httpd restart (RHEL/CentOS/Fedora)
# service apache2 restart (Debian/Ubuntu)



Hide Apache Version





Hide Apache Version



2. Disable Directory Listing


By default Apache list all the content of Document root directory in the absence of index file. Please see the image below.



Apache Directory ListingApache Directory Listing



We can turn off directory listing by using Options directive in configuration file for a specific directory. For that we need to make an entry in httpd.conf or apache2.conf file.




<Directory /var/www/html>
Options -Indexes
</Directory>



Hide Apache Directory ListingHide Apache Directory Listing



3. Keep updating Apache Regularly


Apache developer community is continuously working on security issues and releasing its updated version with new security options. So It is always recommended to use the latest version of Apache as your web server.



To check Apache version: You can check your current version with httpd -v command.




# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Aug 13 2013 17:29:28



You can update your version with the following command.




# yum update httpd
# apt-get update apache2



It is also recommended to keep your Kernel and OS updated to the latest stable releases if you are not running any specific application which works only on specific OS or Kernel.



4. Disable Unnecessary Modules


It’s always good to minor the chances of being a victim of any web attack. So it’s recommended to disable all those modules that are not in use currently. You can list all the compiled modules of web server, using following command.




# grep LoadModule /etc/httpd/conf/httpd.conf

# have to place corresponding `LoadModule' lines at this location so the
# LoadModule foo_module modules/mod_foo.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
....



Above is the list of modules that are enabled by default but often not needed: mod_imap, mod_include, mod_info, mod_userdir, mod_autoindex. To disable the particular module, you can insert a “#” at the beginning of that line and restart the service.



5. Run Apache as separate User and Group


With a default installation Apache runs its process with user nobody or daemon. For security reasons it is recommended to run Apache in its own non-privileged account. For example: http-web.



Create Apache User and Group



# groupadd http-web
# useradd -d /var/www/ -g http-web -s /bin/nologin http-web



Now you need to tell Apache to run with this new user and to do so, we need to make an entry in /etc/httpd/conf/httpd.conf and restart the service.



Open /etc/httpd/conf/httpd.conf with vim editor and search for keyword “User” and “Group” and there you will need to specify the username and groupname to use.




User http-web
Group http-web



6. Use Allow and Deny to Restrict access to Directories


We can restrict access to directories with “Allow” and “Deny” options in httpd.conf file. Here in this example, we’ll be securing root directory, for that by setting the following in the httpd.conf file.




<Directory />
Options None
Order deny,allow
Deny from all
</Directory>





  1. Options “None” – This option will not allow users to enable any optional features.




  2. Order deny, allow – This is the order in which the “Deny” and “Allow” directives will be processed. Here it will “deny” first and “allow” next.




  3. Deny from all – This will deny request from everybody to the root directory, nobody will be able to access root directory.




7. Use mod_security and mod_evasive Modules to Secure Apache


These two modules “mod_security” and “mod_evasive” are very popular modules of Apache in terms of security.



Mod_security


Where mod_security works as a firewall for our web applications and allows us to monitor traffic on a real time basis. It also helps us to protect our websites or web server from brute force attacks. You can simply install mod_security on your server with the help of your default package installers.



Install mod_security on Ubuntu/Debian



$ sudo apt-get install libapache2-mod-security
$ sudo a2enmod mod-security
$ sudo /etc/init.d/apache2 force-reload



Install mod_security on RHEL/CentOS/Fedora/



# yum install mod_security
# /etc/init.d/httpd restart



Mod_evasive


mod_evasive works very efficiently, it takes one request to process and processes it very well. It prevents DDOS attacks from doing as much damage. This feature of mod_evasive enables it to handle the HTTP brute force and Dos or DDos attack. This module detects attacks with three methods.




  1. If so many requests come to a same page in a few times per second.


  2. If any child process trying to make more than 50 concurrent requests.


  3. If any IP still trying to make new requests when its temporarily blacklisted.



mod_evasive can be installed directly from the source. Here, we have an Installation and setup guide of these modules which will help you to set up these Apache modules in your Linux box.



Protect Apache using Mod_Security and Mod_evasive



8. Disable Apache’s following of Symbolic Links


By default Apache follows symlinks, we can turn off this feature with FollowSymLinks with Options directive. And to do so we need to make the following entry in main configuration file.




Options -FollowSymLinks



And, if any particular user or website need FollowSymLinks enable, we can simply write a rule in “.htaccess” file from that website.




# Enable symbolic links
Options +FollowSymLinks



Note: To enable rewrite rules inside “.htaccess” file “AllowOverride All” should be present in the main configuration globally.



9. Turn off Server Side Includes and CGI Execution


We can turn off server side includes (mod_include) and CGI execution if not needed and to do so we need to modify main configuration file.




Options -Includes
Options -ExecCGI



We can do this for a particular directory too with Directory tag. Here In this example, we are turning off Includes and Cgi file executions for “/var/www/html/web1” directory.




<Directory "/var/www/html/web1">
Options -Includes -ExecCGI
</Directory>



Here are some other values with can be turned On or off with Options directive.





  1. Options All – To enable All options at once. This is the default value, If you don’t want specify any values explicitly in Apache conf file or .htaccess.




  2. Options IncludesNOEXEC – This option allows server side includes without the execute permission to a command or cgi files.




  3. Options MultiViews – Allows content negotiated multiviews with mod_negotiation module.




  4. Options SymLinksIfOwnerMatch – It’s similar to FollowSymLinks. But, this will follow only when the owner is the same between the link and the original directory to which it is linked.




10. Limit Request Size


By default Apache has no limit on the total size of the HTTP request i.e. unlimited and when you allow large requests on a web server its possible that you could be a victim of Denial of service attacks. We can Limit the requests size of an Apache directive “LimitRequestBody” with the directory tag.



You can set the value in bytes from 0 (unlimited) to 2147483647 (2GB) that are allowed in a request body. You can set this limit according to your site needs, Suppose you have a site where you allows uploads and you want to limit the upload size for a particular directory.



Here in this example, user_uploads is a directory which contains files uploaded by users. We are putting a limit of 500K for this.




<Directory "/var/www/myweb1/user_uploads">
LimitRequestBody 512000
</Directory>



11. Protect DDOS attacks and Hardening


Well, it’s true that you cannot completely protect your web site from DDos attacks. Here are some directives which can help you to have a control on it.





  1. TimeOut : This directive allows you to set the amount of time the server will wait for certain events to complete before it fails. Its default value is 300 secs. It’s good to keep this value low on those sites which are subject to DDOS attacks. This value totally depends on kind of request you are getting on your website. Note: It could pose problems with come CGI scripts.




  2. MaxClients : This directive allows you to set the limit on connections that will be served simultaneously. Every new connection will be queued up after this limit. It is available with Prefork and Worker both MPM. The default value of it is 256.




  3. KeepAliveTimeout : Its the amount of time the server will wait for a subsequent request before closing the connection. Default value is 5 secs.




  4. LimitRequestFields : It helps us to set a limit on the number of HTTP request’s header fields that will be accepted from the clients. Its default value is 100. It is recommended to lower this value if DDos attacks are occurring as a result of so many http request headers.




  5. LimitRequestFieldSize : It helps us to set a size limit on the HTTP Request header.




12. Enable Apache Logging


Apache allows you to logging independently of your OS logging. It is wise to enable Apache logging, because it provides more information, such as the commands entered by users that have interacted with your Web server.



To do so you need to include the mod_log_config module. There are three main logging-related directives available with Apache.





  1. TransferLog: Creating a log file.




  2. LogFormat : Specifying a custom format.




  3. CustomLog : Creating and formatting a log file.




You can also use them for a particular website it you are doing Virtual hosting and for that you need to specify it in the virtual host section. For example, here is the my website virtual host configuration with logging enabled.




<VirtualHost *:80>
DocumentRoot /var/www/html/example.com/
ServerName www.example.com
DirectoryIndex index.htm index.html index.php
ServerAlias example.com
ErrorDocument 404 /story.php
ErrorLog /var/log/httpd/example.com_error_log
CustomLog /var/log/httpd/example.com_access_log combined
</VirtualHost>



13. Securing Apache with SSL Certificates


Last, but not the least SSL certificates, you can secure your all the communication in an encrypted manner over the Internet with SSL certificate. Suppose you have a website in which people login by proving their Login credentials or you have an E- Commerce website where people provides their bank details or Debit/Credit card details to purchase products, by default your web server send these details in plain – text format but when you use SSL certificates to your websites, Apache sends all this information in encrypted text.



You can purchase SSl certificates from So many different SSL providers like namecheap.com. If you are running a very small web business and do not willing to purchase an SSL certificate you can still assign a Self signed certificate to your website. Apache uses the mod_ssl module to support SSL certificate.




# openssl genrsa -des3 -out example.com.key 1024
# openssl req -new -key example.com.key -out exmaple.csr
# openssl x509 -req -days 365 -in example.com.com.csr -signkey example.com.com.key -out example.com.com.crt



Once your certificate has been created and signed. Now you need to add this in Apache configuration. Open main configuration file with vim editor and add the following lines and restart the service.




<VirtualHost 172.16.25.125:443>
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/example.com.crt
SSLCertificateKeyFile /etc/pki/tls/certs/example.com.key
SSLCertificateChainFile /etc/pki/tls/certs/sf_bundle.crt
ServerAdmin ravi.saive@example.com
ServerName example.com
DocumentRoot /var/www/html/example/
ErrorLog /var/log/httpd/example.com-error_log
CustomLog /var/log/httpd/example.com-access_log common
</VirtualHost>



Open up your browser, type https://example.com, and you will be able to see the new self-signed certificate.



These are few security tips that you can use to secure your Apache web server installation. For more useful security tips and ideas, see the official online documentation of Apache HTTP Server.





Link gốc: 13 Apache Web Server Security and Hardening Tips

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Powerade Coupons