Azure website + mysql - php

I am starting my Azure Project. I did a website to Run Wordpress. Migrating from a previous host entity.
I use mysql, the ClearDb azure has is very limited and expensive $75 p month just because i need views and triggers ( only available on the dedicated server plan) its SAD. I Then created my MySql in Amazon RDS.
I did some latency tests, and the fact that Mysql being Closer to the Website region helps alot to reduce latency.
But still, my wordpress navigation seems slow! The first time is terrible, around 4 seconds. The next ones a bit better but nothing compared to my previous host of around 200ms!
Is this because of mysql being accessed by remote and not being in the same "data center" ? or is this because another thing like the "hot and cold" websites concept of Azure!? ( because even secondary calls are slow)...
I am starting to realize Azure is not Good for Websites with PHP + MYSQL.
I like the look and feel of Azure UI and Website concept but this is Very disappointing from azure not having a self MYSQL Structure.

Latency is a problem. Before assume that Azure is good or not, try a new thing. Create an azure virtual machine and install mysql in there. Then, edit your connection string to point to your VM. Also, install a plugin cache because wordpress execute a lot of queries in your database.
Another option: did you try the Scalable WordPress available through Azure Marketplace?
http://azure.microsoft.com/en-us/marketplace/partners/wordpress/scalablewordpress/

#Miguel, I agree with Thiago.
I think you can install MYSQL database on VM and connect it with your Wordpress website.
In this scenarios, I suggest you can use some tool to find the items which takes more times, such as webpagetest . It is useful for further steps.
At the same time, you can try to optimize your database,compress Images and so on. I recommend you can refer to this blog about how to improve the WP site performances.
By the way, Azure will unload your site if it is idle for the standard 20 minute timeout, which can cause slow responses for the initial site users after it is unloaded. You could enable the "always on" feature if you think it is necessary.

Did you try using persistent connections from your WordPress site to MySQL database. That can decrease latency times by decreasing time to create a connection and instead reuse existing connections.

The MySQL latency is an issue and there is probably not much we can do about it since the DB call has to be made further than to the localhost - simple as that.
1) If you need Azure for your MySQL driven eapp, use Microsoft's VM which is running quite reliably and where you can install PHP/MySQL on the same machine - speedy but relatively pricey. So far the only production acceptable solution for MySQL I found.
2) Don't use Azure if you need fast MySQL connections. We have tons of MS apps running in azure with various versions of MSSQL - and they all running relatively fine. So far I did not find fast solution for MySQL. Therefore, I am still using Linode for the PHP/MySQL apps. Their speed and service is superb (I am not getting anything from Linode for this recommendation :) and it is quite inexpensive in comparison to Azure in this case.

Related

How to set up a website with a PostgreSQL database?

I'm doing a group project and we're creating an online game. We're about half way done and now it's time to implement a database to store our records/data and make the website go live on the internet.
I'm just confused on how PSQL works exactly. My understanding is that PSQL needs to be running on some server in order to access it. For previous assignments, I downloaded Postgres for my Mac and ran it on localhost. The PHP code was something along the lines of:
$dbconn = pg_connect("host=localhost port=5432 dbname=mydbname");
So, if we intend to use PSQL, where would the server be? Do one of us have to host the server? Can we use some sort of free online server? How do we connect to that server with PHP?
In summary, I have two main questions:
How do we make our code go live on the internet for free? (It's just a temporary website and will only be up for a few weeks at most)
How can we all access a shared PSQL database?
Sorry for the noob questions, I just got started with web development and am still learning.
So, if we intend to use PSQL, where would the server be? Do one of us have to host the server? Can we use some sort of free online server? How do we connect to that server with PHP?
PostGreSQL is going to have to run on some machine visible to anyone who needs to access it. If only your web server (i.e., the machine running PHP and your website) needs to talk to the PGSQL, then PGSQL can be installed on your web server. This is a very common configuration.
The server might also run on the LAN where your web server is running or it might be running on an entirely different network on a different continent. The most important thing is that any machine which must connect directly to the database can actually connect to it. If you're building a website, this means you have a web server. Your web server will need to connect to the PGSQL server. The second most important thing is that your web server and the PGSQL server should share a very fast connection for the sake of performance and efficiency.
It's probably most common for your web server to also host the database. On an ubuntu machine, installing a PostGreSQL server is as easy as running a few commands. A quick search yields many examples like this one.
How do we make our code go live on the internet for free? (It's just a temporary website and will only be up for a few weeks at most)
I don't know anyone who is in the habit of offering free web hosting or DBMS services. You could ask a friend. Or put an ad on craigslist or something. Or if you are tech-savvy (it doesn't sound like you are) then you could configure a high-end router at your home to use Dynamic DNS to point some domain at a machine running at your house.
How can we all access a shared PSQL database?
I have no experience with Heroku, but you might sniff around there. PostGreSQL's website also maintains a list of hosting companies. Amazon offers RDS instances running PGSQL. Digital Ocean has a variety of tutorials and how-tos on dealing with PostGres. You could probably fire up a 'droplet' server for super cheap and install it yourself without too much effort.
Amazon offer a free tier database solution for Postgres. Something like 300 hours (don't quote me on it) for a low level set up.
They have tutorials on doing this here:
https://aws.amazon.com/rds/?nc2=h_m1
Once set up you get the end point and your connection string becomes something like
db_connect ("host=[URLENDPOING] user=postgres dbname=postres")

Joomla on Azure Web App - performance issues

I'm trying to get Joomla running on Azure Web Apps but the performance is terrible. 3-5 second response time no matter what operation I'm doing.
Tried the Bitnami VM and it runs much much smoother, so the problem is obviously in the web app. Have tried both Cleardb and the internal mysql preview db and both give the same laggy result. It doesn't matter what sized machines I run on, they all lag.
The only thing I haven't tried is upgrading the Cleardb database from the free tier to the paid ones, simply because my subscription doesn't allow it. Since I see the same performance issue with the internal mysql db this should not matter.
My guess is that this is an issue with PHP and IIS. Anyone with similar experience, and possibly a solution?

phpMyAdmin Hosted in Azure problems

I created my phpMyadmin in Windows Azure which only allows 1 MySQL database for free users.
After creating a phpMyAdmin I linked MySQL Database Resources to another Website.
In this website I try to login my accounts registered to the database.
At first it goes smooth and seems there is no problem, but as i try to continue accessing the website which retrieves details from the linked MySQL Database Resources, The website returns and error of..
User 'b48a56f527c793' has exceeded the 'max_user_connections' resource (current value: 4)
But after a while 3-5mins the connection is good again.
At first I think the Windows Azure just tries to limit traffic but is it really that real cause of the problem or did i made mistake in setting up my phpMyAdmin in Windows Azure?
How to fix that error?
Big thanks in advance!
When you use MySQL on Azure you have to know is it provided by ClearDB, and the free tier is very limited. You can check the limitations here. For example you only have 4 concurrent connections limit, which is quite restrictive.
As a suggestion - never use mysql_pconnect in your scripts, but always use mysql_connect and always kill your connection when you don't need it anymore (i.e. when you retrieve the data).
I'm not 100% sure, but I think default installation of phpMyAdmin uses mysql_pconnect, which might keep idle connections as a resource from these 4 you have.
If you are using ClearDb on Azure which is the default option, ClearDb has really tight limit for simultaneous connections. Check it here:
https://www.cleardb.com/store/azure

Comprehensive guide to setting up a data driven website using Amazon web services for EC2

I have started making a website and was hosting on Hostgator but I am going to move it to Amazon web services before launch. There is a small problem that I previously just uploaded my files to the relevant location to Hostgator and it has all just worked. I have no experience in setting up from scratch a production worthy server setup and I need to know how. I did setup the basic lamp stack on the EC2 instance, however, I keep reading that when the EC2 instance does down it will take all the data with it and I can not have that happen. I have also read then when it dies it wont do anything and you have to start up the apache server again it is not automatic. I need it to be reliable and have the data independent so it will not crash, burn and die if the server goes. I have worked out that I will need S3 for static things such as my PDF's and images as well as using the RDS for my MYSQL database. My domain name is registered elsewhere so I believe I need to use route 53 as well.I want to use AWS for a few reasons reasons, firstly as it can scale which is really important but not sure if this is built in or it requires customization. I have been told that it is very secure the EC2 and the last reason is that I can debug my php code. The debug reason is that I have an error that only appears on the Hostgator server not my local lamp stack and I can't debug it there so I should be able to when I move to EC2.
I have done a lot of looking around online and I can't find anything comprehensive about what to setup. I have been reading (some of you may think otherwise). However, I am so overwhelmed by the amount of information there is as it is either far to complicated discussing some theory that I do not care about or to easy and does not discuss how to use anything other then a generic install of a LAMP stack on the EC2 with out using the other services.
I have seen http://bitnami.com/stack/lamp/cloud/amazon but do not think this is what I want as again the EC2 has a mysql database and I am not using the RDS
If someone can point me in the direction of a comprehensive guide to setting up a slid LAMP stack on AWS (mabey even a book has been written) that would be great as I found the amazon docs did not go into much detail and told me how to do things but not why I should do them and what purpose they had.
Thanks
I'll start with answering your q's first, and as you are a newbie I would suggest don't pressurize to learn all of AWS, you can keep migrating slowly and keep discovering the magic of cloud.
Q.
when the EC2 instance does down it will take all the data with it and
I can not have that happen. I have also read then when it dies it wont
do anything and you have to start up the apache server again it is not
automatic?
A. When an EC2 instance goes down (down could mean shutdown manual by you or Down means AWS network is down, or instances are having some other issues) only the data on "ephemeral data" or you can say data on RAM or sessions will get lost, whatever is on disk will remain on disk, And the instance will be available as soon as problem is resolved.
Apache will start itself when an instance restarts, and remains up until you manually shut it down or some other issue.
Q. I will need S3 for static things such as my PDF's and images as
well as using the RDS for my MYSQL database?
A. Its a good practice to keep static stuff on s3, but not a necessary thing to do, you can set up a ftp or manage your static content like you were used to, like keeping it on a folder of your website.
You don't necessarily need RDS to have a mysql database, I have a process running on aws with around 40 mil transactions a day, and I do it on a normal mysql at an ec2 instance.
however having RDS gets rid from the daily backup and index maintenance hustles.
Q. My domain name is registered elsewhere so I believe I need to use
route 53 as well ?
A. Again not a necessary thing, you can just go to your domain manager and change the A-name or C-name records (with static public ip of ec2) and give a static public ip to your ec2 instance or Elastic load balancer and you'll be up and running in no time.
Q. I want to use AWS for a few reasons reasons, firstly as it can
scale which is really important but not sure if this is built in or it
requires customization.
A. It can scale really well, but depends how do you want it to scale, and its highly customizable.
there are 2 kinds of scaling
vertical - you change your instance type from one type to another to get better disk / cpu or RAM or better network performance, but this will need you to stop your ec2 instance and change its type, that means there will be downtime of around 10 minutes while you do so.
horizontal - you can put your website (ec2 based) behind a load balancer (ELB - elastic load balancer) and add/remove more instances to/from it as and when you deemed suitable, or you can also have an auto scaling policy to help you do it automatically depending up on the load at your web server.
Security? - you can be very well assured its very well secure, and so much secure that I can bet my life on a secure ec2 instance, i can swear by linux thor that it works and it works like a charm.
Debugging? - I suggest you do debugging by classic means, make logs of errors and all, just treat ec2 like a normal machine and learn slowly the tricks of trade.
Now lets setup a basic solid LAMP stack for ourselves, I am assuming that you have a ready ubuntu instance, and you can ssh to it, in case you haven't been able to make one - see this.
basically.
1. create security groups - This is your firewall, makes sure which ports are open, and also makes sure which ec2 instances can talk amongst themselves.
2. Create an ec2 instance - make any ubuntu instance.
And access your instance using ssh - ssh is basically secure terminal connection to your ec2 machine which is secured by a key file (pem file) and whoever has it can access your machine's data, so keep it very very secure, and you can't afford to lose it.
3. install LAMP using - Tasksel utility
4. setup a public ip for yourself ( costs a dollar per month) - you can use this ip to redirect your www.example.com traffic using domain manager of your DNS provider - godaddy or someone alike i suppose.
I think this will be it to make you start with AWS.
Just to be safe that you have a copy of your data make an AMI of your ec2 instance with all the data on it. AMI is the image from which you can make a similar or better instance in 10 minutes flat (or even lesser).
You wil pay for - instance type you chose, public IP, traffic if its beyond a level (usually very very cheap), and disk usage (8 gb is the default disk), and AMI volume.
Have fun with AWS.
To retain data between during the down time, make sure you use EBS storage. Its default now a days. In the past, before EBS, instance storage was default and you would lose data once server is down, but with the EBS storage, data is retained during the shutdown.
You can go one of the follow two routes depending upon your needs.
1. Use AWS ElasticBeanStalk (http://aws.amazon.com/elasticbeanstalk/) if you do not need to install anything additional Its super easy and its similar to Google Apps and you can deploy your app quickly. You do not get server, but a server to deploy your app. You have to use RDS for database and S3 for storage. You can not store locally on the server where you are running.
Use EC2 server with static IP address. You can get pre-configured LAMP stacks from market place. I use bitnami cloud stacks for AWS that comes pre-configured with LAMP and many other apps. Just use their free account to create micro instance for your PHP and select a server and you are good to go. http://bitnami.com/cloud
You do not need to use Route 53 unless you need to manage DNS programatically. You can just point your server to EC2 server by adding entry in your DNS (godaddy or whoever is your domain name provider).
Bitnami service also allow scheduled backups, but if you are not storing anything locally, you do not need frequent backups.
Make sure you use Multi-AZ option in RDS which is more reliable. When you provision a Multi-AZ DB Instance, Amazon RDS automatically creates a primary DB Instance and synchronously replicates the data to a standby instance in a different Availability Zone (AZ). Also, Amazon RDS automatically patches the database software and backs up your database, storing the backups for a user-defined retention period and enabling point-in-time recovery, up to last 5 minutes.
I hope this helps.
You should be using dynamo DB (http://aws.amazon.com/dynamodb/pricing/) in with LAMP without Mysql for storage. Having a Samebox database can almost never give you reliability. So you will not loose your data what ever your Application box goes through. You can even read our application config from dynamo DB.
http://aws.amazon.com/documentation/dynamodb/
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SettingUpTestingSDKPHP.html
Do I need to use EC2 with DynamoDB?
You wont loose data when server is down. Just make sure your select EBS volume, and not Instance.
You can get ready-made server from AWS market place. I used the following for my projects, but there are many other pre-configured servers available.
https://aws.amazon.com/marketplace/pp/B007IN7GJA/ref=srh_res_product_title?ie=UTF8&sr=0-2&qid=1382655655469
This with RDS server is what you need. We use this all the time for production servers and never had any issues.
Here are two guides that look good to me:
http://shout.setfive.com/2013/04/05/amazon-aws-ec2-lamp-quickstart-guide-5-steps-in-10-minutes/
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html
If learning the Linux command line isn't your thing, you should consider going "up the stack" to a PaaS (Platform As A Service). They are things like Heroku, Google App Engine, and ElasticBeanStalk.
The trade-off between Infrastructure as a Service (IaaS like EC2) and a Platform as a Service (PaaS like Heroku):
- PasS is quicker to get started, less to learn. IaaS requires you to know the entire stack from the start (or hire/rent a sysadmin).
- PasS usually gets more expensive as you get bigger compared to IaaS (but it depends).
- PaaS has less control (you can't choose the language version, so you can't upgrade to get around a specific bug.)
- IaaS can literally do anything (it's just a Linux box)
- IaaS allows for more tuning (upgrade libraries to get features, switch to different instance type to trade off RAM for CPU, run HipHop for speed, add caching layers, etc)
You have a few choices:
Use only EC2. Install Apache+MySQL and your dynamic website on EC2. This will be very similar to setting it up on Hostgator except you are running a full server.
Use EC2 for "compute" (that is, the dynamic part of the site) and S3 for storage. This doesn't differ much from #1 above, except that you are using S3 for static file storage - which is great if you are expecting to host a lot of static content (multimedia, etc)
Set up your website using Amazon Elastic Beanstalk (which now supports PHP). However, if you go this route, you will need to host your database somewhere - which will likely be RDS.
I recommend going with #1. There is nothing wrong with that - yes, if EC2 goes down, it will take down your site with it, but to alleviate that, you can run two servers in two different regions (one in US East and one in US West) - I don't think two EC2 regions have ever gone down at the same time.
UPDATE: If you are concerned about backup/restore and making sure your data is safe, I recommend the following (I do this with a site in production on EC2):
Put your website code into Git/SVN source control; and pull from there
Backup your MySQL database to Amazon S3 regularly (at least once a day) using mysqldump
I think you have some misconceptions.
If EC2 as a whole goes down (which is rare) then you do NOT lose your data. The site would simply be offline until Amazon restored services.
If your particular instance goes down due to a hardware issue, then you might lose data. This is no different than if your own server went belly up. The right answer is to simply make normal backups of your database and store it in S3 or some other location. Generally you will want to create and attach a second EBS volume to your DB server which has the DB files on it as well.
If you Terminate your instance then, yes you will lose everything on that. However Amazon has the ability to make terminating instances difficult so you don't do it accidentally.
Stopping your instance is like turning the computer off. The difference being that you can remotely turn it back on when you want. You can only stop EBS backed instances - which means that your data is safe while it is offline.
I would highly suggest that if you are uncomfortable with setting up and maintaining your own server that you should investigate fully managed hosting instead. EC2 is awesome, we've been on it for 2 years. However, we have a strong tech team that understands what it takes to run and manage servers.

Faceted Search With(out) Solr

I want to implement a faceted search for a project of mine. I'm using PHP5, Mysql and Symfony 1.4. Apparently the commnunity points to Apache Solr which seems to do exactly what I want to accomplish.
The problem is that the website is going to be live on a hosting provider that doesn't allow me to setup Solr (it is a shared hosting environment and neither allows Tomcat nor Solr to be up-and-running).
So could you please give me directions on possible alternatives or if there is a way to setup Solr in such an environment?
EDIT
My hosting provider neither supports SOLR nor solutions as opensolr. In general I can't use my environment to connect to a process on the same server or a remote one. It seems the only available option is to use Zend_Search_Lucene. So does this support faceted searching? Or if you have another option in mind please share it! I feel being in the middle of nowhere!
EDIT 2
As this question is opened for about a week from the answers given so far I am surprised (and disappointed) that there is no library (not service) available in PHP to implement faceted search. It seems that either this needs to be implemented manually or use solutions provided below
Change hosts, or host the Solr index elsewhere - for example, a quick search revealed http://www.opensolr.com/ provide Solr hosting, there are no doubt many others.
Performance won't be great and don't discuss scaling, but you can always create a reverse HTTP tunnelling over HTTP. Basically, instead of the web server opening an outbound connection to the Solr server, it's the Solr server connecting to the web server to request jobs and to post job results.
What you'll need to do:
The browser post a search query, the query is simply queued in the database.
The reverse proxy periodically connects to the web server (over plain ol' port 80) to fetch a list of queries from the job queue, pass the queries to the Solr server, and POST the results back to the web server.
The browser periodically polls the web server for finished search result.
Bonus marks: if your server allows concurrent request processing, use long polling to improve latency.
In short, bite the bullet and move to a decent host.
Try to avoid Zend_Search_Lucene, it's not really fast. (Well it's pretty good given that it's implemented in Php and doesn't run as daemon)
Hosted Solr as Paul suggested sounds like a good alternative - if you are not willing to change host.

Categories