How to Increase PHP File Upload Size Limit

Q. When you try to update the blog post in WordPress or any php application, you might notice that the application such as WordPress has a prohibitive maximum PHP file upload size. How to increase this limit in PHP ? In the below screenshot, i configured my PHP upload size to 50MB.

PHP file upload

A. If you own the virtual private server of dedicated web server, it is very easy to increase this parameter or option. The options can be set in php.ini configuration file, this configuration apply to all your applications. Many shared hosting server allows a maximum PHP file upload size is very low. This method may not work for most shared hosting because you do not give root access. If you plan to receive larger files, you should consider to purchase virtual private server (VPS) or dedicated server hardware.

What is default PHP File Upload Size (upload_max_filesize)?

The default values for PHP will restrict you to a maximum 2 MB upload file size.

Note : Below require you to access the server using root access from the linux server console. The steps has been tested on PHP 5.3 and PHP 5.4.

a) Login to your server via ssh connection.

b) Open php.ini file using vi editor :

# vi /etc/php.ini

There are two PHP configuration options that control the maximum PHP file upload size which are “upload_max_filesize” and “post_max_size”.

By default post_max_size = 8M and upload_max_filesize = 2M. You can update this value to the following :

c) Update this value from 8M to 60M :

post_max_size = 60M

d) Update this value from 2M to 50M :

upload_max_filesize = 50M

Note : Technically, post_max_size should always be greater than upload_max_file size . But for such a large number 150M you can safely make them the same size.

e) After you have made a changes, Then restart your web server to take effect of new PHP file upload size (e.g Apache or Nginx).

You can read more on these posts which explains PHP file upload article.

How to Install and Setup Apache Tomcat 8 on CentOS 7 / RHEL 7

What is Tomcat Server and What is Apache Tomcat used for ?

Apache Tomcat version 8 is an open source web server and servlet container developed by the Apache Software Foundation (ASF).

It provides a web server environment for Java based source code and used to deploy Java Servlets and JSPs.

Basically Apache is an HTTP Server, serving HTTP. Tomcat is a Servlet and JSP Server serving Java technologies.

Tomcat 8 is the first Apache Tomcat release to support the Servlet 3.1, JSP 2.3, EL 2.3, and WebSocket specifications.

This article will describes how to install and configure Tomcat 8 on CentOS 7, RHEL 7 and Oracle Linux 7.

1. Install Oracle java :

2. How to download Apache Tomcat 8 :

To download Apache tomcat 8, go to the apache tomcat mirror

# cd /opt
# wget http://apache.arvixe.com/tomcat/tomcat-8/v8.0.22/bin/apache-tomcat-8.0.22.tar.gz

3. Extract the downloaded files :

# tar xzvf apache-tomcat-8.0.22.tar.gz

4. Create tomcat8 group and add user tomcat8 to that group:

# groupadd tomcat8
# useradd -s /bin/bash -g tomcat8 tomcat8

5. Create a symbolic link of tomcat directory to /opt/tomcat and assign permission :

# ln -s /opt/apache-tomcat-8.0.22 /opt/tomcat
# chown -R tomcat8:tomcat8 /opt/tomcat /opt/apache-tomcat-8.0.22

6. Create a Systemd Setting file :

# vi /usr/lib/systemd/system/tomcat8.service

Add the following :

[Unit]
Description=Apache Tomcat 8
After=network.target

[Service]
Type=oneshot
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
RemainAfterExit=yes
User=tomcat8
Group=tomcat8

[Install]
WantedBy=multi-user.target

7. How to start tomcat server and make it auto start at boot :

# systemctl start tomcat8
# systemctl enable tomcat8

8. Tomcat server works on port 8080 default. You can access from your browser using the url :

http://serverURL:8080

setup-tomcat-centos7-1

9. There are changes on the user roles on Tomcat 8. By default, no users or passwords are created for the Tomcat manager roles. To set roles, user name(s) and password(s), we need to configure the tomcat-users.xml file located at $CATALINA_HOME/conf/tomcat-users.xml.

# vi /opt/tomcat/conf/tomcat-users.xml

Add the following :

<!-- user manager can access only manager section -->
<role rolename="manager-gui"></role>
<user username="manager" password="password" roles="manager-gui"></user>

<!-- user admin can access manager and admin section both -->
<role rolename="admin-gui"></role>
<user username="admin" password="password" roles="manager-gui,admin-gui"></user>

Read here on the different between Apache Web Server and Apache Tomcat server.

How to Install LAMP on CentOS 7 / RHEL 7

LAMP stack is a group of open source software that installed together to let you run a web server to host dynamic websites. “L” stand for Linux, “A” stand for Apache (to host Web server), “M” stand for MySQL(to store database) but in RHEL 7, MariaDB will in place of MySQL by default. “P” stand for PHP(to process dynamic content). This brief tutorial will explain how to install LAMP on CentOS 7 / RHEL 7 / Oracle Linux 7.

How to Install LAMP on CentOS 7 / RHEL 7 / Oracle Linux 7

The LAMP stack is just short reference for Linux, Apache, MySQL/MariaDB and PHP :

L = Linux
A = Apache
M = MariaDB /MySQL
P = PHP

If you’re a newbie, these steps can help to install web server and database server on linux operating system. It is very simple to install install LAMP on CentOS 7 / RHEL 7 / Oracle Linux 7. You just need to follow these steps one by one.

1. Install Apache web server, Mariadb database and PHP packages :

When come to the question, how to install web server i ? The answer is very easy,

[root@centos7 ~]# sudo yum install mariadb mariadb-server httpd php php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap -y

2. Start Apache web server and Mariadb database. Make it auto start at boot :

[root@centos7 ~]# sudo systemctl start httpd.service
[root@centos7 ~]# sudo systemctl enable httpd.service
[root@centos7 ~]# sudo systemctl start mariadb
[root@centos7 ~]# sudo systemctl enable mariadb.service

3. Settings for MariaDB.

[root@centos7 ~]# sudo mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

4. Browse to your server ip http://IPaddress.

Install LAMP on CentOS 7
Follow the instruction in welcome.conf before proceed to configure the virtual host :

[root@centos7 ~]# vi /etc/httpd/conf.d/welcome.conf

Install LAMP on CentOS 7

5. Configure Apache Virtual host :

a. Create DocumentRoot directory for new domain :

[root@centos7 ~]# mkdir -p /var/www/html/ehowstuff

b. Create vhost.conf to place Name-based virtual host. For example, the default domain is centos7.ehowstuff.local and you wish to add the new virtual host www.ehowstuff.local, which points at the same IP address.

[root@centos7 ~]# vi /etc/httpd/conf.d/vhost.conf

Add the following. Please note that “NameVirtualHost *:80” no longer valid in Apache 2.4.x :

#Create new default domain
<VirtualHost *:80>
   DocumentRoot /var/www/html
   ServerName centos7.ehowstuff.local
</VirtualHost>
# for virtual domain
<VirtualHost *:80>
   DocumentRoot /var/www/html/ehowstuff
   ServerName www.ehowstuff.local
   ServerAdmin webmaster@ehowstuff.local
   ErrorLog logs/www.ehowstuff.local-error_log
   CustomLog logs/www.ehowstuff.local-access_log combined
</VirtualHost>

6. To debug apache configuration :

[root@centos7 ~]# httpd -S
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server centos7.ehowstuff.local (/etc/httpd/conf.d/vhost.conf:2)
         port 80 namevhost centos7.ehowstuff.local (/etc/httpd/conf.d/vhost.conf:2)
         port 80 namevhost centos7.ehowstuff.local (/etc/httpd/conf.d/vhost.conf:2)
         port 80 namevhost www.ehowstuff.local (/etc/httpd/conf.d/vhost.conf:7)
         port 80 namevhost www.ehowstuff.local (/etc/httpd/conf.d/vhost.conf:7)
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex default: dir="/run/httpd/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
PidFile: "/run/httpd/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48

7. To get more information about apache :

[root@centos7 ~]# httpd -V
Server version: Apache/2.4.6 (CentOS)
Server built:   Jan 12 2015 13:22:31
Server's Module Magic Number: 20120211:23
Server loaded:  APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="/run/httpd/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

8. Check php version :

[root@centos7 ~]# php -v
PHP 5.4.16 (cli) (built: Oct 31 2014 12:59:36)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

Install LAMP on CentOS 7

I hope this article gives you some ideas and essential guidance on how to install LAMP on CentOS 7 / RHEL 7 / Oracle Linux 7.

 

How to Hide Apache Information on Ubuntu VPS/Dedicated Web server

By default the sensitive server information such as of Apache version, modules, operating System was not hide from the HTTP Header. This information will be display when there is a request to it. Attackers can use those information when they performing attacks to your VPS webserver. This post will show you how to hide apache details on Ubuntu 14.04 VPS or dedicated server.

1. Modify security.conf :

ehowstuff@ubuntu14:~$ sudo vi /etc/apache2/conf-enabled/security.conf

Change “ServerTokens OS” to “ServerTokens Prod” then
Change “ServerSignature On” to “ServerSignature Off”

..
..
ServerTokens Prod
..
..

..
ServerSignature Off
..
..

2. After done the changes, restart the apache2 :

ehowstuff@ubuntu14:~$ sudo service apache2 restart
 * Restarting web server apache2                                                             [ OK ]

3. Perform the following command before change and after change the configuration :

ehowstuff@ubuntu14:~$ sudo curl -I http://192.168.0.114

The result should be as below :

Before :

HTTP/1.1 200 OK
Date: Sun, 11 May 2014 01:25:52 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Thu, 08 May 2014 16:39:14 GMT
ETag: "2cf6-4f8e61f1300ba"
Accept-Ranges: bytes
Content-Length: 11510
Vary: Accept-Encoding
Content-Type: text/html

After hide should be like this :

HTTP/1.1 200 OK
Date: Sun, 11 May 2014 01:29:50 GMT
Server: Apache
Last-Modified: Thu, 08 May 2014 16:39:14 GMT
ETag: "2cf6-4f8e61f1300ba"
Accept-Ranges: bytes
Content-Length: 11510
Vary: Accept-Encoding
Content-Type: text/html

Done!!

How to Fix _default_ VirtualHost overlap on port 80, the first has precedence

Question :
I running wordpress blog on apache web server on Virtual private server (VPS). I had the problem when i restarted the httpd service on my VPS. This error came after i setup multiple domain on my httpd config file, meaning i used more than one VirtualHost on httpd.conf :

[root@vps ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: [Thu May 01 00:01:03 2014] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
                                                           [  OK  ]

Solution :

After a few hours troubleshooting and googling to internet, i managed to fix the issue. When we decide to run multiple domain in one web server or web hosting world called it shared hosting service, you need to configure name-based virtual hosts on your apache httpd service. NameVirtualhost is require to be included in httpd.conf file as below :

..
..
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#
..
..

Then restart the apache httpd. Issue resolved!

How to Install Varnish Cache With Apache On CentOS 6.5

Varnish is an open source web accelerator (also called a HTTP reverse proxy) designed for content-heavy dynamic web sites to speed up web server’s performance. Typical Web server will handles all the request and returning a response to the client. But with Varnish cache, it will serve the saved copy page instead of re-requesting the same revisited page from web server. This will reduced the server load and increased the response times. For those who plan to run a virtual private server (VPS) and also run a dedicated web server, hope that this article will help. This article will describe how to install and configure Varnish Cache with Apache on CentOS 6.5.

1. Setup varnish repo :

[root@centos6 ~]# wget http://repo.varnish-cache.org/redhat/varnish-3.0/el6/noarch/varnish-release/varnish-release-3.0-1.el6.noarch.rpm
[root@centos6 ~]# rpm --nosignature -i varnish-release-3.0-1.el6.noarch.rpm

2. Install Varnish and Apache :

[root@centos6 ~]# yum install varnish -y
[root@centos6 ~]# yum install httpd -y

3. Make both program start at boot :

[root@centos6 ~]# chkconfig --level 345 varnish on
[root@centos6 ~]# chkconfig --level 345 httpd on

4. Configure apache to listen to port 8080 :

[root@centos6 ~]# vi /etc/httpd/conf/httpd.conf

Modify below :

Listen 8080

5. Configuring Varnish Cache :

[root@centos6 ~]# vim /etc/sysconfig/varnish
..
..
# # Main configuration file. You probably want to change it :)
VARNISH_VCL_CONF=/etc/varnish/default.vcl
#
# # Default address and port to bind to
# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=
#VARNISH_LISTEN_PORT=6081
VARNISH_LISTEN_PORT=80
#
# # Telnet admin interface listen address and port
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
VARNISH_ADMIN_LISTEN_PORT=6082
#
# # Shared secret file for admin interface
VARNISH_SECRET_FILE=/etc/varnish/secret
#
# # The minimum number of worker threads to start
VARNISH_MIN_THREADS=50
#
# # The Maximum number of worker threads to start
VARNISH_MAX_THREADS=1000
#
# # Idle timeout for worker threads
VARNISH_THREAD_TIMEOUT=120
#
# # Cache file location
VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin
#
# # Cache file size: in bytes, optionally using k / M / G / T suffix,
# # or in percentage of available disk space using the % suffix.
VARNISH_STORAGE_SIZE=1G
#
# # Backend storage specification
VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
#
# # Default TTL used when the backend does not specify one
VARNISH_TTL=120
#
# # DAEMON_OPTS is used by the init script.  If you add or remove options, make
# # sure you update this section, too.
DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
             -f ${VARNISH_VCL_CONF} \
             -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
             -t ${VARNISH_TTL} \
             -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \
             -u varnish -g varnish \
             -S ${VARNISH_SECRET_FILE} \
             -s ${VARNISH_STORAGE}"
#
..
..

Add the following in /etc/varnish/default.vcl :

[root@centos6 ~]# vim /etc/varnish/default.vcl
backend default {
  .host = "127.0.0.1";
  .port = "8080";
}

6. Start Varnish and Apache ”

[root@centos6 ~]# service varnish start
Starting Varnish Cache:                                    [  OK  ]
[root@centos6 ~]# service httpd start
Starting httpd:                                            [  OK  ]

7. verify varnish and Apache running on the correct port :

[root@centos6 ~]# netstat -plunt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1042/rpcbind
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      21729/varnishd
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1075/sshd
tcp        0      0 127.0.0.1:6082              0.0.0.0:*                   LISTEN      21728/varnishd
tcp        0      0 :::111                      :::*                        LISTEN      1042/rpcbind
tcp        0      0 :::80                       :::*                        LISTEN      21729/varnishd
tcp        0      0 :::8080                     :::*                        LISTEN      1182/httpd
tcp        0      0 :::22                       :::*                        LISTEN      1075/sshd
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               1042/rpcbind
udp        0      0 0.0.0.0:793                 0.0.0.0:*                               1042/rpcbind
udp        0      0 :::111                      :::*                                    1042/rpcbind
udp        0      0 :::793                      :::*                                    1042/rpcbind

8. Verify the Varnish by running the following command.

[root@centos6 ~]# curl -I http://www.ehowstuff.local
HTTP/1.1 200 OK
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
X-Pingback: http://www.ehowstuff.local/xmlrpc.php
Content-Type: text/html; charset=UTF-8
Content-Length: 7990
Accept-Ranges: bytes
Date: Sun, 13 Apr 2014 15:41:41 GMT
X-Varnish: 1889373153
Age: 0
Via: 1.1 varnish
Connection: keep-alive

9. ApacheBench performance test without Varnish Cache

[root@centos6 ~]# ab -k -n 1000 -c 50 http://www.ehowstuff.local:8080/
This is ApacheBench, Version 2.3 < $Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.ehowstuff.local (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.2.15
Server Hostname:        www.ehowstuff.local
Server Port:            8080

Document Path:          /
Document Length:        0 bytes

Concurrency Level:      50
Time taken for tests:   217.545 seconds
Complete requests:      1000
Failed requests:        81
   (Connect: 0, Receive: 0, Length: 81, Exceptions: 0)
Write errors:           0
Non-2xx responses:      1000
Keep-Alive requests:    0
Total transferred:      318518 bytes
HTML transferred:       20331 bytes
Requests per second:    4.60 [#/sec] (mean)
Time per request:       10877.237 [ms] (mean)
Time per request:       217.545 [ms] (mean, across all concurrent requests)
Transfer rate:          1.43 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3  12.1      0      65
Processing:   219 10822 17202.8   3275   61139
Waiting:      218 10802 17210.6   3228   61138
Total:        239 10825 17201.5   3275   61139

Percentage of the requests served within a certain time (ms)
  50%   3275
  66%   4513
  75%   5570
  80%  12099
  90%  40539
  95%  60069
  98%  60103
  99%  60200
 100%  61139 (longest request)

10. ApacheBench performance test with Varnish Cache

[root@centos6 ~]# ab -k -n 1000 -c 50 http://www.ehowstuff.local/
This is ApacheBench, Version 2.3 < $Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.ehowstuff.local (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.2.15
Server Hostname:        www.ehowstuff.local
Server Port:            80

Document Path:          /
Document Length:        7990 bytes

Concurrency Level:      50
Time taken for tests:   0.227 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    1000
Total transferred:      8565396 bytes
HTML transferred:       8221710 bytes
Requests per second:    4410.08 [#/sec] (mean)
Time per request:       11.338 [ms] (mean)
Time per request:       0.227 [ms] (mean, across all concurrent requests)
Transfer rate:          36888.79 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   3.2      0      19
Processing:     7   10   1.7     10      18
Waiting:        1    4   2.3      4      15
Total:          7   11   4.1     10      31

Percentage of the requests served within a certain time (ms)
  50%     10
  66%     10
  75%     11
  80%     11
  90%     12
  95%     13
  98%     27
  99%     31
 100%     31 (longest request)

11. Result on Steps (9) and (10) shows that Apache with Varnish serve faster response than running Apache standalone.

 

How to Install WordPress on Remote MySQL

WordPress is an open source content management system (CMS) and popular blogging platform in the world based on PHP and MySQL platform. WordPress can be install on multiple way, either using dedicated server, virtual private server(VPS) or the cheapest way is running on shared hosting. When come to decision to run the wordpress on dedicated server or on VPS, the next question would be whether to run a web service and database service on single or multiple server. We have an option to combine it or to split it. For high performance wordpress website, i would suggest you to run web server(Apache, NGINX, Lighttpd) and database server (MySQL) on different server. Below steps should provide the basic steps how you can setup the wordpress on remote MySQL.

server1 = 192.168.0.5 = Apache server
server2 = 192.168.0.6 = Remote MySQL server

1. Login as a root on server1 then download latest wordpress file and extract the file :

[root@server1 html]# cd /var/www/html
[root@server1 html]# wget http://wordpress.org/latest.tar.gz
[root@server1 html]# tar xzvf latest.tar.gz

2. Login to server2, create the database for the wordpress :

[root@server2 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database wordpressdb;
Query OK, 1 row affected (0.00 sec)

mysql> create user 'wordpressuser'@'192.168.0.5' identified by 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on wordpressdb.* to 'wordpressuser'@'192.168.0.5';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> show grants for 'wordpressuser'@'192.168.0.5';
+------------------------------------------------------------------------------------------------------------------------+
| Grants for wordpressuser@192.168.0.5                                                                                   |
+------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wordpressuser'@'192.168.0.5' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' |
| GRANT ALL PRIVILEGES ON `wordpressdb`.* TO 'wordpressuser'@'192.168.0.5'                                               |
+------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

3. Once step 2 above has been done, login again to server1, test the connectivity to database server :

[root@server1 html]# mysql -u wordpressuser -p -h 192.168.0.6
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
| worpressdb         |
+--------------------+
3 rows in set (0.00 sec)

4. Still on server1, copy the config.php file :

[root@server1 ~]# cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php

5. Modify the config.php file and enter the database informations and remote mysql server details :

[root@server1 ~]# vi /var/www/html/wordpress/wp-config.php
define('DB_NAME', 'wordpressdb');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');

/** MySQL hostname */
define('DB_HOST', '192.168.0.6');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

6. To install, navigate the browser to http://servername/wordpress/.

http://192.168.0.5/wordpress/

Install MySQL, Apache and PHP on CentOS 6.5

LAMP stand for Linux, Apache, MySQL and PHP which is group of software used to run an web applications. The combination of these software is called LAMP stack. This document will walk you through the steps to install MySQL, Apache and PHP on CentOS 6.5.


What is Apache ?

Apache httpd is one of the most popular web servers and has a lot of features that make it very extensible and useful for many different types of websites.

What is MySQL?
MySQL Database server is one of the most popular used database in the internet especially for content management and blogging site.

What is PHP?
PHP is a widely-used and open-source server-side scripting language that was especially designed for web development to produce dynamic web pages and can be embedded into HTML.

Steps :
1. Install MySQL, Apache and PHP :

[root@centos6-05 ~]# yum install mysql mysql-server httpd php* -y

2. Start Apache and MySQL :

[root@centos6-05 ~]# service httpd start
[root@centos6-05 ~]# service mysqld start

3. Check Apache, MySQL and PHP version :
Apache

[root@centos6-05 ~]# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built:   Aug 13 2013 17:29:28

MySQL

[root@centos6-05 ~]# mysql -V
mysql  Ver 14.14 Distrib 5.1.71, for redhat-linux-gnu (x86_64) using readline 5.1

PHP

[root@centos6-05 ~]# php -v
PHP 5.3.3 (cli) (built: Dec 11 2013 03:29:57)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

4. Verifying Apache, MySQL and PHP :

Create a page called phpinfo.php under web root directory /var/www/html.

[root@centos6-05 ~]# vi /var/www/html/index.php
<?php

     phpinfo ();
?>

Restart Apache :

[root@centos6-05 ~]# service httpd restart

php-info

Securing and Hardening Linux Dedicated Server

securing linuxWhen we hosted the linux dedicated server or virtual private server(VPS) in a data center, security of the system is very important in order to ensure the data and the information are safe from the hackers. Securing and hardening linux dedicated server is mandatory when nearly every computing resources and the application systems is online and susceptible to attack. This post share basic security and hardening tips for the linux dedicated server. If you are plan to host your own linux dedicated server, then this post should able to provide you a good baseline and ideas. The following are the best practices to securing and hardening linux dedicated server :

1. Patching Linux Systems
2. Keep Linux Kernel and Software such as WordPress/Joomla Up to Date
3. Secure SSH
4. Enforcing Stronger Passwords and Password Aging
5. Disable Unnecessary Processes, Services and Daemons
6. Install a host based firewall to protect your dedicated server from unauthorized access
7. Implement Linux Kernel /etc/sysctl.conf hardening
8. Configure Logging and Auditing
9. Install And Use Intrusion Detection System

How to Setup Apache httpd on CentOS Dedicated Server

apachehttpdThe Apache HTTP Server is a free or open source Web server developed by the Apache Software Foundation (http://www.apache.org/). This post describes the basic steps to setup Apache httpd on CentOS 6.4 64 bit dedicated server to host the website and blog. Having dedicated web server, you will get more control and flexibility on the configuration and you does not share its resources with anyone else. With at least 2GB RAM, you will get fairly consistent load times and better speed if compared to shared hosting and virtual private server (VPS). Bloggers or webmasters can get reasonable dedicated server price starting at $139 at very reputable companies such as hostgator.

1. How to Install httpd :

[root@centos64 ~]# yum install httpd -y

2. How to Check Apache server version :

[root@centos64 ~]# httpd -V
Server version: Apache/2.2.15 (Unix)
Server built:   Feb 22 2013 11:19:58
Server's Module Magic Number: 20051115:25
Server loaded:  APR 1.3.9, APR-Util 1.3.9
Compiled using: APR 1.3.9, APR-Util 1.3.9
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

3. Change /etc/hosts file :

[root@centos64 ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.2.62 centos64.ehowstuff.local

4. Always backup the original configuration file before doing any changes :

[root@centos64 ~]# cp -p /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backup.01042013

Note : -p mean preserve the specified attributes (default: mode,ownership,timestamps)

5. How to Configure httpd Apache service :

[root@centos64 ~]# vi /etc/httpd/conf/httpd.conf
ServerTokens Prod
KeepAlive On
ServerAdmin root@ehowstuff.local
ServerName www.ehowstuff.local:80
Options Indexes FollowSymLinks ExecCGI
AllowOverride All
DirectoryIndex index.html index.cgi index.php
ServerSignature Off
#AddDefaultCharset UTF-8
AddHandler cgi-script .cgi .pl

6. Restart Apache httpd :

[root@centos64 ~]# /sbin/service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

7. How to configure Apache httpd auto start at boot :

[root@centos64 ~]# chkconfig httpd on

8. How to check the apache access log :

[root@centos64 ~]# tail -f /var/log/httpd/access_log
192.168.2.52 - - [01/Apr/2013:23:14:35 +0800] "GET /index.php?=PHPE9568F34-D428-11d2-A769-00AA001ACF42 HTTP/1.1" 200 2524 "http://192.168.2.62/" "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"
192.168.2.52 - - [01/Apr/2013:23:14:35 +0800] "GET /index.php?=PHPE9568F35-D428-11d2-A769-00AA001ACF42 HTTP/1.1" 200 2146 "http://192.168.2.62/" "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"
192.168.2.52 - - [01/Apr/2013:23:14:35 +0800] "GET / HTTP/1.1" 200 71412 "-" "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"
192.168.2.52 - - [01/Apr/2013:23:14:36 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"
192.168.2.52 - - [01/Apr/2013:23:14:36 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"

9 Steps to Setup Dedicated Server for your Website

dedicated serverThere are different types of hosting services are used in the computer technology such as shared hosting, VPS (Virtual Private Server) and Dedicated Server hosting. For new websites with low numbers of visitors, I would highly recommend getting a shared hosting. If you need more control of the server, then you should moving from shared hosting to a VPS. There are plenty of hosting companies offering Virtual Private Servers, and VPS hosting is getting cheaper. This blog hosted at RamNode VPS.

At some point, your site will get super slow server performance impact on limited resources when running VPS hosting. More server resources required is due to the increased number of visitors to the tens of thousands or hundreds of thousands per day.

At the situation when you are hitting super slow website performance due to huge numbers of traffic, I would recommend you to getting dedicated servers. Cheaper way is to setup VPS additional to balance the load. If cost is not an issue, I always recommend you to purchase a dedicated server as this will give you excellent processing performance. In a dedicated server environment , resources such as memory , hard drive storage capacity, processing power, and network access are all 100% to dedicated servers instead of shared with multiple VPS or dozens of shared hosting customers. Popular websites on the Internet certainly have excellent servers behind them. Without such an excellent server, web sites with high concurrency of visitors will not be able to survive.

If you are an experienced system administrator, the following articles may not attract you, but for web developers and those new to the web hosting, the following article can be a useful guide on their first steps. I believe the popular website on the internet has been setup by a consultant who specializes in servers or installed by an experienced system administrator. In this article, I would like to share 9 steps to setup Dedicated Server for your Website.

Once you have purchased a dedicated server, you can log in to your server to complete the setup of your server from start to finish. Below is a guide and checklist for you who are new to server administration.

9 Steps to Setup Dedicated Server

1. Choose and Install Linux operating system :

Choosing the right platform on which to host your dedicated server. Please make sure that you are familiar with the preferred operating system (OS) either CentOS or Fedora or Ubuntu or maybe Windows OS. If you choose linux OS, I would recommend you to do a clean minimal installed of the OS.

2. Update operating system :

Make sure that the OS has been applied the latest patches.
How to Update CentOS 6.4 System using ‘yum update’

3. Install Apache or Nginx Web server :

Apache httpd is one of the most popular web servers and has a lot of features that make it very extensible and useful for many different types of websites. As an alternative to Apache http server, you also can install NGINX. Nginx or “engine x” is a free, open-source HTTP server that provide high-performance edge web server with the lowest memory footprint and the key features to build modern and efficient web infrastructure. I used Nginx to run this blog.

How to Setup Nginx With PHP-FastCGI on CentOS 6.2/CentOS 6.3 VPS Server

4. Install MySQL Database server :

MySQL server is a database server that can stores and retrieves data for the blog, websites and applications. It is one of the most popular most used in the internet especially for content management and blogging site.

5. Install PHP :

PHP: Hypertext Preprocessor is a widely used, free and open-source server-side scripting language that was especially designed for web development to produce dynamic web pages and can be embedded into HTML.

6. Install Bind DNS server :

BIND (the Berkeley Internet Name Domain) also known as NAMED is the most widely used DNS server in the internet. Bind DNS helps to resolve domain name to ip address and ip address to domain name.

7. Install FTP server :

File Transfer Protocol (FTP) is a network protocol used transfer file in the network. one of the most popular FTP server for Unix/Linux is vsftpd. Vsftpd stand for Very Secure FTP Daemon. Vsftpd not only just another popular FTP server for Unix/Linux systems, but vsftpd delivers excellent performance by consuming less memory.

8. Harden and Secure the dedicated server :

There are a few steps to harden the OS of dedicated server.
a) Install a host based firewall to protect your dedicated server from unauthorized access:
Once you have your web server running, you have to install host based firewall and open only certain port in your firewall. I would recommend you tosetting up iptables on your linux dedicated server.

b) Use Strong passwords :
Password complexity requirements should be in place to enforce strong password. A strong password should have mixed case, special characters, numbers, and be longer than 8 characters. Additional security, the passwords should be changed regularly.

c) Disable Unnecessary Processes, Services and Daemons :
I would recommend you to disable unneeded processes,services and daemon such as bluetooth, hidd, cups, yum-updatesd, ypbind, nfs, snmpd, saslauthd, netfs, gpm, pcmcia and sendmail. SELinux also should be set to “Disabled”. This is still very experimental so I would leave this disabled unless you really know what you are doing.

9. Install or migrate over the content of your website or blog :

You can start to migrate over the content of your website or blog to your new dedicated server. For dynamic content blog, i would recommend you to use WordPress as a platform. WordPress is an open-source blogging platform. It’s a free blogging tool and content management system (CMS) based on PHP and MySQL.

I hope that this 9 steps to setup dedicated server can be a useful guide on your first steps to have your own dedicated server to run a websites.