How to set up a website on CentOS VPS?

Click here for the best cheap VPS.

To set up a website on a VPS, typically you need three software components installed on the VPS: Apache(the http server which listens on port 80 to receive http requests and feeds html to the browsers), mysql(database server which is used by most websites to store data in), php modules(to parse the php files of your website and output html code to the browsers).

Some vpses have Apache software installed and enabled by default. Type the following command to see if Apache is installed and working on your system:

[root@default ~]# service httpd status
httpd (pid 8093) is running…

You can see httpd(the Apache server) is installed and working normally. If you see the following information:

[root@default ~]# service httpd status
httpd is stopped

That means the Apache server is installed but stopped working for some reason. You can put it back to work by typing the following command:

[root@default ~]# service httpd start
Starting httpd: [ OK ]

If Apache server is not installed on the system, you should install it first, by typing the following command:

yum install httpd

Then use “service httpd start” to start the http service.

If everything is ok, you can type http://yourserverip in a browser such as IE to see the Apache test page.

But where is the Apache test page located? The test page is /var/www/error/noindex.html, which is displayed if httpd cannot find the index.html in /var/www/html/ when you type the server’s ip in the browser. You can change the default page by editing /etc/httpd/conf.d/welcome.conf to specify a new test file in the line: “ErrorDocument 403 /error/noindex.html”, although normally you do not need to do so.

You website files are put in the directory: /var/www/html/. Without php modules installed, the httpd can only serve html files. You can check whether the php modules are working properly by putting a php file such as index.php in /var/www/html/ and see if it can be displayed in the browser. If php modules are not installed or configured correctly, the content in the php file will not be parsed and will be served as it is. You can also issue the command “rpm -q php” to see if the php module is installed on the CentOS. If not installed, please install it with “yum install php”. Now restart httpd with “service httpd restart”, and you will see the php file can be displayed correctly in the browser. Besides the core php modules, there are some common php modules that are necessary to be installed to properly handle the function calls in your php files.
yum install php-xml php-gd php-mbstring php-pear php-ldap php-xmlrpc php-snmp php-soap curl curl-devel
Now you can write complex php files for your website.

The next step is to install and configure mysql software.
Type “service mysqld status” to check if mysql has already been installed on your system. If not,use the following command to install the mysql components:

yum install mysql mysql-server

Then use “service mysqld start” to start mysql service.
By default, the mysql server has no password set up for the root user, this is dangerous. You should secure the mysql server using the command “mysql_secure_installation” which also provides you with more options for security considerations.

Now restart httpd and mysqld and everything is ready for you to develop an amazing website which supports php and mysql database operations. Note that after installing and running LAMP(Apache, Mysql, and php), your VPS typically consumes about 200M memory.

Posted in tips of hosting

Leave a Reply