{"id":768,"date":"2009-08-05T21:57:59","date_gmt":"2009-08-06T01:57:59","guid":{"rendered":"http:\/\/mattclare.ca\/wordpress\/?p=768"},"modified":"2009-08-06T23:34:32","modified_gmt":"2009-08-07T03:34:32","slug":"my_server-centos_5_linux_operating_system","status":"publish","type":"post","link":"https:\/\/mattclare.ca\/blog\/2009\/08\/05\/my_server-centos_5_linux_operating_system\/","title":{"rendered":"Building-Up CentOS 5 Linux Operating System"},"content":{"rendered":"<p><a href=\"http:\/\/mattclare.ca\/wordpress\/wp-content\/uploads\/2009\/08\/Picture-3.png\"><img loading=\"lazy\" src=\"http:\/\/mattclare.ca\/wordpress\/wp-content\/uploads\/2009\/08\/Picture-3-300x167.png\" alt=\"HyperVM admin page\" title=\"HyperVM admin page\" width=\"300\" height=\"167\" class=\"alignright size-medium wp-image-778\" srcset=\"https:\/\/mattclare.ca\/blog\/wp-content\/uploads\/2009\/08\/Picture-3-300x167.png 300w, https:\/\/mattclare.ca\/blog\/wp-content\/uploads\/2009\/08\/Picture-3-1024x571.png 1024w, https:\/\/mattclare.ca\/blog\/wp-content\/uploads\/2009\/08\/Picture-3.png 1044w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>When setting up my VPS server there were a number of options for building it.  The VPS admin tool gives you &#8220;virtual&#8221; control over the power switch and the ability to rebuild the server with a fresh OS image at any time.  <a href=\"http:\/\/a2webhosting.com\/\">A2 Web Hosting<\/a> has a few flavours of Linux to choose from: <a href=\"http:\/\/centos.org\/\">CentOS<\/a> (the GPL-based rebuild of Red Hat&#8217;s Enterprise Server 5), <a href=\"http:\/\/www.gentoo.org\/\">Gentoo<\/a> and <a href=\"http:\/\/www.ubuntu.com\/\">Ubuntu<\/a>.  I went with <a href=\"http:\/\/centos.org\/\">CentOS<\/a> as I use it at work, and Enterprise-Grade always seems good to me.<\/p>\n<p>From here on I&#8217;ll assume that you know something about the command line, and that you&#8217;ve got a good <a href=\"http:\/\/en.wikipedia.org\/wiki\/Secure_Shell\">SSH<\/a> client like the OS X Terminal or <a href=\"http:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/\">Putty<\/a> and a way to upload files via an SFTP client like <a href=\"http:\/\/cyberduck.ch\/\">Cyberduck<\/a> or <a href=\"http:\/\/filezilla-project.org\/\">Filezilla<\/a>.<\/p>\n<p>One my first steps with a pristine Linux operating system is to create a folder called &#8220;backup&#8221; and an &#8220;etc_original&#8221; folder in there and copy all of the original etc folder files there for reference.<br \/>\n<code>mkdir \/backup<br \/>\nmkdir \/backup_original<br \/>\ncp -r \/etc\/ \/backup\/etc_original<\/code><\/p>\n<h3>What you&#8217;ll need on your server<\/h3>\n<p>Depending on the install\/image you use you may have everything you need right there, but here are the packages I install out of the gate:<\/p>\n<p>First off I install the screen tool (more about screen at <a href=\"http:\/\/www.cyberciti.biz\/tips\/how-to-use-screen-command-under-linux.html\">http:\/\/www.cyberciti.biz\/tips\/how-to-use-screen-command-under-linux.html<\/a>) so that I can walk away and reconnect to this process, rsync for moving things and backing things up and telnet for testing ports\/servers:<br \/>\n<code>yum install screen rsync telnet<\/code><br \/>\nMake sure Apache&#8217;s installed and that we&#8217;ve got all the PHP modules we need:<br \/>\n<code>yum install httpd php php-cli php-zip php-mysql php-mcrypt php-mbstring<\/code><br \/>\nAlso get some SSL support:<br \/>\n<code>yum install mod_ssl openssl<\/code><br \/>\nInstall MySQL client and server:<br \/>\n<code>yum install mysql mysql-server<\/code><br \/>\nInstall the firewall<br \/>\n<code>yum install iptables<\/code><\/p>\n<p>Once all of those packages are installed you&#8217;ll need to set them up.<\/p>\n<h3>Securing SSH and the rest of the server<\/h3>\n<p>Here&#8217;s a great a guide to securing SSH itself and setting up iptables, so I will deffer to it: <a href=\"http:\/\/wiki.centos.org\/HowTos\/Network\/SecuringSSH\">http:\/\/wiki.centos.org\/HowTos\/Network\/SecuringSSH<\/a><\/p>\n<p>Be sure to allow the appropriate ports you&#8217;ll need later (http 80, https 443, and your current ssh port <small>because you&#8217;d never keep it at 22, right?<\/small>).<\/p>\n<h3>Setting up Apache<\/h3>\n<p>For Apache I like to edit the httpd.conf <code>nano -w \/etc\/httpd\/conf\/httpd.conf<\/code> and turn off the following modules by commenting them out with a #:<br \/>\n<code><br \/>\nLoadModule auth_basic_module modules\/mod_auth_basic.so<br \/>\nLoadModule auth_digest_module modules\/mod_auth_digest.so<br \/>\nLoadModule authn_file_module modules\/mod_authn_file.so<br \/>\nLoadModule authn_alias_module modules\/mod_authn_alias.so<br \/>\nLoadModule authn_anon_module modules\/mod_authn_anon.so<br \/>\n#LoadModule authn_dbm_module modules\/mod_authn_dbm.so<br \/>\nLoadModule authn_default_module modules\/mod_authn_default.so<br \/>\nLoadModule authz_host_module modules\/mod_authz_host.so<br \/>\nLoadModule authz_user_module modules\/mod_authz_user.so<br \/>\nLoadModule authz_owner_module modules\/mod_authz_owner.so<br \/>\n#LoadModule authz_groupfile_module modules\/mod_authz_groupfile.so<br \/>\n#LoadModule authz_dbm_module modules\/mod_authz_dbm.so<br \/>\n#LoadModule authz_default_module modules\/mod_authz_default.so<br \/>\n#LoadModule ldap_module modules\/mod_ldap.so<br \/>\n#LoadModule authnz_ldap_module modules\/mod_authnz_ldap.so<br \/>\n#LoadModule include_module modules\/mod_include.so<br \/>\nLoadModule log_config_module modules\/mod_log_config.so<br \/>\nLoadModule logio_module modules\/mod_logio.so<br \/>\nLoadModule env_module modules\/mod_env.so<br \/>\nLoadModule ext_filter_module modules\/mod_ext_filter.so<br \/>\nLoadModule mime_magic_module modules\/mod_mime_magic.so<br \/>\nLoadModule expires_module modules\/mod_expires.so<br \/>\nLoadModule deflate_module modules\/mod_deflate.so<br \/>\nLoadModule headers_module modules\/mod_headers.so<br \/>\nLoadModule usertrack_module modules\/mod_usertrack.so<br \/>\nLoadModule setenvif_module modules\/mod_setenvif.so<br \/>\nLoadModule env_module modules\/mod_env.so<br \/>\nLoadModule ext_filter_module modules\/mod_ext_filter.so<br \/>\nLoadModule mime_magic_module modules\/mod_mime_magic.so<br \/>\nLoadModule expires_module modules\/mod_expires.so<br \/>\nLoadModule deflate_module modules\/mod_deflate.so<br \/>\nLoadModule headers_module modules\/mod_headers.so<br \/>\nLoadModule usertrack_module modules\/mod_usertrack.so<br \/>\nLoadModule setenvif_module modules\/mod_setenvif.so<br \/>\nLoadModule mime_module modules\/mod_mime.so<br \/>\n#LoadModule dav_module modules\/mod_dav.so<br \/>\n#LoadModule status_module modules\/mod_status.so<br \/>\nLoadModule autoindex_module modules\/mod_autoindex.so<br \/>\n#LoadModule info_module modules\/mod_info.so<br \/>\n#LoadModule dav_fs_module modules\/mod_dav_fs.so<br \/>\nLoadModule vhost_alias_module modules\/mod_vhost_alias.so<br \/>\nLoadModule negotiation_module modules\/mod_negotiation.so<br \/>\nLoadModule dir_module modules\/mod_dir.so<br \/>\nLoadModule actions_module modules\/mod_actions.so<br \/>\nLoadModule speling_module modules\/mod_speling.so<br \/>\nLoadModule userdir_module modules\/mod_userdir.so<br \/>\nLoadModule alias_module modules\/mod_alias.so<br \/>\nLoadModule rewrite_module modules\/mod_rewrite.so<br \/>\n#LoadModule proxy_module modules\/mod_proxy.so<br \/>\n#LoadModule proxy_balancer_module modules\/mod_proxy_balancer.so<br \/>\n#LoadModule proxy_ftp_module modules\/mod_proxy_ftp.so<br \/>\n#LoadModule proxy_http_module modules\/mod_proxy_http.so<br \/>\n#LoadModule proxy_connect_module modules\/mod_proxy_connect.so<br \/>\nLoadModule cache_module modules\/mod_cache.so<br \/>\nLoadModule suexec_module modules\/mod_suexec.so<br \/>\nLoadModule disk_cache_module modules\/mod_disk_cache.so<br \/>\nLoadModule file_cache_module modules\/mod_file_cache.so<br \/>\nLoadModule mem_cache_module modules\/mod_mem_cache.so<br \/>\nLoadModule cgi_module modules\/mod_cgi.so<br \/>\n<\/code><\/p>\n<p>Other than a few tweaks like commenting out the cgi-bin there isn&#8217;t much else I do to the httpd.conf.  You may also need to remove the \/etc\/httpd\/conf.d\/proxy_ajp.conf file.<\/p>\n<p>What I like to do for the rest of my Apache configurations is create a file with a name\/location like &#8220;\/etc\/httpd\/conf.d\/current_server_name.conf&#8221;.  This is where I put the rest of my modifications.  This file will get loaded and applied when Apache starts and is protected from updates etc by being placed in the conf.d folder.<\/p>\n<p>Some examples of configurations I often add are:<br \/>\n<code>DirectoryIndex index.rss index.php index.html<\/p>\n<p># THINGS TO CHANGE WHEN THE SERVER GETS SLOW (switch 'em)<br \/>\n# Buffering logs - Not good for dev, very good for production<br \/>\nBufferedLogs On<br \/>\nHostnameLookups Off<\/code><\/p>\n<p>When you&#8217;re ready start apache:<br \/>\n<code>\/etc\/init.d\/httpd start<\/code><\/p>\n<p>and to make sure it always starts with the server:<br \/>\n<code>\/sbin\/chkconfig --add httpd<\/code><\/p>\n<h3>Turbo Charge PHP<\/h3>\n<p>I&#8217;m a big fan of the <a href=\"http:\/\/pecl.php.net\/package\/APC\">APC<\/a> PHP <a href=\"http:\/\/en.wikipedia.org\/wiki\/PHP_accelerator\">Pre-Compiler\/Accelerator<\/a>.  It works by caching the text-based PHP file&#8217;s compiled opcode and runs that until the original file is modified.  This greatly speeds up the process of PHP files and speeds up larger PHP-based applications with a lot of files, like WordPress.  You can even tell APC to not even check the drive for updates, just served the cached page, until the server is restarted or the cached cleared. I also like the persistent shared memory it can introduce to PHP.<\/p>\n<p>It requires the developer tools to be installed:<br \/>\n<code>install gcc make mlocate autoconf<\/code><\/p>\n<p>Then I&#8217;d recommend install APC based on this guide: <a href=\"http:\/\/2bits.com\/articles\/installing-php-apc-gnulinux-centos-5.html\">http:\/\/2bits.com\/articles\/installing-php-apc-gnulinux-centos-5.html<\/a><\/p>\n<p>For the record, here&#8217;s what my &#8220;\/etc\/php.d\/apc.ini&#8221; file currently looks like.  I&#8217;ve assigned 48mb of ram, and I&#8217;m telling APC not to check the disk for updates, just serve the cached page:<br \/>\n<code>extension=\"apc.so\"<br \/>\napc.enabled = 1<br \/>\napc.shm_size = 48<br \/>\napc.ttl = 7200<br \/>\napc.user_ttl = 7200<br \/>\napc.optimization = 1<br \/>\napc.stat=0<br \/>\n<\/code><\/p>\n<h3>MySQL<\/h3>\n<p>Start MySQL:<br \/>\n<code>\/etc\/init.d\/mysql start<\/code><\/p>\n<p>and to make sure it always starts with the server:<br \/>\n<code>\/sbin\/chkconfig --add mysql<\/code><\/p>\n<p>You&#8217;ll have to set a root password for MySQL:<br \/>\n<code>mysqladmin -u root password yourrootsqlpassword<\/code><\/p>\n<p>and then proceed to add whatever accounts and database you&#8217;d like to add however you&#8217;d like to do that.  In my case I download <a href=\"http:\/\/www.phpmyadmin.net\/home_page\/\">PHPMyAdmin<\/a> and configuring it.  What I also do is add to my own Apache config file some IP restrictions like this (with some example IPs):<\/p>\n<p><code>&lt;Location \"\/phpmyadmin\"&gt;<br \/>\nOrder deny,allow<br \/>\ndeny from ALL<br \/>\nAllow from 127.0.0.1<br \/>\nAllow from 192.168.<br \/>\n#   Force clients from the Internet to use HTTPS<br \/>\n    RewriteEngine on<br \/>\n    RewriteCond %{SERVER_PORT} ^80$<br \/>\n    RewriteRule ^phpmyadmin\/*$ https:\/\/%{SERVER_NAME}%{REQUEST_URI} [R,L]<br \/>\n&lt;\/Location&gt;<\/code><\/p>\n<p>That&#8217;s the really geeky part covered, next I&#8217;ll look at the more interesting element: Setting-up Google Apps including Gmail for the whole system&#8217;s mail.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When setting up my VPS server there were a number of options for building it. The VPS admin tool gives you &#8220;virtual&#8221; control over the power switch and the ability to rebuild the server with a fresh OS image at any time. A2 Web Hosting has a few flavours of Linux to choose from: CentOS&hellip; <a class=\"continue\" href=\"https:\/\/mattclare.ca\/blog\/2009\/08\/05\/my_server-centos_5_linux_operating_system\/\">Continue Reading<span> Building-Up CentOS 5 Linux Operating System<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,38,44,3],"tags":[],"_links":{"self":[{"href":"https:\/\/mattclare.ca\/blog\/wp-json\/wp\/v2\/posts\/768"}],"collection":[{"href":"https:\/\/mattclare.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mattclare.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mattclare.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mattclare.ca\/blog\/wp-json\/wp\/v2\/comments?post=768"}],"version-history":[{"count":32,"href":"https:\/\/mattclare.ca\/blog\/wp-json\/wp\/v2\/posts\/768\/revisions"}],"predecessor-version":[{"id":803,"href":"https:\/\/mattclare.ca\/blog\/wp-json\/wp\/v2\/posts\/768\/revisions\/803"}],"wp:attachment":[{"href":"https:\/\/mattclare.ca\/blog\/wp-json\/wp\/v2\/media?parent=768"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mattclare.ca\/blog\/wp-json\/wp\/v2\/categories?post=768"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mattclare.ca\/blog\/wp-json\/wp\/v2\/tags?post=768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}