A quick way to find out if your server is reading your .htaccess files is to type “test” or any text into it. If the .htaccess file is being used – you will get a server error when you reload a page on that site. If you do not get an error – you most likely need to adjust your AllowOveride directive so it does not use “None”.
Finally after two years of contemplating the updates to Apache 2.x, MySQL 5.x, and PHP 5.x, I finally updated my server to the latest version os Apache, MySQL, and PHP. I was not too concerned about custom work or any of my WordPress sites, but I was concerned XOOPS and/or XOOPS modules would have some problems, but it is now a week later and everything is running smoothly. Why finally? Well, as of the end of this month, support for PHP 4 will be discontinued. Better late than never. Time to update your servers too?
After spending a frustrating day yesterday working with a client, their web site overload issues, and the hosting “advanced support” I am worn out. The issue: extremely high traffic database driven web site – when moved into the production environment on a dedicated server – would spike the processors’ load to 100% and would then need to be restarted. I got called to help solve the problem. The “advanced support” blamed it on the CMS and that is where I stepped in. The first thing I wanted to see were the server logs. (Apache and MySQL to start) After a long and frustrating time on the phone with the “advanced support” they were finally convinced I knew what I was talking about and gave me shell access to the server so I could tail (tail -f logname_log) the log in order to see what kind of error messages were generated. Mind you – my client had been dealing with the “advanced support” for two days at this point and not once did they look at the log files. Within a few seconds I was able to see the errors that were causing Apache and MySQL to run out of control and within a short while, I had a solution.
The lesson here – and it seems like I have tried to get this across many times before – if you are experiencing server issues of any kind – DNS, email, web, database – always check the logs first. The log files will either tell you what is wrong right away, or give you something to search for on your search engine of choice. The other lesson of the day: if you are have a content management system that uses a lot of database queries on a very busy site – make sure you you are using some sort of caching. (such as the MySQL Query Cache)
Apache’s mod_rewrite is very powerful. You can prevent hot-linking to your site’s graphics to prevent others from stealing them, redirect your from your old URL to a new URL, re-write URLs, as well as about 500 other really cool things…but today I wanted to share the syntax needed to redirect every incoming URL for a particular web site to a specific page. Why? This could come in handy when doing work on a site and you have a “Performing Updates” (in this case index.html) page. You can put the following code in your .htaccess or httpd.conf file:
# Enable rewrite engine Options +FollowSymLinks RewriteEngine On # Redirect internally all URLs to /index.html RewriteRule .* index.html [L]
After working with Ben for almost eight years he had decided to move on. I wanted to wish Ben all the luck in the world. We had a great time working together for many years…as he put up with my on again off again relationship with Mac OS X Server and I put up with his “not as funny as he thought” videos and comics 😉 We also had a good time playing Carmageddon 2, Diablo, Diablo II and Quake 3 Arena. We did do some great work in between all the games and great music (I got him out of the “ambient” music mode and opened the door to electronica, DJs, etc). We did do a kick ass job of putting together a really sweet Mac OS X/Mac OS X Server server set up using Apache, MySQL, PHP, WebObjects complete with failover. Best of luck and thanks for the good times.
After working with content management managements for well quite awhile now, the thought of creating more than seven (more than five, less than ten) static pages for a client makes me cringe. Why? I am spoiled by using template driven solutions. With templateing, if I need to make a header change, I change it one place and I am done with it. With using static .html pages, I have to make the change to all the pages. I have grown very reliant on using find and replace, but then – because of the person I am – I have to go back and make sure everything looks right.
I am currently wrapping up a project where I was not able to use a content management system, PHP, or any sort of database. No, this is not 1998, this is present day. For decisions I will not get into, this was the situation, no getting around it. This web site has about 75 static pages and around the twentieth page I started to sweat when the client wanted a major layout change. After emailing someone technical in the department I found out they did allow the use of Server Side Includes (SSI) by way of the mod_include module in Apache. My life became much easier after this past weekend as I converted all the pages to be .shtml pages (needed for SSI). By using SSI, I was able to create common files (header, footer, side links, navigation) so any changes to the common elements, and I just need to touch one file instead of all 75 pages.
What you need to use SSI on the server end:
- Apache with mod_include
- Apache configuration must have the proper AddType and AddHandlers set up:
AddType text/html .shtml
AddHandler server-parsed .shtml
- Apache configuration must also have the directive set up for the appropriate directorys ():
What you need to use SSI on the client/page end:
- Name all files you want to have SSI elements in them to include the .shtml extension so Apache knows to parse these files properly
- Use the following syntax when you want to include a file:
when you want to “inlcude” some common code such as a header or footer. (please see the mod_include documentation for all syntax)
Apache’s mod_includes also gives you the ability to include CGI files, show modification dates, date and time, the user name who last modified the file, etc. Lesson learned: if someone approaches you about creating a “simple” static web site, look into if SSI is an option!
[tags]Apache, mod_include, SSI[/tags]
After finally getting some to to set up my development environment, I began thinking…why am I not using Apache 2.2 and PHP 5.1.2? What made me think about this? “Legacy Release” The phrase “legacy release” is what httpd.apache.org described Apache 1.3.x as in their news section. I have been using Apache 1.x for several years now, only ever really thinking about migrating to 2.0 because of the need to run a subversion server. I have a solid web server solution in place that has made me very happy for the last few years using Apache 1.3.x, but it is finally time to check out something in the 2.x family, and I am going to make that 2.2. I am going to spend some time tomorrow reading about any known issues (especially with PHP, as I remember that being a show stopper for my interest in 2.0 before) and then install/configure it. Stay tuned for some tutorials on what I did to get everything up and running!
[tags]apache, php, mysql, subversion[/tags]
I cannot stress how amazing the Apache community has been when I have needed help. Not only do I spend a lot of time reading the great documentation on the Apache web site, I subscribe to the Apache mailing lists, and when I really need help fast, I jump on the #Apache channel using IRC (server=irc.freenode.net). So, if you ever have any questions/problems with Apache, support is only a few minutes away. (I had questions about some mod_rewrite syntax yesterday that I got instant help with yesterday via the IRC channel.) I know I promised a link today to my XOOPS project, but I still need a day or so to figure out the cacheing. I am not someone who likes to release links unless they are pretty polished, and I am not there yet.
Set Up: Mac OS X Client OS, one network card, and multiple Virtual Hosts (three of the Virtual Hosts need SSL certificates) using Apache. Continue reading Multiple IPs, One NIC, Apache, Multiple Virtual Hosts with SSL, Mac OS X
If you find yourself developing more than one web site at home, or anywhere with a *NIX machine with Apache, and want to be able to access all the sites for testing, it is time to set up Virtual Hosts. By using Virtual Hosts, you can access all your web sites easily (especially if you use absolute links) and separately by typing in:
http://other. How does this work? Like I mentioned before, the first step is to set up Virtual Hosts. The second step is to edit your /etc/hosts file so you can assign names to your localhost address (jappler for http://jappler/)
Setting up Virtual Hosts
- To set up virtual hosts, you will need to edit your Apache configuration (
sudo pico /etc/httpd/httpd.conf). You can make a number of changes in the Apache configuration to set up an environment that is right for you, but for now, all you are concerned about is located at the end of the standard config file.
- Uncomment the line:
NameVirtualHost *:80(delete the number sign in front of the line)
- Add in your Virtual Hosts information:
CustomLog /Volumes/www/Sites/jappler.com/logs/access_log common
To break it down line by line:
- ServerAdmin: your email address, not really too important for local testing.
- DocumentRoot: where your site files are located.
- ServerName: This is the name you want to use when to test the web site in your browser (ex. I use jappler for http://jappler/)
*This will also match the name you will add to your /etc/hosts file)
- ErrorLogs: Location of your error logs. You can create separate log files for each hostname, or use one log file for all errors.
- CustomLog: Location of your access logs. You can create separate log files for each hostname, or use one log file for all access information.
Modifying the /etc/hosts file
- You will need to edit the /etc/hosts file (
sudo pico /etc/hosts).
- Your /etc/hosts file will look like:
# Host Database
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
You will need to add in the site names you want, after the 127.0.0.1 localhost line. You can add in as many as you want, but know these will only work on your local machine. More on the /etc/hosts file. Using pico or any other editor, add the hostnames you want to use locally to the /etc/files so it will now look like this (see changes in bold):
*Make sure your hostnames match the names you used in your Apache Virtual Host section
Once you have your Virtual Host information in place, and you have editted your /etc/hosts file, it is time to start up Apache. To start, stop, or restart Apache, you can use
apachectl in the command line. On Mac OS X, this is located:
/usr/sbin/apachectl and in most UNIX/Linux distributions, it is located:
/usr/local/apache/bin/apachectl. To use it, you can type in (on Mac OS X)
sudo /usr/sbin/apachectl stop (to stop Apache). To start Apache type in:
sudo /usr/sbin/apachectl start. If you have any syntax errors, Apache will display them after you type in that command, if not and everything is ok, you will get the message:
/usr/sbin/apachectl start: httpd started.
Now you are all set to serve your web projects on your local machine with unique names for testing purposes! Questions? Just ask.
[tags]Mac OS X, web development, apache, vhosts[/tags]